Exemplo n.º 1
0
class Comment(TimeStampedModel):
    __tablename__ = 'comments'

    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer, db.ForeignKey('posts.id'))
    content = db.Column(db.Text)
    image = db.Column(db.Text, nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    upvotes = db.Column(db.Integer, default=0)
    upvoted_by = db.Column(db.String, default=None)
    is_deleted = db.Column(db.Boolean, default=False)

    def __init__(self,
                 post_id,
                 content,
                 user_id,
                 image=None,
                 upvotes=0,
                 upvoted_by=None):
        self.post_id = post_id
        self.content = content
        self.user_id = user_id
        self.image = image
        self.upvotes = upvotes
        self.upvoted_by = upvoted_by

    def __repr__(self):
        return 'content %s' % self.content

    def get_all_comments_post(self, post_id):
        return Comment.query.filter_by(post_id=post_id)

    def get_all_comments_user(self, user_id):
        return Comment.query.filter_by(user_id=user_id)
Exemplo n.º 2
0
class Task(db.Model):
    __tablename__ = "tasks"

    id = db.Column(db.Integer, primary_key=True)
    creator_id = db.Column(db.Integer,
                           db.ForeignKey("users.id"),
                           nullable=False)
    # assignee_id = db.relationship("User",
    #                         secondary=task_users_table,
    #                         backref="tasks")
    dashboard_id = db.Column(db.Integer,
                             db.ForeignKey("dashboards.id"),
                             nullable=False)
    text = db.Column(db.String(1000), nullable=False)
    status = db.Column(db.String(80), nullable=False)

    creator = db.relationship("User", foreign_keys=[creator_id])

    # assignee = db.relationship("User", foreign_keys=[assignee_id])

    def serialize(self):
        return {
            "id": self.id,
            "creator_id": self.creator_id,
            "dashboard_id": self.dashboard_id,
            "text": self.text,
            "status": self.status
        }
Exemplo n.º 3
0
class TestSuite(SAFRSBase, db.Model):
    __tablename__ = 'TestSuite'

    id = db.Column(db.Integer,
                   primary_key=True,
                   server_default=db.FetchedValue())
    test_suite_static_id = db.Column(db.ForeignKey('TestSuiteStatic.id'))
    test_run_id = db.Column(db.ForeignKey('TestRun.id'))
    tests = db.Column(db.Integer, nullable=False)
    failures = db.Column(db.Integer, nullable=False)
    errors = db.Column(db.Integer, nullable=False)
    time = db.Column(db.Numeric, nullable=False)
    skipped = db.Column(db.Integer, nullable=False)
    timestamp = db.Column(db.DateTime, nullable=False)
    hostname = db.Column(db.String, nullable=False)
    url = db.Column(db.String)
    properties = db.Column(db.JSON)
    system_out = db.Column(db.String)
    system_err = db.Column(db.String)

    test_run = db.relationship(
        'TestRun',
        primaryjoin='TestSuite.test_run_id == TestRun.id',
        backref='test_suites')
    test_suite_static = db.relationship(
        'TestSuiteStatic',
        primaryjoin='TestSuite.test_suite_static_id == TestSuiteStatic.id',
        backref='test_suites')
Exemplo n.º 4
0
class Task(db.Model):
    __tablename__ = 'tasks'

    id = db.Column(db.Integer, primary_key=True)
    task_name = db.Column(db.String(32), nullable=False)
    text = db.Column(db.Text, nullable=True)
    admin = db.Column(db.Integer,
                      db.ForeignKey("users.chat_id", ondelete='CASCADE'),
                      nullable=False)
    dashboard_id = db.Column(db.Integer,
                             db.ForeignKey("dashboards.id",
                                           ondelete='CASCADE'),
                             nullable=False)
    created_at = db.Column(db.DateTime, default=db.func.now())
    status = db.Column(db.String(32), default="TO DO")

    comments = db.relationship('Comment', backref='task')
    admin_name = db.relationship('User', backref='task')

    def __repr__(self):
        return '<Task %r>' % self.task_name

    def serialize(self):
        return {
            "id": self.id,
            "task_name": self.task_name,
            "text": self.text,
            "admin": self.admin,
            "admin_name": self.admin_name.username,
            "dashboard_id": self.dashboard_id,
            "dashboard": self.dashboard.dashboard_name,
            "created_at": self.created_at.strftime("%d-%m-%Y %H:%M:%S"),
            "status": self.status
        }
Exemplo n.º 5
0
class Rating(db.Model):
    id = db.Column(db.Integer,
                   db.Sequence('seq_reg_id', start=1, increment=1),
                   unique=True,
                   primary_key=True)
    user = db.Column(db.String,
                     db.ForeignKey('rater.username'),
                     nullable=False)
    restaurant = db.Column(db.Integer,
                           db.ForeignKey('restaurant.restaurantId'),
                           nullable=False)
    date = db.Column(db.DateTime)
    price = db.Column(db.Integer, db.CheckConstraint('price<=5'),
                      db.CheckConstraint('price>=1'))
    food = db.Column(db.Integer, db.CheckConstraint('food<=5'),
                     db.CheckConstraint('food>=1'))
    mood = db.Column(db.Integer, db.CheckConstraint('mood<=5'),
                     db.CheckConstraint('mood>=1'))
    staff = db.Column(db.Integer, db.CheckConstraint('staff<=5'),
                      db.CheckConstraint('staff>=1'))
    comments = db.Column(db.Text)

    def __init__(self, user, date, price, food, mood, staff, comments,
                 restaurant):
        self.user = user
        self.date = date
        self.price = price
        self.food = food
        self.mood = mood
        self.staff = staff
        self.comments = comments
        self.restaurant = restaurant

    def __repr__(self):
        return '<Rating %r, %r>' % (self.user, self.date)
Exemplo n.º 6
0
class Inventory(db.Model):
    __tablename__ = 'inventory'
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete='CASCADE'),
                        nullable=False)
    user = db.relationship('User')
    item_id = db.Column(db.Integer,
                        db.ForeignKey('items.id', ondelete='CASCADE'),
                        nullable=False)
    item = db.relationship('Item')
    code = db.Column(db.String(8), unique=True)
    expiration = db.Column(db.DateTime)

    @hybrid_property
    def is_expired(self):
        return self.expiration is not None and self.expiration <= datetime.now(
        )

    def activate(self):
        self.code = ''.join([secrets.choice(code_simbols) for _ in range(8)])
        self.expiration = datetime.now() + \
                          timedelta(seconds=Item.query.get(self.item_id).expiration_period)
        db.session.commit()
        return {
            'item_id': self.id,
            'code': self.code,
            'expires_in': self.expires_in
        }

    @hybrid_property
    def expires_in(self):
        if self.expiration is None:
            return None
        return (self.expiration - datetime.now()).total_seconds()
