def _update_collections(self, old_assigned_to_coll, new_assigned_to_coll, res_id): """ Append or remove resource from collections """ diff_list = set(old_assigned_to_coll) new_list = diff_list.symmetric_difference(new_assigned_to_coll) collection = CollectionOperationalAPI() for coll_id in new_list: if coll_id in new_assigned_to_coll: coll = collection.getCollectionInfo(coll_id).to_dict() coll_spec = self._search_spec(ELEM_TYPES['IS_COLL'], coll['specification_name'])[0] Collection.setup_specification([CollectionSpecification(coll_spec)]) collection.appendResourceToCollection(coll_id, res_id) elif coll_id in old_assigned_to_coll: collection.removeResourceFromCollection(coll_id, res_id)
def get_collection_params(self, request): """ Implement GET method """ if request.GET.get('coll_id', None): collection = CollectionOperationalAPI() coll_info = collection.getCollectionInfo(request.GET['coll_id']).to_dict() coll_spec = self._search_spec(ELEM_TYPES['IS_COLL'], coll_info['specification_name'])[0] # for TreeMenu spec_params_json = json.dumps(coll_spec['params_spec']) to_text = spec_params_json.replace('param_name','text') items = to_text.replace('children_spec','items') json_data = {'coll_spec': coll_spec['params_spec'], 'coll_info': coll_info, 'allowed_types': coll_spec['allowed_types'], 'items': json.loads(items)} return HttpResponse(json.dumps(json_data), mimetype="application/json") return HttpResponse()