Esempio n. 1
0
class Meal(db.Model):
    __tablename__ = 'meals'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)
    picture = db.Column(db.LargeBinary, nullable=False)
    title = db.Column(db.String(25), nullable=False)
    description = db.Column(db.String(250), nullable=False)
    date = db.Column(db.Date, nullable=False)

    availabilities = db.relationship('Availability',
                                     backref='meals',
                                     lazy=True)

    def __init__(self, title, description, picture):
        self.title = title
        self.description = description
        self.picture = picture
        self.created_at = datetime.now()

    @classmethod
    def get_by_date(cls, date):
        return cls.query.filter_by(date=date)

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

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Esempio n. 2
0
class Comment(db.Model):
    __tablename__ = 'comments'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)
    text = db.Column(db.String(250), nullable=False)

    # relationship
    comment_id = db.Column(db.String(40),
                           db.ForeignKey('comments.id'),
                           nullable=True)
    meal_id = db.Column(db.String(40),
                        db.ForeignKey('meals.id'),
                        nullable=True)
    user_id = db.Column(db.String(40),
                        db.ForeignKey('users.id'),
                        nullable=False)

    def __init__(self, text):
        self.text = text
        self.created_at = datetime.utcnow()

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

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Esempio n. 3
0
class Ticket(db.Model):
    __tablename__ = 'tickets'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)
    time = db.Column(db.DateTime, nullable=False)

    availability_id = db.Column(db.String,
                                db.ForeignKey('availabilities.id'),
                                nullable=True)

    user_id = db.Column(db.String, db.ForeignKey('users.id'), nullable=True)
    user = db.relationship("User", back_populates="ticket")

    def __init__(self, time):
        self.time = time
        self.created_at = datetime.now()

    @classmethod
    def find_by_date(cls, date):
        return cls.query.filter_by(time=date)

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Esempio n. 4
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    username = db.Column(db.String(80), unique=True, nullable=False)
    password = db.Column(
        PasswordType(
            # The returned dictionary is forwarded to the CryptContext
            onload=lambda **kwargs: dict(schemes=flask.current_app.config[
                'PASSWORD_SCHEMES'],
                                         **kwargs), ),
        unique=False,
        nullable=False)
    created_at = db.Column(db.DateTime, nullable=False)

    # ticket_id = db.Column(db.String, db.ForeignKey('tickets.id'), nullable=True)

    ticket = db.relationship("Ticket", uselist=False, back_populates="user")

    ticket_histories = db.relationship('TicketHistory',
                                       backref='user',
                                       lazy=True)

    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.created_at = datetime.utcnow()

    def save(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def get_all(cls):
        return cls.query.get().all()

    @classmethod
    def find_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()
Esempio n. 5
0
class TicketHistory(db.Model):
    __tablename__ = 'ticket_histories'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)

    user_id = db.Column(db.String, db.ForeignKey('users.id'), nullable=False)

    def __init__(self):
        self.created_at = datetime.now()

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
class Availability(db.Model):
    __tablename__ = 'availabilities'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)
    time = db.Column(db.DateTime, nullable=False)

    meal_id = db.Column(db.String, db.ForeignKey('meals.id'), nullable=False)

    tickets = db.relationship('Ticket', backref='tickets', lazy=True)

    def __init__(self):
        self.created_at = datetime.now()

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Esempio n. 7
0
class TicketHistory(db.Model):
    __tablename__ = 'ticket_histories'

    id = db.Column(db.String(40), primary_key=True, default=generate_uuid)
    created_at = db.Column(db.DateTime, nullable=False)

    user_id = db.Column(db.String, db.ForeignKey('users.id'), nullable=False)

    def __init__(self):
        self.created_at = datetime.utcnow()

    def save_or_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def get_by_user_id(cls, user_id):
        return cls.query.filter_by(user_id=user_id).all()