class Categories(Collection):
    __collection__ = 'categories'
    _key = String(required=True)
    name = String(required=True)

    def __str__(self):
        return "<Subject({})>".format(self.name)
Пример #2
0
class DummyRelation(Relation):

    __collection__ = "dummy_relation"

    _key = String(required=True)
    _from = String()
    _to = String()
Пример #3
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 + ")>"
Пример #4
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 + ")>"
class Student(Collection):

    __collection__ = 'students'

    _key = String(required=True)  # registration number
    name = String(required=True, allow_none=False)
    age = Integer()
class People(Collection):
    __collection__ = 'people'

    _key = String(required=True)
    name = String(required=True)

    def __str__(self):
        return "<Subject({})>".format(self.name)
Пример #7
0
class Teacher(Collection):
    __collection__ = "teachers"

    _key = String(required=True)  # employee id
    name = String(required=True)

    def __str__(self):
        return "<Teacher({})>".format(self.name)
Пример #8
0
class Book(Collection):
    """Class for Book node"""

    __collection__ = "books"

    _key = String(required=True)  # book_id
    authors = String(required=True)
    year = Integer(required=True)
    title = String(required=True)
    language = String(required=True)

    def __init__(self, book_id=None, authors=None, year=None, title=None, language=None):
        super(Book, self).__init__()
        self._key = book_id
        self.authors = authors
        self.year = year
        self.title = title
        self.language = language

    def insert(self):
        """Inserting book node to graph"""
        db.add(self)

    def find_by_id(self):
        book = db.query(Book).by_key(self._key)
        return book

    def linked_tags(self):
        """Return list of tags for specific book"""
        book = db.query(Book).by_key(self._key)
        graph.expand(book, depth=1, direction='any')
        tags = [tag._object_from.tag_name for tag in book._relations["tagged_to"]]
        return tags

    def link_to_tag(self, tag_id):
        """Create relationship (Book)-[:TAGGED_TO]->(Tag) """
        if self.find_by_id():
            tag = db.query(Tag).by_key(tag_id)
            db.add(graph.relation(self, Relation("tagged_to"), tag))

    @staticmethod
    def books():
        """Return list of all books"""
        books = db.query(Book).all()
        return books


    @staticmethod
    def most_popular_books():
        """ Returns books which are read by most amount of users """
        query = """
                FOR user IN users
                    FOR book IN INBOUND user reads
                        COLLECT book_doc=book WITH COUNT INTO amount
                        SORT book_doc, amount ASC
                        RETURN {"book":book_doc, "count":amount}
                """
        return graph.aql(query)
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)
Пример #10
0
class Student(Collection):
    __collection__ = "students"

    _key = String(required=True)  # registration number
    name = String(required=True, allow_none=False)
    age = Integer(allow_none=True, missing=None)

    def __str__(self):
        return "<Student({})>".format(self.name)
Пример #11
0
class Categories(Collection):
    __collection__ = 'productCategories'

    _key = String(required=True, allow_none=False)
    name = String(required=True, allow_none=False)
    description = String()

    def __str__(self):
        return "<Subject({})>".format(self.name)
Пример #12
0
class SpecializesIn(Relation):
    __collection__ = "specializes_in"

    _key = String()
    expertise_level = String(required=True,
                             options=["expert", "medium", "basic"])

    def __str__(self):
        return "<SpecializesIn(_key={}, expertise_level={}, _from={}, _to={})>".format(
            self._key, self.expertise_level, self._from, self._to)
Пример #13
0
class Vehicle(Collection):
    __collection__ = "vehicle"

    _inheritance_field = "discr"
    _inheritance_mapping = {'Bike': 'moto', 'Truck': 'truck'}

    _key = String()
    brand = String()
    model = String()
    discr = String(required=True)
Пример #14
0
class Subject(Collection):
    __collection__ = "subjects"

    _key = String(required=True)  # subject code
    name = String(required=True)
    credit_hours = Integer(allow_none=True, missing=None)
    has_labs = Boolean(missing=True)

    def __str__(self):
        return "<Subject({})>".format(self.name)
Пример #15
0
    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)
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')
Пример #17
0
class Clients(Collection):
    __collection__ = 'Clients'

    _key = String(required=True)
    name = String(required=True)
    username = String(required=True)
    password = String(required=True)
    courriel = String(required=True)

    def __str__(self):
        return "<Subject({}, {}, {}, {})>".format(self.name, self.username,
                                                  self.password, self.courriel)
Пример #18
0
class Products(Collection):
    __collection__ = 'products'

    _key = String(required=True, allow_none=False)
    name = String(required=True, allow_none=False)
    description = String()
    imageLocation = String()
    price = float()
    discount = float()

    def __str__(self):
        return "<Subject({})>".format(self.name)
Пример #19
0
class Car(Collection):
    __collection__ = "cars"
    _allow_extra_fields = True

    make = String(required=True)
    model = String(required=True)
    year = Integer(required=True)
    owner_key = String(allow_none=True, missing=None)

    owner = relationship(Person, "owner_key")

    def __str__(self):
        return "<Car({} - {} - {})>".format(self.make, self.model, self.year)
Пример #20
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)
Пример #21
0
class Car(Collection):

    __collection__ = 'cars'
    _allow_extra_fields = True

    make = String(required=True)
    model = String(required=True)
    year = Integer(required=True)
    owner_key = String()

    owner = relationship(Person, 'owner_key')

    def __str__(self):
        return "<Car({} - {} - {})>".format(self.make, self.model, self.year)
Пример #22
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 + ")>"
Пример #23
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
Пример #24
0
class Tag(Collection):
    """Class for Tag node"""

    __collection__ = "tags"

    _key = String(required=True)  # tag_id
    tag_name = String(required=True)

    def __init__(self, tag_id=None, tag_name=None):
        super(Tag, self).__init__()
        self._key = tag_id
        self.tag_name = tag_name

    def insert(self):
        """ Insert tag to graph"""
        db.add(self)

    def find_by_id(self):
        tag = db.query(Tag).by_key(self._key)
        return tag
Пример #25
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()
Пример #26
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)
class Department(Collection):
    __collection__ = 'department'
    _allow_extra_fields = True
    _index = [{'type': 'hash', 'unique': False, 'fields': ['name']}]
    _key = String(required=True)  # registration number
    name = String(required=True, allow_none=False)
Пример #28
0
class Area(Collection):

    __collection__ = 'areas'

    _key = String(required=True)  # area name
Пример #29
0
 class ResultMixin(CollectionBase):
     _key = String()
     _timestamp = DateTime()
     stats = String()
Пример #30
0
        class Person(Collection):
            __collection__ = "persons"
            _key_field = "name"

            name = String(required=True, allow_none=False)
            age = Integer(allow_none=True, missing=None)