Exemplo n.º 7
0
class CaseCooldown(db.Model):
    __tablename__ = 'case_cooldown'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', on_delete='CASCADE'),
                        nullable=False)
    case_id = db.Column(db.Integer,
                        db.ForeignKey('cases.id', on_delete='CASCADE'),
                        nullable=False)
    cooldown = db.Column(db.DateTime)

    user = db.relationship('User')
    case = db.relationship('Case', backref=db.backref('case_cooldowns'))

    def __init__(self, user_id, case_id):
        cooldown_period = Case.query.get(case_id).cooldown_period
        if cooldown_period is None:
            cooldown_period = 0

        self.user_id = user_id
        self.case_id = case_id
        self.cooldown = datetime.now() + timedelta(seconds=cooldown_period)

    @hybrid_property
    def is_cooled_down(self):
        return self.cooldown < datetime.now()

    @hybrid_property
    def cooldown_left(self):
        return max(0, (self.cooldown - datetime.now()).total_seconds())
Exemplo n.º 8
0
class Comment(db.Model):
    __tablename__ = "comments"

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(32), nullable=False)
    text = db.Column(db.Text, nullable=False)
    sender = db.Column(db.Integer,
                       db.ForeignKey("users.chat_id", ondelete='CASCADE'),
                       nullable=False)
    task_id = db.Column(db.Integer,
                        db.ForeignKey("tasks.id", ondelete='CASCADE'),
                        nullable=False)
    created_at = db.Column(db.DateTime, default=db.func.now())

    def __repr__(self):
        return '<Comment %r>' % self.title

    def serialize(self) -> dict:
        return {
            "id": self.id,
            'title': self.title,
            "comment": self.text,
            "sender": self.author.username,
            "task": self.task.task_name,
            "task_id": self.task_id,
            "created_at": self.created_at.strftime("%d-%m-%Y %H:%M:%S")
        }
