Ejemplo n.º 1
0
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, unique=True)
    password = db.Column(db.String)
    roles = db.Column(db.String)
    recipes = db.relationship("Recipe")
    is_active = db.Column(db.Boolean, default=True, server_default='true')

    @property
    def rolenames(self):
        try:
            return self.roles.split(',')
        except Exception:
            return []

    @classmethod
    def lookup(cls, username):
        return cls.query.filter_by(username=username).one_or_none()

    @classmethod
    def identify(cls, id):
        return cls.query.get(id)

    @property
    def identity(self):
        return self.id

    def is_valid(self):
        return self.is_active
Ejemplo n.º 2
0
class Recipe(db.Model):
    __tablename__ = 'recipes'
    __table_args__ = (db.UniqueConstraint('name', 'version', name='uix_1'), )
    id = db.Column(db.Integer, primary_key=True)
    userid = db.Column(db.Integer, db.ForeignKey('users.id'))
    name = db.Column("name", db.String)
    public = db.Column("public", db.Boolean)
    version = db.Column("version", db.Integer)
    batchvolume = db.Column("batchvolume", db.Integer)
    batchnic = db.Column("batchnic", db.Integer)
    batchratio = db.Column("batchratio", db.Integer)
    basenic = db.Column("basenic", db.Integer)
    baseratio = db.Column("baseratio", db.Integer)
    flavours = db.relationship("Flavour", cascade="all, delete-orphan")

    def __eq__(self, other):
        return (self.name == other.name
                and int(self.public) == int(other.public)
                and int(self.batchvolume) == int(other.batchvolume)
                and int(self.batchnic) == int(other.batchnic)
                and int(self.batchratio) == int(other.batchratio)
                and int(self.basenic) == int(other.basenic)
                and int(self.baseratio) == int(other.baseratio)
                and self.flavours == other.flavours)

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
Ejemplo n.º 3
0
class Request(db.Model):
    __tablename__ = "requests"

    id = db.Column(db.Integer, primary_key=True)
    goal = db.Column(db.String, nullable=False)
    time = db.Column(db.String, nullable=False)
    name = db.Column(db.String, nullable=False)
    phone = db.Column(db.String, nullable=False)
Ejemplo n.º 4
0
class Time(db.Model):
    __tablename__ = "times"

    id = db.Column(db.Integer, primary_key=True)
    time = db.Column(db.String, nullable=False)
    is_free = db.Column(db.Boolean, nullable=False)

    day_id = db.Column(db.Integer, db.ForeignKey("days.id"))
    day = db.relationship("Day")
Ejemplo n.º 5
0
class Goal(db.Model):
    __tablename__ = "goals"

    id = db.Column(db.Integer, primary_key=True)
    goal = db.Column(db.String, nullable=False)
    view = db.Column(db.String, nullable=False)

    teachers = db.relationship("Teacher",
                               secondary=goals_relations_association,
                               back_populates="goals")
Ejemplo n.º 6
0
class Subject(db.Model):
    __tablename__="Subject"
    id = db.Column('id', db.Integer, primary_key=True)
    first_name = db.Column('first_name', db.String(30), nullable=False)
    last_name = db.Column('last_name', db.String(30),nullable=False)
    images = db.relationship("Image", backref="subject", lazy='dynamic')
    def __init__(self, first_name, last_name):
        self.first_name=first_name
        self.last_name=last_name

        def __repr__(self):
            return f'Subject {self.id}'
Ejemplo n.º 7
0
class Day(db.Model):
    __tablename__ = "days"

    id = db.Column(db.Integer, primary_key=True)
    day = db.Column(db.String, nullable=False)
    view = db.Column(db.String, nullable=False)

    times = db.relationship("Time")

    teachers = db.relationship("Teacher",
                               secondary=days_relations_association,
                               back_populates="days")
Ejemplo n.º 8
0
class Flavour(db.Model):
    __tablename__ = 'flavours'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column("name", db.String)
    percentage = db.Column("percentage", db.Integer)
    recipeid = db.Column(db.Integer, db.ForeignKey('recipes.id'))

    def __eq__(self, other):
        return (self.name == other.name
                and int(self.percentage) == int(other.percentage))

    def __ne__(self, other):
        return (self.name != other.name or self.percentage != other.percentage)

    def __hash__(self):
        return hash(self.name + str(self.percentage))

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
Ejemplo n.º 9
0
class Image(db.model):
    __tablename__ = "Image"
    id = db.column(db.Integer, primary_key=True)
    path = db.column(db.String(255), nullable=False)

    subject_id = db.Column(db.Integer,
                           db.Foreignkey('subject.id'),
                           nullable=False)
    subject = db.relationship('Subject')

    def __init__(self, path, subject):
        self.path = path
        self.subject = subject

        def __repr__(self):
            return f'<Image {self.id}>'

    id_subject = db.Column(db.Integer,
                           db.Foreignkey('id_subject.id'),
                           nullable=False)
    category = db.relationship(
        'Subject',
        backref=db.backref('Image'),
    )
Ejemplo n.º 10
0
class Booking(db.Model):
    __tablename__ = "bookings"

    id = db.Column(db.Integer, primary_key=True)
    day = db.Column(db.String, nullable=False)
    time = db.Column(db.String, nullable=False)
    name = db.Column(db.String, nullable=False)
    phone = db.Column(db.String, nullable=False)

    teacher_id = db.Column(db.Integer, db.ForeignKey("teachers.id"))
    teacher = db.relationship("Teacher")
Ejemplo n.º 11
0
class Teacher(db.Model):
    __tablename__ = "teachers"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    about = db.Column(db.String, nullable=False)
    rating = db.Column(db.Float, nullable=False)
    picture = db.Column(db.String, nullable=False)
    price = db.Column(db.Float, nullable=False)

    bookings = db.relationship("Booking")

    goals = db.relationship("Goal",
                            secondary=goals_relations_association,
                            back_populates='teachers')

    days = db.relationship("Day",
                           secondary=days_relations_association,
                           back_populates='teachers')
Ejemplo n.º 12
0
from app_setup import db

goals_relations_association = db.Table(
    'goals_relations',
    db.Column('teacher_id', db.Integer(), db.ForeignKey('teachers.id')),
    db.Column('goal_id', db.Integer(), db.ForeignKey('goals.id')))

days_relations_association = db.Table(
    'days_relations',
    db.Column('teacher_id', db.Integer(), db.ForeignKey('teachers.id')),
    db.Column('day_id', db.Integer(), db.ForeignKey('days.id')))


class Teacher(db.Model):
    __tablename__ = "teachers"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    about = db.Column(db.String, nullable=False)
    rating = db.Column(db.Float, nullable=False)
    picture = db.Column(db.String, nullable=False)
    price = db.Column(db.Float, nullable=False)

    bookings = db.relationship("Booking")

    goals = db.relationship("Goal",
                            secondary=goals_relations_association,
                            back_populates='teachers')

    days = db.relationship("Day",
                           secondary=days_relations_association,