pfunk.tests

View Source
from pfunk import Collection, StringField, EnumField, Enum, ReferenceField, SlugField
from pfunk.resources import Index
from pfunk.contrib.auth.collections import User, Group
from pfunk.contrib.auth.resources import GenericGroupBasedRole, GenericUserBasedRole

GENDER_PRONOUN = Enum(name='gender_pronouns', choices=['he', 'her', 'they'])


class SimpleIndex(Index):
    name = 'simple-index'
    terms = ['name', 'slug']
    unique = True
    source = 'Project'


class Sport(Collection):
    use_crud_functions = True
    name = StringField(required=True)
    slug = SlugField()

    def __unicode__(self):
        return self.name

    class Meta:
        unique_together = [('name', 'slug')]


class Person(Collection):
    collection_roles = [GenericGroupBasedRole]
    verbose_plural_name = 'people'
    first_name = StringField(required=True)
    last_name = StringField(required=True)
    gender_pronoun = EnumField(GENDER_PRONOUN)
    sport = ReferenceField(Sport)
    group = ReferenceField(Group)

    def __unicode__(self):
        return f"{self.first_name} {self.last_name}"


class House(Collection):
    collection_roles = [GenericUserBasedRole]
    address = StringField(required=True)
    user = ReferenceField(User)

    def __unicode__(self):
        return self.address
#   class SimpleIndex(pfunk.resources.Index):
View Source
class SimpleIndex(Index):
    name = 'simple-index'
    terms = ['name', 'slug']
    unique = True
    source = 'Project'
#   name: str = 'simple-index'
#   terms: list = ['name', 'slug']
#   unique: bool = True
#   source: str = 'Project'
View Source
class Sport(Collection):
    use_crud_functions = True
    name = StringField(required=True)
    slug = SlugField()

    def __unicode__(self):
        return self.name

    class Meta:
        unique_together = [('name', 'slug')]

Base class for all pFunk Collection classes. In Fauna, a Collection is analogous to a table in Postgresql or MySQL. This class is analogous to a model in Django.

#   use_crud_functions: bool = True

Specifies whether to create the CRUD functions

#   class Sport.Meta:
View Source
    class Meta:
        unique_together = [('name', 'slug')]
#   Sport.Meta()
#   unique_together = [('name', 'slug')]
View Source
class Person(Collection):
    collection_roles = [GenericGroupBasedRole]
    verbose_plural_name = 'people'
    first_name = StringField(required=True)
    last_name = StringField(required=True)
    gender_pronoun = EnumField(GENDER_PRONOUN)
    sport = ReferenceField(Sport)
    group = ReferenceField(Group)

    def __unicode__(self):
        return f"{self.first_name} {self.last_name}"

Base class for all pFunk Collection classes. In Fauna, a Collection is analogous to a table in Postgresql or MySQL. This class is analogous to a model in Django.

#   collection_roles: list = [<class 'pfunk.contrib.auth.resources.GenericGroupBasedRole'>]

Roles that are attached to this collection.

#   verbose_plural_name: str = 'people'

Overrides the default plural collection name.

View Source
class House(Collection):
    collection_roles = [GenericUserBasedRole]
    address = StringField(required=True)
    user = ReferenceField(User)

    def __unicode__(self):
        return self.address

Base class for all pFunk Collection classes. In Fauna, a Collection is analogous to a table in Postgresql or MySQL. This class is analogous to a model in Django.

#   collection_roles: list = [<class 'pfunk.contrib.auth.resources.GenericUserBasedRole'>]

Roles that are attached to this collection.