def getDefaultDiagram(request): projectID = request.GET['projectID'] user = request.user try: diagrams = Diagram.objects.filter(id=1) if not diagrams: diagram, created = Diagram.objects.get_or_create(code='default') diagram.smOwningUser = user diagram.smCreatedBy = user diagram.save() else: diagram = diagrams[0] except Exception as e: return JSONError(e) jsonDiagram = diagram.info if isinstance(jsonDiagram, dict): jsonDiagram = json.dumps(jsonDiagram, cls=JSONEncoder) jsondict = { 'success': True, 'message': '', 'diagramID': diagram.id, 'diagramCode': diagram.code, 'diagram': jsonDiagram, } context = json.dumps(jsondict) return HttpResponse(context, content_type="application/json")
def getEntitiesJSONDiagram(request): """ return all tables from project """ selectedTables = [] try: tableEnterprise = { 'id': '63c0f27a-716e-804c-6873-cd99b945b63f', 'tableName': 'Enterprise' } tableUsage = { 'id': '3253ff2a-a920-09d5-f033-ca759a778e19', 'tableName': 'UsageLogiciel' } tableLogiciel = { 'id': '2810494b-931f-da59-fd9d-6deba4385fe0', 'tableName': 'Logiciel' } selectedTables.append(tableEnterprise) selectedTables.append(tableUsage) selectedTables.append(tableLogiciel) except Exception as e: print(e) return JSONError("Entity non trouvé") jsondict = { 'success': True, 'message': '', 'tables': selectedTables, } context = json.dumps(jsondict) return HttpResponse(context, content_type="application/json")
def deleteDiagram(request): attributes = ast.literal_eval(request.POST['diagrams']) try: diagram = Diagram.objects.get(id=attributes['id']) diagram.delete() except Exception as e: return JSONError(e) jsondict = { 'success': True, 'message': 'Diagram deleted', } context = json.dumps(jsondict) return HttpResponse(context, content_type="application/json")
def createDiagram(request): attributes = ast.literal_eval(request.POST['diagrams']) code = attributes['code'] try: diagram = Diagram.objects.create(code=code) except Exception as e: return JSONError(e) jsondict = { 'success': True, 'message': 'Diagram created', 'diagramID': diagram.id, } context = json.dumps(jsondict) return HttpResponse(context, content_type="application/json")
def openDiagram(request): diagramID = request.GET['diagramID'] try: diagram = Diagram.objects.get(id=diagramID) except Exception as e: return JSONError(e) jsonDiagram = diagram.info if isinstance(jsonDiagram, dict): jsonDiagram = json.dumps(jsonDiagram, cls=JSONEncoder) jsondict = { 'success': True, 'message': '', 'diagramID': diagram.id, 'diagramCode': diagram.code, 'diagram': jsonDiagram, } context = json.dumps(jsondict) return HttpResponse(context, content_type="application/json")
def saveDiagram(request): diagramID = request.GET['diagramID'] jsonFile = json.loads(request.body) jsonString = JSONEncoder().encode(jsonFile) jsonString = '{"objects":' + jsonString + '}' try: diagram = Diagram.objects.get(id=diagramID) diagram.info = jsonString diagram.save() except Exception as e: return JSONError(e) jsondict = { 'success': True, 'message': 'Diagram saved', } context = json.dumps(jsondict) return HttpResponse(context, content_type="application/json")
def synchDBFromDiagram(request): """ Create and synchronize elements in database """ try: projectID = request.GET['projectID'] except Exception as e: return JSONError(e) objects = json.loads(request.body) selectedTables = [] connectors = [] assembler = JSONAssembler() selectedTables, connectors = assembler.getJSONElements(objects) jsondict = { 'success': True, 'message': '', 'tables': selectedTables, 'connectors': connectors, } context = json.dumps(jsondict) return HttpResponse(context, content_type="application/json")