class User(Document):
    __collection__ = 'users'

    index = IntField(required=True)
    email = StringField(required=True)
    first_name = StringField(
        db_field="whatever", max_length=50, default=lambda: "Bernardo"
    )
    last_name = StringField(max_length=50, default="Heynemann")
    is_admin = BooleanField(default=True)
    website = URLField(default="http://google.com/")
    updated_at = DateTimeField(
        required=True, auto_now_on_insert=True, auto_now_on_update=True
    )
    embedded = EmbeddedDocumentField(
        EmbeddedDocument, db_field="embedded_document"
    )
    nullable = EmbeddedDocumentField(
        EmbeddedDocument, db_field="nullable_embedded_document"
    )
    numbers = ListField(IntField())

    posts = ListField(ReferenceField(reference_document_type=Post))

    def __repr__(self):
        return "%s %s <%s>" % (self.first_name, self.last_name, self.email)
Example #2
0
class User(Document):
    __collection__ = "AggregationUser"

    email = StringField(required=True)
    first_name = StringField(max_length=50, default=lambda: "Bernardo")
    last_name = StringField(max_length=50, default="Heynemann")
    is_admin = BooleanField(default=True)
    updated_at = DateTimeField(required=True,
                               auto_now_on_insert=True,
                               auto_now_on_update=True)
    number_of_documents = IntField()
    list_items = ListField(IntField())
Example #3
0
class Lesson(Document):
    id = IntField()
    name = StringField(required=True)
    audience = StringField()
    teacher_name = StringField()
    lesson_type = StringField()
    start_time = StringField()
    color = StringField()
    comments = ListField(EmbeddedDocumentField(embedded_document_type=Comment))
    day = ReferenceField('DayTimetable')
Example #4
0
class User(BaseDocument):
    mobile = StringField(required=True)
    password = StringField(required=True)
    nickname = StringField(required=True)
    gender = IntField(required=True, default=1)
    description = StringField()
    avatar_url = StringField()

    school_id = ReferenceField(reference_document_type=School)
    like_count = IntField(required=True, default=0)
    follower_count = IntField(required=True, default=0)
    following_count = IntField(required=True, default=0)

    create_time = DateTimeField(required=True,
                                auto_now_on_insert=True,
                                auto_now_on_update=False)

    def to_dict(self):
        data = super(User, self).to_dict()
        del data['password']
        return data
Example #5
0
    def test_from_son(self):
        field = IntField()

        expect(field.from_son(10)).to_equal(10)
        expect(field.from_son(10.0)).to_equal(10)
        expect(field.from_son(10.0230)).to_equal(10)
        expect(field.from_son("10")).to_equal(10)
Example #6
0
    def test_validate_enforces_integers(self):
        field = IntField()

        expect(field.validate(1)).to_be_true()
        expect(field.validate("1")).to_be_true()
        expect(field.validate("qwe")).to_be_false()
        expect(field.validate(None)).to_be_true()
Example #7
0
class User(Document):
    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)

    id = IntField(unique=True)
    email = EmailField()

    _salt = BinaryField(12)
    # 64 is the length of the SHA-256 encoded string length
    _password = StringField(64)

    group = ReferenceField('scheduler.model.Group')
    timetable = EmbeddedDocumentField('scheduler.model.Schedule')
Example #8
0
    def test_to_son(self):
        field = IntField()

        expect(field.to_son(10)).to_equal(10)
        expect(field.to_son(10.0)).to_equal(10)
        expect(field.to_son(10.0230)).to_equal(10)
        expect(field.to_son("10")).to_equal(10)
        expect(field.to_son(None)).to_equal(None)
