def getEntityCode(self, code, prefix): # Formatea el nombre de la entidad enttCode = code if len(prefix) and enttCode.startswith(prefix): enttCode = enttCode[len(prefix):] return getClassName(enttCode)
def getDiagramDefinition(self, queryset): self.diagrams = [] self.arcs = [] for pDiag in queryset: gDiagram = { 'code': getClassName(pDiag.code) , 'label': pDiag.code , 'showBorder' : getattr(pDiag, 'showBorder' , False), 'arcs': [] } for pDiagComposition in pDiag.artefactcomposition_set.all(): # Verifica si el nodo inicial es el contenedor pArc0 = pDiagComposition.inputArt.code if gDiagram['label'] == pArc0: pArc0 = 'Start' # Verifica si el nodo final es nulo, entonces end # Conserva el nombre diagrama y agrega un :Label try: pArc1 = pDiagComposition.outputArt.code except: pArc1 = 'End' pArc01 = { 'n0': slugify( pArc0 ) , 'n1': slugify( pArc1 ) } self.arcs.append(pArc01) gDiagram['arcs'].append(pArc01) self.diagrams.append(gDiagram)
def getEntityCode(self, code, prefix): # Formatea el nombre de la entidad enttCode = code.lower() prefix = prefix or '' if len(prefix) and enttCode.startswith(prefix.lower()): enttCode = enttCode[len(prefix):] return getClassName(enttCode)
def exportProtoJson(request, pModel): cViews = { 'code': pModel.code, 'model': slugify(pModel.code, '_'), 'entities': {}, } for pEntity in pModel.entity_set.all(): # Do not delete ( dgt ) cEntity = { 'code': pEntity.code, 'entity': getClassName(pEntity.code), 'fullName': cViews['model'] + '.' + getClassName(pEntity.code), # 'properties' : {}, 'prototypes': {}, } cViews['entities'][cEntity['code']] = cEntity # Do not delete ( dgt ) # for pProperty in pEntity.property_set.all(): # # # cProperty = { # 'code' : pProperty.code, # 'property' : slugify(pProperty.code, '_'), # 'isForeign' : pProperty.isForeign, # # 'baseType' : pProperty.baseType, # 'prpLength' : pProperty.prpLength, # 'prpScale' : pProperty.prpScale, # # 'isPrimary' : pProperty.isPrimary, # 'isReadOnly' : pProperty.isReadOnly, # # 'isNullable' : pProperty.isNullable, # 'isRequired' : pProperty.isRequired, # 'isSensitive' : pProperty.isSensitive, # 'prpChoices' : pProperty.prpChoices, # 'prpDefault' : pProperty.prpDefault, # 'vType' : pProperty.vType, # # 'crudType' : pProperty.crudType, # 'description' : pProperty.description, # 'notes' : pProperty.notes, # # 'dbName' : pProperty.dbName, # 'isEssential' : pProperty.isEssential, # 'isLookUpResult' : pProperty.isLookUpResult, # } # # # if pProperty.isForeign: # cProperty[ 'refEntity' ] = pProperty.relationship.refEntity.code # cProperty[ 'refCode' ] = getClassName( pProperty.relationship.refEntity.code ) # # cProperty[ 'baseMax'] = pProperty.relationship.baseMax # cProperty[ 'baseMin'] = pProperty.relationship.baseMin # cProperty[ 'onRefDelete'] = pProperty.relationship.onRefDelete # cProperty[ 'refMax'] = pProperty.relationship.refMax # cProperty[ 'refMin'] = pProperty.relationship.refMin # cProperty[ 'relatedName'] = pProperty.relationship.relatedName # cProperty[ 'typeRelation'] = pProperty.relationship.typeRelation # # cEntity['properties'][ cProperty['code'] ] = cProperty for pPrototype in pEntity.prototype_set.all(): # Migration proto - App sAux = pPrototype.metaDefinition.replace("info__", "").replace("-", "_") sAux = sAux.replace("prototype.ProtoTable.", "") sAux = sAux.replace('"' + slugify(pModel.code, '_') + '_', '"' + cViews['model'] + '.') cProto = json.loads(sAux) # Propiedades de base try: del cProto['jsonField'] del cProto['protoEntity'] del cProto['protoEntityId'] del cProto['__ptType'] except: pass cProto['localSort'] = False cProto['viewIcon'] = 'icon-1' cProto['viewEntity'] = cEntity['fullName'] # Elimina campos de control de prototypos y redirecciona zooms newFields = [] for fld in cProto['fields']: if fld['name'] in ['entity', 'entity_id', 'info']: continue if fld['name'] == '__str__': try: del fld['cpFromZoom'] del fld['cpFromField'] del fld['physicalName'] except: pass try: del fld['__ptType'] except: pass newFields.append(fld) cProto['fields'] = newFields cPrototype = { 'code': pPrototype.code, 'description': pPrototype.description, 'notes': cEntity['fullName'], 'metaDefinition': cProto } cEntity['prototypes'][cPrototype['code']] = cPrototype # Creacion de la vista try: protoDef = ProtoDefinition.objects.get_or_create( code=cProto['viewCode'])[0] protoDef.active = True protoDef.overWrite = False protoDef.description = cEntity.get('fullName', '') + ' - ' + cProto.get( 'viewCode', '') + '<br>' protoDef.description += cProto.get( 'shortTitle', '') + '<br>' + cProto.get('description', '') protoDef.metaDefinition = json.dumps(cProto, cls=JSONEncoder) protoDef.save() except: pass return json.dumps(cViews, cls=JSONEncoder, sort_keys=True, indent=4, separators=(',', ':'))
def exportPrototypeModel(request, pModel): strModel = StringIO() modelCode = slugify(pModel.code, '_') strModel.write("# -*- coding: utf-8 -*-\n\n") strModel.write('# This is an auto-generated model module by CeRTAE SoftMachine v13.12dgt\n' ) strModel.write("# for model : \"{0}\"\n".format( modelCode ) ) strModel.write("# You'll have to do the following manually to clean this up:\n") strModel.write("# * Add specific procedures (WFlow)\n\n") strModel.write("from django.db import models\n") strModel.write("from protoLib.models import ProtoModel\n") strModel.write("from protoLib.utilsBase import slugify\n") for pEntity in pModel.entity_set.all(): strModel.write( "\n" ) strModel.write( "class {0}(ProtoModel):\n".format( getClassName( pEntity.code ) )) arrKeys = [] # Field Str Formating # 0. pCode, # 1. pType, # 2. strNull, # 3. str( intLength ), # 4. str( intScale ) # 5. slugify(pEntity.code, '_') for pProperty in pEntity.property_set.all(): pCode = slugify(pProperty.code, '_') if pProperty.isForeign: pType = getClassName( pProperty.relationship.refEntity.code ) strAux = "{0} = models.ForeignKey('{1}', blank= {2}, null= {2}, related_name='{5}_{0}')\n" # RelatedName Entity_Field? # on_delete={5} : CASCADE, PROTECT, SET_NULL else: pType = TypeEquivalence.get( pProperty.baseType , 'CharField') # prpDefault intLength = pProperty.prpLength intScale = pProperty.prpScale if pType == 'CharField': strAux = "{0} = models.{1}(blank= {2}, null= {2}, max_length= {3})\n" if intLength == 0: intLength = 200 elif pType == 'DecimalField': strAux = "{0} = models.{1}(blank= {2}, null= {2}, max_digits={3}, decimal_places= {4})\n" if intLength == 0 or intLength > 24 : intLength = 48 if intScale < 0 or intScale > intLength : intScale = 2 elif pType == 'BooleanField': strAux = "{0} = models.{1}()\n" else: strAux = "{0} = models.{1}(blank = {2}, null = {2})\n" # isRequired isNullable: if pProperty.isRequired: strNull = 'False' else: strNull = 'True' if pProperty.isPrimary: arrKeys.append( pCode ) strModel.write( repStr(' ',4) + strAux.format( pCode, pType, strNull, str( intLength ), str( intScale ), slugify(pEntity.code, '_') )) strModel.write("\n") strModel.write(repStr(' ',4)+ "def __unicode__(self):\n") if arrKeys.__len__() > 0: # Unicode strOptions = '' for pProperty in pEntity.property_set.all(): if not pProperty.isPrimary : continue if strOptions.__len__() > 0: strOptions += " + '.' + " if pProperty.isForeign or not ( pProperty.baseType in [ 'string', 'text' ] ): strAux = 'str( self.{0})'.format( slugify(pProperty.code, '_')) else : strAux = 'self.{0}'.format( slugify(pProperty.code, '_')) strOptions += strAux strModel.write( repStr(' ',8) + "return slugify({0})\n".format( strOptions )) #meta strModel.write("\n") strModel.write(repStr(' ',4)+ "class Meta:\n") strOptions = '' for pCode in arrKeys: strOptions += "'{0}',".format( pCode ) strModel.write( repStr(' ',8) + "unique_together = ({0})\n".format( strOptions )) else: strModel.write( repStr(' ',8) + "return 'NoKey'") strAux = strModel.getvalue() strModel.close() return strAux
def getDiagramDefinition(self, diagramSet): self.diagrams = [] self.entities = [] for pDiag in diagramSet: gDiagram = { 'code': getClassName(pDiag.code), 'label': pDiag.code, 'clusterName': getattr(pDiag, 'title', pDiag.code), 'graphLevel': getattr(pDiag, 'graphLevel', self.GRAPH_LEVEL.all), 'graphForm': getattr(pDiag, 'graphForm', self.GRAPH_FORM.orf), 'showPrpType': getattr(pDiag, 'showPrpType', False), 'showBorder': getattr(pDiag, 'showBorder', False), 'prefix': getattr(pDiag, 'prefix', ''), 'entities': [] } for pDiagEntity in pDiag.diagramentity_set.all(): pEntity = pDiagEntity.entity enttCode = self.getEntityCode(pEntity.code, gDiagram.get('prefix')) if enttCode in self.entities: continue self.entities.append(enttCode) gEntity = {'code': enttCode, 'fields': [], 'relations': []} for pProperty in pEntity.property_set.all(): pptCode = slugify(pProperty.code, '_') if pProperty.isForeign: pType = self.getEntityCode( pProperty.relationship.refEntity.code, gDiagram.get('prefix')) gEntity['relations'].append({ 'code': pptCode, 'type': pType, 'primary': pProperty.isPrimary, 'required': pProperty.isRequired, 'essential': pProperty.isEssential, 'foreign': True }) else: pType = slugify(pProperty.baseType, '_') gEntity['fields'].append({ 'code': pptCode, 'type': pType or 'string', 'primary': pProperty.isPrimary, 'required': pProperty.isRequired, 'essential': pProperty.isEssential, 'foreign': False }) gDiagram['entities'].append(gEntity) self.diagrams.append(gDiagram)
def exportProtoJson(request, pModel ): cViews = { 'code' : pModel.code, 'model': slugify(pModel.code, '_'), 'entities' : {}, } for pEntity in pModel.entity_set.all(): # Do not delete ( dgt ) cEntity = { 'code' : pEntity.code, 'entity' : getClassName( pEntity.code ), 'fullName' : cViews['model' ] + '.' + getClassName( pEntity.code ), # 'properties' : {}, 'prototypes' : {}, } cViews['entities'][ cEntity['code'] ] = cEntity # Do not delete ( dgt ) # for pProperty in pEntity.property_set.all(): # # # cProperty = { # 'code' : pProperty.code, # 'property' : slugify(pProperty.code, '_'), # 'isForeign' : pProperty.isForeign, # # 'baseType' : pProperty.baseType, # 'prpLength' : pProperty.prpLength, # 'prpScale' : pProperty.prpScale, # # 'isPrimary' : pProperty.isPrimary, # 'isReadOnly' : pProperty.isReadOnly, # # 'isNullable' : pProperty.isNullable, # 'isRequired' : pProperty.isRequired, # 'isSensitive' : pProperty.isSensitive, # 'prpChoices' : pProperty.prpChoices, # 'prpDefault' : pProperty.prpDefault, # 'vType' : pProperty.vType, # # 'crudType' : pProperty.crudType, # 'description' : pProperty.description, # 'notes' : pProperty.notes, # # 'dbName' : pProperty.dbName, # 'isEssential' : pProperty.isEssential, # 'isLookUpResult' : pProperty.isLookUpResult, # } # # #TODO: 'propertyModel' :pProperty.propertyModel, # # if pProperty.isForeign: # cProperty[ 'refEntity' ] = pProperty.relationship.refEntity.code # cProperty[ 'refCode' ] = getClassName( pProperty.relationship.refEntity.code ) # # cProperty[ 'baseMax'] = pProperty.relationship.baseMax # cProperty[ 'baseMin'] = pProperty.relationship.baseMin # cProperty[ 'onRefDelete'] = pProperty.relationship.onRefDelete # cProperty[ 'refMax'] = pProperty.relationship.refMax # cProperty[ 'refMin'] = pProperty.relationship.refMin # cProperty[ 'relatedName'] = pProperty.relationship.relatedName # cProperty[ 'typeRelation'] = pProperty.relationship.typeRelation # # cEntity['properties'][ cProperty['code'] ] = cProperty for pPrototype in pEntity.prototype_set.all(): # Migration proto - App sAux = pPrototype.metaDefinition.replace("info__","").replace("-","_" ) sAux = sAux.replace("prototype.ProtoTable.","" ) sAux = sAux.replace( '"' + slugify(pModel.code, '_') + '_', '"' + cViews['model' ] + '.' ) cProto = json.loads( sAux ) # Propiedades de base try: del cProto[ 'jsonField' ] del cProto[ 'protoEntity' ] del cProto[ 'protoEntityId' ] del cProto['__ptType'] except: pass cProto[ 'localSort' ] = False cProto[ 'viewIcon' ] = 'icon-1' cProto[ 'viewEntity' ] = cEntity[ 'fullName'] # Elimina campos de control de prototypos y redirecciona zooms newFields = [] for fld in cProto['fields'] : if fld['name'] in [ 'entity', 'entity_id', 'info' ]: continue if fld['name'] == '__str__': try: del fld['cpFromZoom'] del fld['cpFromField'] del fld['physicalName'] except: pass try: del fld['__ptType'] except: pass newFields.append( fld ) cProto['fields'] = newFields cPrototype = { 'code' : pPrototype.code, 'description' : pPrototype.description, 'notes' : cEntity[ 'fullName'], 'metaDefinition' : cProto } cEntity['prototypes'][ cPrototype['code'] ] = cPrototype # Creacion de la vista try: protoDef = ProtoDefinition.objects.get_or_create(code = cProto[ 'viewCode' ] )[0] protoDef.active = True protoDef.overWrite = False protoDef.description = cEntity.get('fullName','') + ' - ' + cProto.get('viewCode','') + '<br>' protoDef.description += cProto.get('shortTitle','') + '<br>' + cProto.get( 'description','') protoDef.metaDefinition = json.dumps( cProto, cls = JSONEncoder ) protoDef.save() except : pass return json.dumps( cViews , cls = JSONEncoder , sort_keys= True, indent = 4, separators=(',', ':') )
def getDiagramDefinition(self, diagramSet): self.diagrams = [] self.entities = [] for pDiag in diagramSet: gDiagram = { 'code': getClassName(pDiag.code) , 'label': slugify( pDiag.code ), 'clusterName': slugify( getattr(pDiag, 'title', pDiag.code)), 'graphLevel' : getattr(pDiag, 'graphLevel' , self.GRAPH_LEVEL.all), 'graphForm' : getattr(pDiag, 'graphForm' , self.GRAPH_FORM.orf), 'showPrpType': getattr(pDiag, 'showPrpType' , False), 'showBorder' : getattr(pDiag, 'showBorder' , False), 'showFKey' : getattr(pDiag, 'showFKey' , False), 'prefix' : slugify( getattr(pDiag, 'prefix' , '')), 'entities': [] } for pDiagEntity in pDiag.diagramentity_set.all(): pEntity = pDiagEntity.entity enttCode = self.getEntityCode(pEntity.code, gDiagram.get('prefix')) # Si ya se encuentra en otro diagrama no la dibuja if enttCode in self.entities: continue self.entities.append(enttCode) gEntity = { 'code': enttCode, 'fields': [], 'relations': [] } for pProperty in pEntity.property_set.all(): pptCode = slugify(pProperty.code, '_') if pProperty.isForeign: pLinkTo = self.getEntityCode(pProperty.relationship.refEntity.code, gDiagram.get('prefix')) gEntity['relations'].append({ 'code': pptCode, 'linkTo': pLinkTo, 'primary': pProperty.isPrimary, 'required': pProperty.isRequired, 'essential': pProperty.isEssential, 'foreign': True }) else: pType = slugify(pProperty.baseType , '_') gEntity['fields'].append({ 'code': pptCode, 'type': pType or 'string', 'primary': pProperty.isPrimary, 'required': pProperty.isRequired, 'essential': pProperty.isEssential, 'foreign': False }) gDiagram['entities'].append(gEntity) self.diagrams.append(gDiagram)
def exportPrototypeModel(request, pModel): strModel = StringIO() modelCode = slugify(pModel.code, '_') strModel.write("# -*- coding: utf-8 -*-\n\n") strModel.write( '# This is an auto-generated model module by CeRTAE SoftMachine v13.12dgt\n' ) strModel.write("# for model : \"{0}\"\n".format(modelCode)) strModel.write( "# You'll have to do the following manually to clean this up:\n") strModel.write("# * Add specific procedures (WFlow)\n\n") strModel.write("from django.db import models\n") strModel.write("from protoLib.models import ProtoModel\n") strModel.write("from protoLib.utilsBase import slugify\n") for pEntity in pModel.entity_set.all(): strModel.write("\n") strModel.write("class {0}(ProtoModel):\n".format( getClassName(pEntity.code))) arrKeys = [] # Field Str Formating # 0. pCode, # 1. pType, # 2. strNull, # 3. str( intLength ), # 4. str( intScale ) # 5. slugify(pEntity.code, '_') for pProperty in pEntity.property_set.all(): pCode = slugify(pProperty.code, '_') if pProperty.isForeign: pType = getClassName(pProperty.relationship.refEntity.code) strAux = "{0} = models.ForeignKey('{1}', blank= {2}, null= {2}, related_name='{5}_{0}')\n" # RelatedName Entity_Field? # on_delete={5} : CASCADE, PROTECT, SET_NULL else: pType = TypeEquivalence.get(pProperty.baseType, 'CharField') # prpDefault intLength = pProperty.prpLength intScale = pProperty.prpScale if pType == 'CharField': strAux = "{0} = models.{1}(blank= {2}, null= {2}, max_length= {3})\n" if intLength == 0: intLength = 200 elif pType == 'DecimalField': strAux = "{0} = models.{1}(blank= {2}, null= {2}, max_digits={3}, decimal_places= {4})\n" if intLength == 0 or intLength > 24: intLength = 48 if intScale < 0 or intScale > intLength: intScale = 2 elif pType == 'BooleanField': strAux = "{0} = models.{1}()\n" else: strAux = "{0} = models.{1}(blank = {2}, null = {2})\n" # isRequired isNullable: if pProperty.isRequired: strNull = 'False' else: strNull = 'True' if pProperty.isPrimary: arrKeys.append(pCode) strModel.write( repStr(' ', 4) + strAux.format(pCode, pType, strNull, str(intLength), str(intScale), slugify(pEntity.code, '_'))) strModel.write("\n") strModel.write(repStr(' ', 4) + "def __unicode__(self):\n") if arrKeys.__len__() > 0: # Unicode strOptions = '' for pProperty in pEntity.property_set.all(): if not pProperty.isPrimary: continue if strOptions.__len__() > 0: strOptions += " + '.' + " if pProperty.isForeign or not (pProperty.baseType in ['string', 'text']): strAux = 'str( self.{0})'.format( slugify(pProperty.code, '_')) else: strAux = 'self.{0}'.format(slugify(pProperty.code, '_')) strOptions += strAux strModel.write( repStr(' ', 8) + "return slugify({0})\n".format(strOptions)) #meta strModel.write("\n") strModel.write(repStr(' ', 4) + "class Meta:\n") strOptions = '' for pCode in arrKeys: strOptions += "'{0}',".format(pCode) strModel.write( repStr(' ', 8) + "unique_together = ({0})\n".format(strOptions)) else: strModel.write(repStr(' ', 8) + "return 'NoKey'") strAux = strModel.getvalue() strModel.close() return strAux