def convert_form_name(form_name): """ Usage: convert_form_name('EditAgreementItem') :param form_name: :return: like 'Edit Agreement Item' """ from sagas.util.str_converters import to_camel_case, to_snake_case, to_words return to_words(to_snake_case(form_name), True)
def gen_model(entity_name, mutations_c): gen_ctx = {} gen_ctx['model'] = entity_name gen_ctx['s_model'] = to_snake_case(entity_name) ent = oc.delegator.getModelEntity(entity_name) autoflds = ent.getAutomaticFieldNames() model_c = [] model_c.append("class {ctx[model]}Input(graphene.InputObjectType):".format(ctx=gen_ctx)) names = ent.getAllFieldNames() for field_name in names: if field_name not in autoflds: fld = ent.getField(field_name) fldtype = get_graphql_type(fld.getType()) model_c.append(" {name} = graphene.{type}()".format(name=to_snake_case(field_name), type=fldtype)) # print("\n".join(model_c)) model_c.append(creator_def.format(ctx=gen_ctx)) mutations_c.append(" create_{ctx[s_model]} = Create{ctx[model]}.Field()".format(ctx=gen_ctx)) print("\n".join(model_c))
def gen_model(entity_name): lines = [] resolvers = [] ent = oc.delegator.getModelEntity(entity_name) lines.append("class {ent}(ModelBase):".format(ent=entity_name)) names = ent.getAllFieldNames() for field_name in names: fld = ent.getField(field_name) fldtype = get_graphql_type(fld.getType()) lines.append(" {name} = graphene.{type}()".format( name=to_snake_case(field_name), type=fldtype)) for rel in ent.getRelationsList(True, False, True): model_name = rel.getRelEntityName() # relation_name = rel.getTitle() + rel.getRelEntityName() rel_name = to_snake_case(rel.getTitle() + model_name) # extract relation fields inputs = [] for key in rel.getKeyMaps(): inputs.append("{}=self.{}".format( key.getRelFieldName(), to_snake_case(key.getFieldName()))) # build if rel.getType() == "many": method = "get_relations" lines.append( " {name} = graphene.List(lambda: {model})".format( name=rel_name, model=model_name)) else: method = "get_related_one" lines.append( " {name} = graphene.Field(lambda: {model})".format( name=rel_name, model=model_name)) resolvers.append( resover_def.format(rel_name=rel_name, model=model_name, method=method, inputs=", ".join(inputs))) return "\n".join(lines + resolvers)
def gen_dss_entity(meta): from sagas.util.str_converters import to_snake_case, to_words # print(to_words(to_snake_case('LinearSales'), True)) lines = [] entity_title = to_words(to_snake_case(meta.class_name), True) lines.append( ' <entity entity-name="{name}" package-name="com.sagas.dss" title="{title}">' .format(name=meta.class_name, title=entity_title)) for attr in meta.attributes: lines.append(' <field name="%s" type="%s"></field>' % (attr.prop_name, get_mapping_type(attr.prop_type))) # add the primary key prim = lower_first(meta.class_name) + "Id" lines.append(' <field name="%s" type="id"></field>' % prim) lines.append(' <prim-key field="%s"/>' % prim) lines.append(' </entity>') return ('\n'.join(lines))
def fill_record(self, model, val, rec): names = model.getAllFieldNames() for field_name in names: setattr(val, to_snake_case(field_name), rec[field_name])
def title(self): return to_words(to_snake_case(self.name), capfirst=True)