Exemplo n.º 9
0
class Language_test_score(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    test_id = db.Column(db.Integer, db.ForeignKey('language_test.id'))
    exam_date = db.Column(db.Date)
    listening_id = db.Column(db.Integer, db.ForeignKey('listening.id'))
    reading_id = db.Column(db.Integer, db.ForeignKey('reading.id'))
    writing_id = db.Column(db.Integer, db.ForeignKey('writing.id'))
    speaking_id = db.Column(db.Integer, db.ForeignKey('speaking.id'))
Exemplo n.º 10
0
class Supplier_product(db.Model):
	id = db.Column(db.Integer, primary_key = True)
	pid = db.Column(db.String(10), db.ForeignKey('product.pid', ondelete='CASCADE'))
	sid = db.Column(db.String(10), db.ForeignKey('supplier.sid', ondelete='CASCADE'))
	
	def __init__(self, product, supplier):
		self.product = product
		self.supplier = supplier
Exemplo n.º 11
0
class Advt(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User', backref='advt')
    car_id = db.Column(db.Integer, db.ForeignKey('car.id'))
    car = db.relationship('Car', backref='advt')
    description = db.Column(db.Text)
    price = db.Column(db.Float)
    created_at = db.Column(db.Integer)
Exemplo n.º 12
0
class Product(db.Model):
    __tablename__ = 'products'
    id = db.Column(db.Integer, primary_key=True)
    category_id = db.Column(db.Integer, db.ForeignKey('categories.id'))
    order_id = db.Column(db.Integer, db.ForeignKey('orders.id'))
    name = db.Column(db.String(475), index=True)
    cost = db.Column(db.Integer)
    sell_amount = db.Column(db.Integer, default=0)

    def __repr__(self):
        return "{}".format(self.name)
Exemplo n.º 13
0
class CartItem(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    order_id = db.Column(db.Integer, db.ForeignKey('order.id'), nullable=False)
    order = db.relationship('Order',
                            backref=db.backref('order_items', lazy=True))
    menu_id = db.Column(db.Integer,
                        db.ForeignKey('menu_item.id'),
                        nullable=False)
    menu = db.relationship('MenuItem',
                           backref=db.backref('menu_carts', lazy=True))
    count = db.Column(db.Integer, nullable=True)
Exemplo n.º 14
0
class ActivityComment(db.Model):

    __tablename__ = "activities_comments"

    activity_comment_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    activity_id = db.Column(db.Integer, db.ForeignKey('activities.activity_id'), primary_key=True)
    comment_id = db.Column(db.Integer, db.ForeignKey('comments.comment_id'), primary_key=True)

    activities = db.relationship(Activity, backref=backref("comments_assoc"))
    comments= db.relationship(Comment, backref=backref("activities_assoc"))
Exemplo n.º 15
0
class UserComment(db.Model):

    __tablename__ = "users_comments"

    user_comment_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'), primary_key=True)
    comment_id = db.Column(db.Integer, db.ForeignKey('comments.comment_id'), primary_key=True)

    comments = db.relationship(Comment, backref=backref("users_assoc"))
    users= db.relationship(User, backref=backref("comments_assoc"))
Exemplo n.º 16
0
class ActivityTimePeriod(db.Model):
    """A time period in the year"""

    __tablename__ = "activities_time_periods"

    activity_time_period_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    activity_id = db.Column(db.Integer, db.ForeignKey('activities.activity_id'), primary_key=True)
    time_period_id = db.Column(db.Integer, db.ForeignKey('time_periods.time_period_id'), primary_key=True)

    activities = db.relationship(Activity, backref=backref("time_periods_assoc"))
    time_periods= db.relationship(TimePeriod, backref=backref("activities_assoc"))
Exemplo n.º 17
0
class ChildInterest(db.Model):


    __tablename__ = "children_interests"

    child_interest_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    child_id = db.Column(db.Integer, db.ForeignKey('children.child_id'), primary_key=True)
    interest_id = db.Column(db.Integer, db.ForeignKey('interests.interest_id'), primary_key=True)

    children = db.relationship(Child, backref=backref("interests_assoc"))
    interests= db.relationship(Interest, backref=backref("children_assoc"))
Exemplo n.º 18
0
class ActivityMaterial(db.Model):
    

    __tablename__ = "activities_materials"

    activity_material_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    activity_id = db.Column(db.Integer, db.ForeignKey('activities.activity_id'), primary_key=True)
    material_id = db.Column(db.Integer, db.ForeignKey('materials.material_id'), primary_key=True)

    activities= db.relationship(Activity, backref=backref("materials_assoc"))
    materials= db.relationship(Material, backref=backref("activities_assoc"))
Exemplo n.º 19
0
class ActivityInterest(db.Model):
    

    __tablename__ = "activities_interests"

    activity_interest_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    activity_id = db.Column(db.Integer, db.ForeignKey('activities.activity_id'), primary_key=True)
    interest_id = db.Column(db.Integer, db.ForeignKey('interests.interest_id'), primary_key=True)

    activities= db.relationship(Activity, backref=backref("interests_assoc"))
    interests= db.relationship(Interest, backref=backref("activities_assoc"))
Exemplo n.º 20
0
class Score(db.Model):
    __tablename__ = "score"
    left_id = db.Column(db.Integer,
                        db.ForeignKey('paper.id'),
                        primary_key=True)
    right_id = db.Column(db.Integer,
                         db.ForeignKey('user.id'),
                         primary_key=True)
    rating = db.Column(db.Integer, default=0)
    is_rated = db.Column(db.Boolean, default=False)
    # relationships
    reviewer = relationship("User", back_populates="scored_papers")
    paper = relationship("Paper", back_populates="reviewers")
Exemplo n.º 21
0
class MenuItemRating(db.Model):
    id = db.Column(db.Integer,
                   db.Sequence('seq_reg_id', start=1, increment=1),
                   unique=True)
    restaurantId = db.Column(db.Integer,
                             db.ForeignKey("restaurant.id"),
                             primary_key=True)
    menuitemId = db.Column(db.Integer,
                           db.ForeignKey("menu_item.id"),
                           primary_key=True)
    userId = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
    rating = db.Column(db.Integer, db.CheckConstraint('rating<6'),
                       db.CheckConstraint('rating>0'))
    date = db.Column(db.Date)
Exemplo n.º 22
0
class InterestsTimePeriod(db.Model):
    """A time period in the year"""

    __tablename__ = "interests_time_periods"

    interest_time_period_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    interest_id = db.Column(db.Integer, db.ForeignKey('interests.interest_id'), primary_key=True)
    time_period_id = db.Column(db.Integer, db.ForeignKey('time_periods.time_period_id'), primary_key=True)


    interests = db.relationship(Interest, backref=backref("time_periods_assoc"))
    time_periods= db.relationship(TimePeriod, backref=backref("interests_assoc"))
Exemplo n.º 23
0
class Item(db.Model):
    __tablename__ = 'items'
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    name = db.Column(db.String(255), nullable=False)
    description = db.Column(db.Text)
    probability = db.Column(db.Float, nullable=False)
    expiration_period = db.Column(db.Integer, default=3600)
    image_id = db.Column(db.Integer, db.ForeignKey('image.id'))
    image = db.relationship('Image', backref=db.backref('item_image'))
    case_id = db.Column(db.Integer,
                        db.ForeignKey('cases.id', ondelete='CASCADE'))

    def __str__(self):
        return str(self.name) + ', ' + str(self.id)
Exemplo n.º 24
0
class UserChild(db.Model):

    __tablename__ = "users_children"

    user_child_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'), primary_key=True)
    child_id = db.Column(db.Integer, db.ForeignKey('children.child_id'), primary_key=True)

    children = db.relationship(Child, backref=backref("users_assoc"))
    users= db.relationship(User, backref=backref("children_assoc"))

    def __repr__(self):
        return f'<UserChild id={self.user_child_id} user={self.user_id} child = {self.child_id}>'
Exemplo n.º 25
0
class UserActivity(db.Model):

    __tablename__ = "users_activities"

    user_activity_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'), primary_key=True)
    activity_id = db.Column(db.Integer, db.ForeignKey('activities.activity_id'), primary_key=True)

    activities = db.relationship(Activity, backref=backref("users_assoc"))
    users= db.relationship(User, backref=backref("activities_assoc"))

    def __repr__(self):
        return f'<UserActivity id={self.user_activity_id} user_id ={self.user_id} activity_id = {self.activity_id}>'
Exemplo n.º 26
0
class Exam_test_score(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    exam_id = db.Column(db.Integer, db.ForeignKey('exam.id'))
    exam_date = db.Column(db.Date)
    verbal_id = db.Column(db.Integer, db.ForeignKey('verbal.id'))
    verbal_rank_id = db.Column(db.Integer, db.ForeignKey('rank.id'))
    quantitative_id = db.Column(db.Integer, db.ForeignKey('quantitative.id'))
    quantitative_rank_id = db.Column(db.Integer, db.ForeignKey('rank.id'))
    writing_id = db.Column(db.Integer, db.ForeignKey('writing.id'))
    writing_rank_id = db.Column(db.Integer, db.ForeignKey('rank.id'))
    total_id = db.Column(db.Integer, db.ForeignKey('total.id'))
    total_rank_id = db.Column(db.Integer, db.ForeignKey('rank.id'))
Exemplo n.º 27
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.INTEGER, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    password = db.Column(db.String(80), nullable=False)
    department = db.Column(db.INTEGER, db.ForeignKey('departments.id'))
    superuser = db.Column(db.Boolean, nullable=True, default=False)
Exemplo n.º 28
0
class MenuItem(db.Model):
    itemId = db.Column(db.Integer,
                       db.Sequence('seq_reg_id', start=1, increment=1),
                       unique=True)
    name = db.Column(db.String, primary_key=True)
    itemType = db.Column(db.String)
    category = db.Column(db.String)
    description = db.Column(db.Text)
    price = db.Column(db.Integer)
    restaurant = db.Column(db.Integer,
                           db.ForeignKey('restaurant.restaurantId'),
                           nullable=False,
                           primary_key=True)

    def __init__(self, name, itemType, category, description, price,
                 restaurant):
        self.name = name
        self.itemType = itemType
        self.category = category
        self.description = description
        self.price = price
        self.restaurant = restaurant

    def __repr__(self):
        return '<MenuItem %r, Restaurant %r>' % (self.name, self.restaurant)
Exemplo n.º 29
0
class Place(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    state_id = db.Column(db.Integer, db.ForeignKey('state.id'), nullable=False)
    name = db.Column(db.String(128))

    def __repr__(self):
        return '<Place %r>' % self.name
Exemplo n.º 30
0
class Case(db.Model):
    __tablename__ = 'cases'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    description = db.Column(db.Text)
    image_id = db.Column(db.Integer, db.ForeignKey('image.id'))
    cooldown_period = db.Column(db.Integer)

    image = db.relationship('Image', backref=db.backref('case_image'))
    items = db.relationship('Item', backref=db.backref('case'))

    def __str__(self):
        return self.name

    def json_with_cooldown(self, user_id):
        case_cooldown = CaseCooldown.query.filter_by(user_id=user_id).first()
        if case_cooldown is None:
            cooldown_left = 0
        else:
            cooldown_left = case_cooldown.cooldown_left

        return {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'image': self.image.url,
            'cooldown_left': cooldown_left
        }