From 67d620bc37e8b9d98aeb53b5c5d9e8590df3e203 Mon Sep 17 00:00:00 2001 From: Eibriel Date: Mon, 13 Apr 2015 15:08:44 -0300 Subject: [PATCH] Added upgrade_node_type command Improved task node type Added form_schema to manipulate forms --- attract/manage.py | 122 +++++++++++++++++++++++++++++++++++++------- attract/settings.py | 10 +++- 2 files changed, 112 insertions(+), 20 deletions(-) diff --git a/attract/manage.py b/attract/manage.py index 55747b33..cf993242 100644 --- a/attract/manage.py +++ b/attract/manage.py @@ -36,11 +36,30 @@ def clear_db(): db.drop_collection('users') +@manager.command +def upgrade_node_types(): + """Wipes node_types collection + and populates it again + """ + from pymongo import MongoClient + + client = MongoClient() + db = client.eve + node_types = db.node_types.find({}) + old_ids = {} + for nt in node_types: + old_ids[nt['name']] = nt['_id'] + populate_node_types(old_ids) + + @manager.command def populate_db_test(): """Populate the db with sample data """ + populate_node_types() + +def populate_node_types(old_ids={}): shot_node_type = { "name": "shot", "description": "Shot Node Type, for shots", @@ -77,6 +96,18 @@ def populate_db_test(): #}, } }, + "form_schema": { + "url": {}, + "cut_in": {}, + "cut_out": {}, + "status": {}, + "notes": {}, + "order": {}, + "shot_group": {} + }, + "parent": { + "node_types": [] + } } task_node_type = { @@ -118,32 +149,85 @@ def populate_db_test(): }, "chunks": { "type": "list", + "schema": { + "type": "dict", + "schema": { + "start": { + "type": "datetime", + }, + "duration": { + "type": "integer", + } + } + } + }, + } + } + }, + "form_schema": { + "status": {}, + "owners": { + "schema": { + "users":{}, + "groups":{} + } + }, + "time": { + "schema": { + "start": {}, + "duration": {}, + "chunks": { + "visible": False, + "schema": { + "start":{}, + "duration":{} + } } } } }, - } - - shot = { - "name": "01", - "description": "A sheep tries to hang itself, but fails", - "picture": "", - "order": 0, - "parent": None, - "node_type": "55016a52135d32466fc800be", - "properties": { - "url": "shot01", - "cut_in": 100, - "cut_out": 900, - "status": "todo", - "notes": "I think the sheep should scream a bit more", - "order": 1, - "shot_group": "", + "parent": { + "node_types": ["shot"], } } - post_item('node_types', shot_node_type) - post_item('node_types', task_node_type) + + from pymongo import MongoClient + + client = MongoClient() + db = client.eve + + def mix_node_type(old_id, node_type_dict): + # Take eve parameters + node_type = db.node_types.find({'_id':old_id}) + node_type = node_type[0] + for attr in node_type: + if attr[0]=='_': + # Mix with node type attributes + node_type_dict[attr]=node_type[attr] + return node_type_dict + + + shot_name = shot_node_type['name'] + if shot_name in old_ids: + shot_node_type = mix_node_type(old_ids[shot_name], shot_node_type) + # Remove old node_type + db.node_types.remove({'_id':old_ids[shot_name]}) + # Insert new node_type + db.node_types.insert(shot_node_type) + else: + post_item('node_types', shot_node_type) + + + task_name = task_node_type['name'] + if task_name in old_ids: + task_node_type = mix_node_type(old_ids[task_name], task_node_type) + # Remove old node_type + db.node_types.remove({'_id':old_ids[task_name]}) + # Insert new node_type + db.node_types.insert(task_node_type) + else: + post_item('node_types', task_node_type) if __name__ == '__main__': diff --git a/attract/settings.py b/attract/settings.py index 96d91810..9638a9eb 100644 --- a/attract/settings.py +++ b/attract/settings.py @@ -54,7 +54,7 @@ nodes_schema = { }, 'parent': { 'type': 'objectid', - 'default': '', + #'default': '', #'data_relation': { # 'resource': 'nodes', # 'field': '_id', @@ -93,6 +93,14 @@ node_types_schema = { 'dyn_schema': { 'type': 'dict', 'required': True, + }, + 'form_schema': { + 'type': 'dict', + 'required': True, + }, + 'parent': { + 'type': 'dict', + 'required': True, } }