Ejemplo n.º 1
0
class Person(Collection):

    __collection__ = "persons"
    _allow_extra_fields = False
    _index = [{"type": "hash", "unique": False, "fields": ["name"]}]
    _allow_extra_fields = False  # prevent extra properties from saving into DB

    _key = String()
    name = String(required=True, allow_none=False)
    age = Integer(allow_none=True, missing=None)
    dob = Date(allow_none=True, missing=None)
    is_staff = Boolean(default=False)

    cars = relationship(__name__ + ".Car", "_key", target_field="owner_key")

    @property
    def is_adult(self):
        return self.age and self.age >= 18

    @lazy_property
    def lazy_is_adult(self):
        return self.age and self.age >= 18

    def __str__(self):
        return "<Person(" + self.name + ")>"
Ejemplo n.º 2
0
class Person(Collection):

    __collection__ = 'persons'
    _allow_extra_fields = False
    _index = [{'type': 'hash', 'unique': False, 'fields': ['name']}]
    _allow_extra_fields = False  # prevent extra properties from saving into DB

    _key = String(required=True)
    name = String(required=True, allow_none=False)
    age = Integer(missing=None)
    dob = Date()
    is_staff = Boolean(default=False)

    cars = relationship(__name__ + ".Car", '_key', target_field='owner_key')

    @property
    def is_adult(self):
        return self.age and self.age >= 18

    @lazy_property
    def lazy_is_adult(self):
        return self.age and self.age >= 18

    def __str__(self):
        return "<Person(" + self.name + ")>"
class Tasks(Collection):
    __collection__ = 'tasks'
    _key = String(required=True)
    title = String(required=True)
    description = String(required=True)
    due_date = Date(allow_none=True)

    def __str__(self):
        return "<Subject({})>".format(self.title)
class Employee(Collection):
    _allow_extra_fields = True
    __collection__ = 'employee'
    _index = [{'type': 'hash', 'unique': False, 'fields': ['name']}]
    _key = String(required=True)  # registration number
    name = String(required=True, allow_none=False)
    department_key = String(required=False)
    role_key = String(required=False)
    hired_on = Date(default=datetime.now)
    department = relationship(Department, field='department_key')
    role = relationship(Role, field='role_key')
Ejemplo n.º 5
0
class Shops(Collection):
    __collection__ = 'shops'

    _key = String(required=True, allow_none=False)
    name = String(required=True, allow_none=False)
    slogan = String()
    description = String()
    logoLocation = String()
    geolocation = Field()  #what kind of datatype is geolocal data?
    foundingDate = Date()

    def __str__(self):
        return "<Subject({})>".format(self.name)
Ejemplo n.º 6
0
        class MyModel(Collection):
            __collection__ = "MyCollection"

            _key = String(allow_none=True)
            integer = Integer(allow_none=True)
            datetime = DateTime(allow_none=True)
            url = Url(allow_none=True)
            bool_val = Boolean(allow_none=True)
            str_list = List(String, allow_none=True)
            floater = Float(allow_none=True)
            date = Date(allow_none=True)
            timedelta = TimeDelta(allow_none=True)
            email = Email(allow_none=True)
            number = Number(allow_none=True)
            uuid = UUID(allow_none=True)
            d = Dict(allow_none=True)
Ejemplo n.º 7
0
        class MyModel(Collection):
            __collection__ = "MyCollection"

            _key = String()
            integer = Integer()
            datetime = DateTime()
            url = Url()
            bool_val = Boolean()
            str_list = List(String)
            floater = Float()
            date = Date()
            timedelta = TimeDelta()
            email = Email()
            number = Number()
            uuid = UUID()
            d = Dict()
Ejemplo n.º 8
0
class User(Collection):

    __collection__ = 'user'
    _index = [{'type': 'hash', 'unique': False, 'fields': ['username']}]
    # _key = String(required=True)

    # firstname = String(required=True, allow_none=True)
    # lastname = String(required=True, allow_none=True)
    username = String(required=True, allow_none=False)
    password = String(required=True, allow_none=False)
    email = String(required=True, allow_none=False)
    is_active = Boolean(required=True, default=False, allow_none=False)
    is_superuser = Boolean(required=True, default=False, allow_none=False)
    dob = Date(required=True, allow_none=True)
    # createdate = DateTime(required=True, allow_none=False)

    @property
    def key(self):
        return self._key
Ejemplo n.º 9
0
class Person(Collection):
    class Hobby(Collection):
        class Equipment(Collection):
            name = String(required=False, allow_none=True)
            price = Number(required=False, allow_none=True)

        name = String(required=False, allow_none=True)
        type = String(required=True, allow_none=False)
        equipment = List(Nested(Equipment.schema()),
                         required=False,
                         allow_none=True,
                         default=None)

    __collection__ = "persons"
    _allow_extra_fields = False
    _index = [{"type": "hash", "unique": False, "fields": ["name"]}]
    _allow_extra_fields = False  # prevent extra properties from saving into DB

    _key = String()
    name = String(required=True, allow_none=False)
    age = Integer(allow_none=True, missing=None)
    dob = Date(allow_none=True, missing=None)
    is_staff = Boolean(default=False)
    favorite_hobby = Nested(Hobby.schema(),
                            required=False,
                            allow_none=True,
                            default=None)
    hobby = List(Nested(Hobby.schema()),
                 required=False,
                 allow_none=True,
                 default=None)
    cars = relationship(__name__ + ".Car", "_key", target_field="owner_key")

    @property
    def is_adult(self):
        return self.age and self.age >= 18

    @lazy_property
    def lazy_is_adult(self):
        return self.age and self.age >= 18

    def __str__(self):
        return "<Person(" + self.name + ")>"