def addFragment(request): data = request.GET fragment = json.loads(data["fragment"]) nodes = fragment["nodes"] relations = fragment["rels"] view_id = data['view_id'] the_view = None if (view_id=="") else View.objects.get(id=view_id) for node in nodes: if the_view == None: new_inst = request.configuration.makeEntity(node["cid"]) new_inst["name"] = node["title"] new_inst.save() new_id = new_inst.id else: new_id = node["id"] configuration = Configuration.objects.get(name=request.configuration.__class__.__name__) try: Object.objects.get(oid=str(node["cid"])+","+str(new_id),config=configuration,view=the_view) except Exception: new_model = Object(oid=str(node["cid"])+","+str(new_id),config=configuration,color=node["color"],image=node["image"],size=node["size"],shape=node["shape"],x=node["x"],y=node["y"],view=the_view) new_model.save() if the_view == None: for rel in relations: if rel["source"][0]==node["cid"] and rel["source"][1]==node["id"]: rel["source"][1] = new_id if rel["target"][0]==node["cid"] and rel["target"][1]==node["id"]: rel["target"][1] = new_id node["id"] = new_id if the_view == None: for rel in relations: ent1 = request.configuration.loadEntity(rel["source"][0], rel["source"][1]) ent2 = request.configuration.loadEntity(rel["target"][0], rel["target"][1]) relation = request.configuration.makeRelation(rel["cid"], ent1, ent2) relation.save() return JsonResponse(fragment)
def getObjAttributes(request,cid,id): cid = int(cid) id = int(id) attr_list = [] attr_data_list = [] class_info = request.configuration.classes[cid] entity = request.configuration.loadEntity(cid, id) protos = {} protos_values = {} types = [] for attr in class_info["attributes"]: key = attr["name"] attr_list.append(key) attr_data_list.append(entity[key]) types.append(attr["data_type"]) protos[key] = key not in entity protos_values[key] = entity.get_default_attribute_value(key) return JsonResponse({ "fields": attr_list, "vals": attr_data_list, "types": types, "protos": protos, "proto_vals": protos_values })
def getViewsData(request): views_list = [] configuration_id = Configuration.objects.get( name=request.configuration.__class__.__name__).id views = View.objects.filter(config=configuration_id) for v in views: views_list += [{"id": v.id, "name": v.name, "image": v.image}] return JsonResponse({"data": views_list})
def getRelAttributes(request, cid, id): cid = int(cid) id = int(id) attr_list = [] attr_data_list = [] class_info = request.configuration.classes[cid] relation = request.configuration.loadRelation(cid, id) for attr in class_info["attributes"]: key = attr["name"] attr_list.append(key) attr_data_list.append(relation[key]) return JsonResponse({"fields": attr_list, "vals": attr_data_list})
def configData(request): classes_list = [] relations_list = [] configuration_id = Configuration.objects.get(name=request.configuration.__class__.__name__).id cids = request.configuration.classes.keys() cids.sort() for cls_id in cids: cls_info = request.configuration.classes[cls_id] cls_model_info = ObjectClass.objects.get(cid=cls_id,config=configuration_id) if cls_info["type"] == "entity_class": classes_list += [{ "id": cls_id, "title": cls_info["name"], "description": cls_info["description"], "shape": cls_model_info.shape, "x": cls_model_info.x, "y": cls_model_info.y, "color": cls_model_info.color, "size": cls_model_info.size, "image": cls_model_info.image, "scale": cls_model_info.scale }] else: relations_list += [{ "id": cls_id, "title": cls_info["name"], "description": cls_info["description"], "shape": cls_model_info.shape, "x": cls_model_info.x, "y": cls_model_info.y, "color": cls_model_info.color, "size": cls_model_info.size, "allowed_relations": cls_info["allowed_relations"] }] return JsonResponse({"nodes":classes_list,"rels":relations_list})
def getSearchWidget(request): try: input_widget = GetHtmlEntityIdSelector(request, "search_string") return JsonResponse(input_widget) except Exception,e: result = e
backgrounds = Background.objects.filter(config=configuration,view=the_view) for bg in backgrounds: backgrounds_list += [{ "id": bg.id, "x": bg.x, "y": bg.y, "width": bg.width, "height": bg.height, "image": bg.image, "z": bg.z }] """ if(rel.getFromEntity().cid==2): rel.delete(); return HttpResponse(relations)""" #return HttpResponse(Node.objects.get(id="1,45",config=configuration)); return JsonResponse({'nodes':nodes_list,'rels':relations_list,'bgs':backgrounds_list}) def getObjAttributes(request,cid,id): cid = int(cid) id = int(id) attr_list = [] attr_data_list = [] class_info = request.configuration.classes[cid] entity = request.configuration.loadEntity(cid, id) protos = {} protos_values = {} types = [] for attr in class_info["attributes"]: key = attr["name"]
def configData(request): classes_list = [] relations_list = [] #configuration_id = Configuration.objects.get(name=request.configuration.__class__.__name__).id try: configuration = Configuration.objects.get( name=request.configuration.__class__.__name__) except Configuration.DoesNotExist: configuration = Configuration( name=request.configuration.__class__.__name__) configuration.save() cids = request.configuration.classes.keys() cids.sort() for cls_id in cids: cls_info = request.configuration.classes[cls_id] #tag_id = cls_info #if cls_info["name"]!="tag" and cls_info["name"]!="tag_link": try: cls_model_info = ObjectClass.objects.get(cid=cls_id, config=configuration.id) except ObjectClass.DoesNotExist: if cls_info["type"] == "entity_class": cls_model_info = ObjectClass(cid=str(cls_id), config=configuration, color="#cccccc", size=10, shape="circle", x=30, y=20, scale=0) cls_model_info.save() else: cls_model_info = ObjectClass(cid=str(cls_id), config=configuration, color="#cccccc", size=2, shape="stroke", x=100, y=20, scale=0) cls_model_info.save() if cls_info["type"] == "entity_class": classes_list += [{ "id": cls_id, "title": cls_info["name"], "description": cls_info["description"], "shape": cls_model_info.shape, "x": cls_model_info.x, "y": cls_model_info.y, "color": cls_model_info.color, "size": cls_model_info.size, "image": cls_model_info.image, "scale": cls_model_info.scale }] else: relations_list += [{ "id": cls_id, "title": cls_info["name"], "description": cls_info["description"], "shape": cls_model_info.shape, "x": cls_model_info.x, "y": cls_model_info.y, "color": cls_model_info.color, "size": cls_model_info.size, "allowed_relations": filterTagRelations(cls_info["allowed_relations"]) }] return JsonResponse({"nodes": classes_list, "rels": relations_list})
def getGraphData(request): data = request.GET nodes_list = [] relations_list = [] backgrounds_list = [] configuration = Configuration.objects.get( name=request.configuration.__class__.__name__) trans = maketrans("", "") view_id = data['view_id'] the_view = None if (view_id == "") else View.objects.get(id=view_id) #cids = json.loads(data["cids"]) cids = request.configuration.classes.keys() entities = [] for cid in cids: entities += request.configuration.getAllEntities(cid) for en in entities: try: object_info = Object.objects.get(oid=str(en.getId()).translate( trans, '(|)| '), config=configuration.id, view=the_view) except Object.DoesNotExist: object_info = Object(oid=str(en.getId()).translate(trans, '(|)| '), config=configuration, color="#DC143C", size=10, shape="default", x=0, y=0, scale=0) object_info.save() nodes_list += [{ "id": en.getId()[1], "cid": en.getId()[0], "title": en["readable_name"], "x": object_info.x, "y": object_info.y, "color": object_info.color, "shape": object_info.shape, "size": object_info.size, "image": object_info.image, "scale": object_info.scale #"test": str(en.getId()).translate(maketrans("",""),'(|)| '), }] relations = request.configuration.getAllRelations( en, None, None, True, "from") for rel in relations: rel_name = "" if 'name' in rel: rel_name = rel["name"] for node in nodes_list: from_ent = rel.getFromEntity().getId() if from_ent[0] == node["cid"] and from_ent[1] == node["id"]: relations_list += [{ "id": rel.getId()[1], "source": from_ent, "target": rel.getToEntity().getId(), "cid": rel.getId()[0], "name": rel_name, }] relations = request.configuration.getAllRelations( en, None, None, True, "to") for rel in relations: rel_name = "" if 'name' in rel: rel_name = rel["name"] for node in nodes_list: to_ent = rel.getToEntity().getId() if to_ent[0] == node["cid"] and to_ent[1] == node["id"]: relations_list += [{ "id": rel.getId()[1], "source": rel.getFromEntity().getId(), "target": to_ent, "cid": rel.getId()[0], "name": rel_name, }] backgrounds = Background.objects.filter(config=configuration, view=the_view) for bg in backgrounds: backgrounds_list += [{ "id": bg.id, "x": bg.x, "y": bg.y, "width": bg.width, "height": bg.height, "image": bg.image, "z": bg.z }] """ if(rel.getFromEntity().cid==2): rel.delete(); return HttpResponse(relations)""" #return HttpResponse(Node.objects.get(id="1,45",config=configuration)); return JsonResponse({ 'nodes': nodes_list, 'rels': relations_list, 'bgs': backgrounds_list })