Tweaks to upgrade_node_types
This commit is contained in:
parent
6282229488
commit
a96526351b
@ -62,23 +62,17 @@ def clear_db():
|
|||||||
|
|
||||||
@manager.command
|
@manager.command
|
||||||
def upgrade_node_types():
|
def upgrade_node_types():
|
||||||
"""Wipes node_types collection
|
"""Wipes node_types collection and populates it again"""
|
||||||
and populates it again
|
node_types_collection = app.data.driver.db['node_types']
|
||||||
"""
|
node_types = node_types_collection.find({})
|
||||||
from pymongo import MongoClient
|
|
||||||
|
|
||||||
client = MongoClient(MONGO_HOST, 27017)
|
|
||||||
db = client.eve
|
|
||||||
node_types = db.node_types.find({})
|
|
||||||
old_ids = {}
|
old_ids = {}
|
||||||
for nt in node_types:
|
for node_type in node_types:
|
||||||
old_ids[nt['name']] = nt['_id']
|
old_ids[node_type['name']] = node_type['_id']
|
||||||
populate_node_types(old_ids)
|
populate_node_types(old_ids)
|
||||||
|
|
||||||
|
|
||||||
def get_id(collection, name):
|
def get_id(collection, name):
|
||||||
"""Returns the _id of the given collection
|
"""Returns the _id of the given collection and name"""
|
||||||
and name."""
|
|
||||||
from pymongo import MongoClient
|
from pymongo import MongoClient
|
||||||
client = MongoClient(MONGO_HOST, 27017)
|
client = MongoClient(MONGO_HOST, 27017)
|
||||||
db = client.eve
|
db = client.eve
|
||||||
@ -164,37 +158,32 @@ def manage_groups():
|
|||||||
|
|
||||||
|
|
||||||
def populate_node_types(old_ids={}):
|
def populate_node_types(old_ids={}):
|
||||||
|
node_types_collection = app.data.driver.db['node_types']
|
||||||
from pymongo import MongoClient
|
|
||||||
|
|
||||||
client = MongoClient(MONGO_HOST, 27017)
|
|
||||||
db = client.eve
|
|
||||||
|
|
||||||
def mix_node_type(old_id, node_type_dict):
|
def mix_node_type(old_id, node_type_dict):
|
||||||
# Take eve parameters
|
# Take eve parameters
|
||||||
node_type = db.node_types.find({'_id':old_id})
|
node_type = node_types_collection.find_one({'_id': old_id})
|
||||||
node_type = node_type[0]
|
|
||||||
for attr in node_type:
|
for attr in node_type:
|
||||||
if attr[0]=='_':
|
if attr[0] == '_':
|
||||||
# Mix with node type attributes
|
# Mix with node eve attributes. This is really not needed since
|
||||||
node_type_dict[attr]=node_type[attr]
|
# the attributes are stripped before doing a put_internal.
|
||||||
|
node_type_dict[attr] = node_type[attr]
|
||||||
|
elif attr == 'permissions':
|
||||||
|
node_type_dict['permissions'] = node_type['permissions']
|
||||||
return node_type_dict
|
return node_type_dict
|
||||||
|
|
||||||
def upgrade(node_type, old_ids):
|
def upgrade(node_type, old_ids):
|
||||||
print("Node {0}".format(node_type['name']))
|
print("Node {0}".format(node_type['name']))
|
||||||
node_name = node_type['name']
|
node_name = node_type['name']
|
||||||
if node_name in old_ids:
|
if node_name in old_ids:
|
||||||
node_type = mix_node_type(old_ids[node_name], node_type)
|
node_id = old_ids[node_name]
|
||||||
node_id = node_type['_id']
|
node_type = mix_node_type(node_id, node_type)
|
||||||
|
|
||||||
# Removed internal fields that would cause validation error
|
# Removed internal fields that would cause validation error
|
||||||
internal_fields = ['_id', '_etag', '_updated', '_created']
|
internal_fields = ['_id', '_etag', '_updated', '_created']
|
||||||
for field in internal_fields:
|
for field in internal_fields:
|
||||||
node_type.pop(field, None)
|
node_type.pop(field, None)
|
||||||
# Also remove permissions, since they are managed separately
|
|
||||||
node_type.pop('permissions', None)
|
|
||||||
p = put_internal('node_types', node_type, **{'_id': node_id})
|
p = put_internal('node_types', node_type, **{'_id': node_id})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Making the node")
|
print("Making the node")
|
||||||
print(node_type)
|
print(node_type)
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
_file_embedded_schema = {
|
||||||
|
'type': 'objectid',
|
||||||
|
'data_relation': {
|
||||||
|
'resource': 'files',
|
||||||
|
'field': '_id',
|
||||||
|
'embeddable': True
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
from manage.node_types import _file_embedded_schema
|
||||||
|
|
||||||
node_type_asset = {
|
node_type_asset = {
|
||||||
'name': 'asset',
|
'name': 'asset',
|
||||||
'description': 'Basic Asset Type',
|
'description': 'Basic Asset Type',
|
||||||
@ -23,19 +25,26 @@ node_type_asset = {
|
|||||||
},
|
},
|
||||||
# We point to the original file (and use it to extract any relevant
|
# We point to the original file (and use it to extract any relevant
|
||||||
# variation useful for our scope).
|
# variation useful for our scope).
|
||||||
'file': {
|
'file': _file_embedded_schema,
|
||||||
'type': 'objectid',
|
'description_attachments': {
|
||||||
'data_relation': {
|
'type': 'list',
|
||||||
'resource': 'files',
|
'schema': {
|
||||||
'field': '_id',
|
'type': 'dict',
|
||||||
'embeddable': True
|
'schema': {
|
||||||
},
|
'file': _file_embedded_schema,
|
||||||
|
'url': {
|
||||||
|
'type': 'string',
|
||||||
|
'minlength': 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'form_schema': {
|
'form_schema': {
|
||||||
'status': {},
|
'status': {},
|
||||||
'content_type': {'visible': False},
|
'content_type': {'visible': False},
|
||||||
'file': {'visible': False},
|
'file': {'visible': False},
|
||||||
|
'description_attachments': {'visible': False},
|
||||||
},
|
},
|
||||||
'permissions': {
|
'permissions': {
|
||||||
# 'groups': [{
|
# 'groups': [{
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from manage.node_types import _file_embedded_schema
|
||||||
|
|
||||||
node_type_project = {
|
node_type_project = {
|
||||||
'name': 'project',
|
'name': 'project',
|
||||||
'parent': {},
|
'parent': {},
|
||||||
@ -60,25 +62,9 @@ node_type_project = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
# Logo
|
# Logo
|
||||||
'picture_square': {
|
'picture_square': _file_embedded_schema,
|
||||||
'type': 'objectid',
|
|
||||||
'nullable': True,
|
|
||||||
'data_relation': {
|
|
||||||
'resource': 'files',
|
|
||||||
'field': '_id',
|
|
||||||
'embeddable': True
|
|
||||||
},
|
|
||||||
},
|
|
||||||
# Header
|
# Header
|
||||||
'picture_header': {
|
'picture_header': _file_embedded_schema,
|
||||||
'type': 'objectid',
|
|
||||||
'nullable': True,
|
|
||||||
'data_relation': {
|
|
||||||
'resource': 'files',
|
|
||||||
'field': '_id',
|
|
||||||
'embeddable': True
|
|
||||||
},
|
|
||||||
},
|
|
||||||
# Short summary for the project
|
# Short summary for the project
|
||||||
'summary': {
|
'summary': {
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user