def __new__(cls, name, bases, attrs): # Also ensure initialization is only performed for subclasses of Model # (excluding Model class itself). if not is_base_type(bases, DeferredEnumMeta): return type.__new__(cls, name, bases, attrs) meta = attrs.pop('Meta', None) if meta is None: raise AssertionError('Meta is required for deferred enum type.') if not hasattr(meta, 'values') or not isinstance( meta.values, DeferredAttr): raise AssertionError( 'Incorrect `Meta.values` in deferred enum type.') class DeferredOptions(Options): _values = meta.values @property def enum(self): attrs.update(self._values()) return PyEnum(cls.__name__, attrs) delattr(meta, 'values') attrs['__eq__'] = eq_enum options = DeferredOptions(meta, name=name, description=trim_docstring( attrs.get('__doc__'))) new_attrs = OrderedDict(attrs, _meta=options, **options.enum.__members__) return type.__new__(cls, name, bases, new_attrs)
def __new__(cls, name, bases, attrs): # Also ensure initialization is only performed for subclasses of # DeferredUnion if not is_base_type(bases, DeferredUnionMeta): return type.__new__(cls, name, bases, attrs) meta = attrs.pop('Meta', None) if meta is None: raise AssertionError('Meta is required for union type.') if hasattr(meta, 'types') and isinstance(meta.types, DeferredAttr): class DeferredOptions(Options): _types = meta.types @property def types(self): return self._types() delattr(meta, 'types') options = DeferredOptions(meta, name=name, description=trim_docstring( attrs.get('__doc__'))) else: options = Options( meta, name=name, description=trim_docstring(attrs.get('__doc__')), types=(), ) assert (isinstance(options.types, (list, tuple)) and len(options.types) > 0 ), 'Must provide types for Union {}.'.format(options.name) return type.__new__(cls, name, bases, dict(attrs, _meta=options))
def get_field_description(field, registry=None): """ Common metadata includes verbose_name and help_text. http://docs.mongoengine.org/apireference.html#fields """ parts = [] if hasattr(field, "document_type"): doc = trim_docstring(field.document_type.__doc__) if doc: parts.append(doc) if hasattr(field, "verbose_name"): parts.append(field.verbose_name.title()) if hasattr(field, "help_text"): parts.append(field.help_text) if field.db_field != field.name: name_format = "(%s)" if parts else "%s" parts.append(name_format % field.db_field) return "\n".join(parts)
class Meta: model = models.Contact description = trim_docstring(models.Contact.__doc__)
class Contact(SQLAlchemyObjectType, interfaces=[Node]): contact_id = graphene.Int() note = graphene.String() note_format = graphene.String() class Meta: model = models.Contact description = trim_docstring(models.Contact.__doc__) def resolve_contact_id(self, info): return self.id def resolve_note(self, info): return self.note def resolve_note_format(self, info): return self.note_format # add relationships and proxies pronouns_list = graphene.Field( graphene.List(Pronouns), description=trim_docstring(models.Contact.pronouns_list.__doc__) ) pronouns = graphene.Field( Pronouns, description=trim_docstring(models.Contact.pronouns.__doc__) ) name = graphene.String( category=graphene.String(), description=trim_docstring(models.Contact.name.__doc__) ) names = graphene.Field( graphene.List(ContactName), description=trim_docstring(models.Contact.contact_names_list.__doc__) ) email = graphene.String( category=graphene.String(), description=trim_docstring(models.Contact.email.__doc__) ) emails = graphene.Field( graphene.List(ContactEmail), description=trim_docstring(models.Contact.contact_names_list.__doc__) ) tags = graphene.Field( graphene.List(ContactTag), description=trim_docstring(models.Contact.tags.__doc__) ) def resolve_pronouns_list(self, info): return self.pronouns_list def resolve_pronouns(self, info): return self.pronouns def resolve_name(self, info, category=None): if category: return self.names.get(category, None) return self.name def resolve_names(self, info): return self.contact_names_list def resolve_email(self, info, category=None): if category: return self.emails.get(category, None) return self.email def resolve_emails(self, info): return self.contact_emails_list def resolve_tags(self, info): return self.tags
class Meta: model = models.Tag description = trim_docstring(models.Tag.__doc__)
class Meta: model = models.Pronouns description = trim_docstring(models.Pronouns.__doc__)
class Meta: model = models.User exclude_fields = ('password',) description = trim_docstring(models.User.__doc__)