Example #9
0
class CardDocument(BaseDocument):
    """Данные по карточке.

    :type message: str Текст сообщения карточки;
    :type position: int Порядковый номер позиции в списке карточек;
    """
    __collection__ = "card"
    __lazy__ = False

    message = StringField(required=True)
    position = IntField(required=True)
    listCards = ReferenceField(ListCardsDocument)

    async def check_permission(self, document_user: UserDocument):
        """Проверка прав доступа к текущему документу у определенного пользователя."""
        collection_list_cards = await ListCardsDocument().objects.filter({"_id": self.listCards._id}).find_all()
        if not collection_list_cards:
            return False
        document_list_cards = collection_list_cards[-1]
        return document_list_cards.check_permission(document_user)
Example #10
0
class ListCardsDocument(BaseDocument):
    """Список с карточками.

    :type title: str Заголовок списка;
    :type cards: list Набор карточек актуальных для списка;
    :type position: int Порядковый номер позиции в ряде списков;
    """
    __collection__ = "listCards"
    __lazy__ = False

    title = StringField(required=True)
    position = IntField(required=True)
    board = ReferenceField(BoardDocument)

    async def check_permission(self, document_user: UserDocument):
        """Проверка прав доступа к текущему документу у определенного пользователя."""
        collection_board = await BoardDocument().objects.filter({"_id": self.board._id}).find_all()
        if not collection_board:
            return False
        document_board = collection_board[-1]
        return document_board.check_permission(document_user)
Example #11
0
class City(Document):
    __collection__ = "AggregationCity"

    city = StringField()
    state = StringField()
    pop = IntField()
Example #12
0
class Action(Document):
    __collection__ = "actions"

    action_type = IntField(required=True)
    payload = EmbeddedDocumentField(embedded_document_type=Document)
Example #13
0
 class TestEmbedded(Document):
     __collection__ = "TestEmbedded"
     num = IntField()
Example #14
0
 class SizeDocument(Document):
     items = ListField(IntField())
     item_size = IntField(default=0, on_save=lambda doc, creating: len(doc.items))
Example #15
0
 class Child(Document):
     __collection__ = "MultipleOperatorsTest"
     num = IntField()
Example #16
0
 class Child(Document):
     __collection__ = "NotOperatorTest"
     num = IntField()
Example #17
0
 class Test2(Document):
     __collection__ = "EmbeddedExistsTest"
     test = IntField()
Example #18
0
 class Child(Document):
     __collection__ = "EmbeddedIsNullTest"
     num = IntField()
Example #19
0
 class Test(Document):
     __collection__ = "GreaterThan"
     test = IntField()
Example #20
0
 class Test(Document):
     __collection__ = "LesserThanOrEqual"
     test = IntField()
class AssignmentInfoAction(Document):
    __collection__ = "assignment_info"
    device_uid = UUIDField()
    patient_uid = UUIDField()
    assignment_type = IntField()
Example #22
0
 def test_create_int_field(self):
     field = IntField(db_field="test", min_value=10, max_value=200)
     expect(field.db_field).to_equal("test")
     expect(field.min_value).to_equal(10)
     expect(field.max_value).to_equal(200)
Example #23
0
class Group(Document):
    id = IntField()
    name = StringField(required=True)
    users = ListField(ReferenceField('User'))
    university = ReferenceField('University')
    timetable = EmbeddedDocumentField(Schedule())
Example #24
0
    def test_validate_enforces_max_value(self):
        field = IntField(max_value=5)

        expect(field.validate(1)).to_be_true()
        expect(field.validate(6)).to_be_false()
        expect(field.validate("1")).to_be_true()
Example #25
0
    def test_is_empty(self):
        field = IntField()

        expect(field.is_empty(None)).to_be_true()
Example #26
0
class University(Document):
    id = IntField()
    name = StringField(required=True)
    groups = ListField(EmbeddedDocumentField(Group()))
Example #27
0
 class ElemMatchDocument(Document):
     items = ListField(IntField())
Example #28
0
 class ReferenceFieldClass(Document):
     __collection__ = "TestFindAllReferenceField"
     ref1 = ReferenceField(User)
     num = IntField(default=10)
Example #29
0
class User(Document):
    name = EmbeddedDocumentField(embedded_document_type=Name)
    email = StringField(db_field='email_address')
    numbers = ListField(base_field=IntField())