def project_reorder_components(node, **kwargs): """Reorders the components in a project's component list. :param-json list new_list: List of strings that include node IDs and node type delimited by ':'. """ # TODO(sloria): Change new_list parameter to be an array of objects # { # 'newList': { # {'key': 'abc123', 'type': 'node'} # } # } new_list = [tuple(n.split(":")) for n in request.json.get("new_list", [])] nodes_new = [StoredObject.get_collection(schema).load(key) for key, schema in new_list] valid_nodes = [n for n in node.nodes if not n.is_deleted] deleted_nodes = [n for n in node.nodes if n.is_deleted] if len(valid_nodes) == len(nodes_new) and set(valid_nodes) == set(nodes_new): node.nodes = nodes_new + deleted_nodes node.save() return {} logger.error("Got invalid node list in reorder components") raise HTTPError(http.BAD_REQUEST)
def project_reorder_components(node, **kwargs): """Reorders the components in a project's component list. :param-json list new_list: List of strings that include node IDs and node type delimited by ':'. """ # TODO(sloria): Change new_list parameter to be an array of objects # { # 'newList': { # {'key': 'abc123', 'type': 'node'} # } # } new_list = [tuple(n.split(':')) for n in request.json.get('new_list', [])] nodes_new = [ StoredObject.get_collection(schema).load(key) for key, schema in new_list ] valid_nodes = [n for n in node.nodes if not n.is_deleted] deleted_nodes = [n for n in node.nodes if n.is_deleted] if len(valid_nodes) == len(nodes_new) and set(valid_nodes) == set( nodes_new): node.nodes = nodes_new + deleted_nodes node.save() return {} logger.error('Got invalid node list in reorder components') raise HTTPError(http.BAD_REQUEST)
def check_pk_change(obj): for backref in obj._backrefs_flat: pk = backref[1] if backref[0][1] == 'guid': continue Schema = StoredObject.get_collection(backref[0][1]) record = Schema.load(pk) if record is None: print 'Error: Backref {} not found'.format(pk) field = getattr(record, backref[0][2]) if isinstance(field, list): if obj not in field: print 'Error: Object {} not in backref list'.format(pk) else: if field != obj: print 'Error: Object {} not equal to backref'.format(pk) for fname, fobj in obj._fields.items(): if fobj._is_foreign: if fobj._list: key = fobj._field_instance._backref_field_name else: key = fobj._backref_field_name if not key: continue backref_key = '__'.join([ obj._name, key, fname, ]) value = getattr(obj, fname) if not value: continue if fobj._list: for item in value: if item is None: continue if obj not in getattr(item, backref_key): print 'Error: Obj {} not in backrefs of referent {}'.format( obj._primary_key, fname ) else: if obj not in getattr(value, backref_key): print 'Error: Obj {} not in backrefs of referent {}'.format( obj._primary_key, fname )