Ejemplo n.º 1
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
        }
Ejemplo n.º 2
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')
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
class Student(db.Model):
    __tablename__ = "students"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), nullable=False, unique=True)
    email = db.Column(db.String(45), nullable=False)
    school_ = db.Column(db.Integer, db.ForeignKey("school.id"))
    course = db.relationship("Course",
                             secondary=courses_students_table,
                             backref="students")
    teacher = db.relationship("Teacher",
                              secondary=teachers_students_table,
                              backref="students")
    # teacher = db.Column(db.Integer, db.ForeignKey("teacher.id"))
    grade = db.Column(JSON)
    module = db.relationship("Module",
                             secondary=modules_students_table,
                             backref="students")

    def __repr__(self):
        return f"{self.name} with unique id: {self.id}"

    def serialize(self):
        return {
            "id": self.id,
            "name": self.name,
            "email": self.email,
            "course": str(self.course),
            "teacher": str(self.teacher),
            "modules": str(self.module),
            "grade": str(self.grade)
        }
Ejemplo n.º 5
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())
Ejemplo n.º 6
0
class User(db.Model):
    __tablename__ = 'users'

    chat_id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(32), nullable=False)
    email = db.Column(db.String(32), unique=True, nullable=False)

    dashboards = db.relationship('DashBoard',
                                 secondary=dashboard_users,
                                 backref=db.backref('users', lazy=True))
    tasks = db.relationship('Task',
                            secondary=task_users,
                            backref=db.backref('users', lazy=True))
    comments = db.relationship("Comment", backref='author')
    subscriptions = db.relationship('Event',
                                    secondary=user_subscriptions,
                                    backref=db.backref("subscribers",
                                                       lazy=True))

    def __repr__(self):
        return '<User %r>' % self.username

    def serialize(self) -> dict:
        return {
            "chat_id": self.chat_id,
            "username": self.username,
            "email": self.email
        }
Ejemplo n.º 7
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
        }
Ejemplo n.º 8
0
class Comment(db.Model):
    """A comment"""

    __tablename__ = "comments"

    comment_id = db.Column(db.Integer,
                        autoincrement=True,
                        primary_key=True)
    comment_text = db.Column(db.Text())
    star_rating = db.Column(db.Integer)
    timestamp = db.Column(
        db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
    )

    users = db.relationship("User",
                            secondary="users_comments", back_populates="comments", cascade="all, delete") 
    activities = db.relationship("Activity",
                            secondary="activities_comments",back_populates="comments", cascade="all, delete") 
    activities_comments= db.relationship("ActivityComment", back_populates="comments", cascade="all, delete")
    users_comments= db.relationship("UserComment", back_populates="comments", cascade="all, delete")
    


    def __repr__(self):
        return f'<Comment comment_id={self.comment_id} name={self.star_rating}>'
Ejemplo n.º 9
0
class Product(db.Model):
	
	pid = db.Column(db.String(10), primary_key = True)
	p_category = db.Column(db.String(25))
	p_sub_category = db.Column(db.String(25))
	p_name = db.Column(db.String(25))
	
	p_price = db.Column(db.Integer)
	gst = db.Column(db.Integer)
	product_base_margin = db.Column(db.Integer)
	
	product_sale_price = db.Column(db.Integer)
	#product_arrival_date = db.Column(db.DateTime())
	product_arrival_date = db.Column(db.Date, default = arrow.now().format('YYYY-MM-DD'))
	sid = db.Column(db.String(10),db.ForeignKey('supplier.sid', ondelete='CASCADE'))
	
	ref_from_stock_for_pid = db.relationship('Stock' , backref = 'product', passive_deletes=True)
	ref_from_transactions_for_pid = db.relationship('Transactions' , backref = 'product', passive_deletes=True)
	ref_from_supplier_for_pid = db.relationship('Supplier' , backref = 'product', passive_deletes=True)
	ref_from_supplier_product_for_pid = db.relationship('Supplier_product' , backref = 'product', passive_deletes=True)
	
	def __init__(self, pid, p_category, p_sub_category, p_name, p_price, gst, product_base_margin, product_sale_price, supplier):
		self.pid = pid
		self.p_category = p_category
		self.p_sub_category = p_sub_category
		self.p_name = p_name
		self.p_price = p_price
		self.gst = gst
		self.product_base_margin = product_base_margin
		self.product_sale_price = product_sale_price
		#self.product_arrival_date = product_arrival_date
		self.supplier = supplier
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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"))
Ejemplo n.º 13
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"))
Ejemplo n.º 14
0
class BHA(db.Model):
    __tablename__ = 'BHA'
    id = db.Column(db.Integer, primary_key=True)
    project = db.Column(db.String(100))
    case_file = db.Column(db.String(256))
    description = db.Column(db.String(512))
    create_by = db.Column(db.String(20))
    date = db.Column(db.String(20))
    survey_type = db.Column(db.String(20))

    bha_round = db.relationship('BHARound', backref='bha')
    component = db.relationship('BHAComponent', backref='bha')
Ejemplo n.º 15
0
class DashBoard(db.Model):
    __tablename__ = 'dashboards'

    id = db.Column(db.Integer, primary_key=True)
    dashboard_name = db.Column(db.String(20), unique=True, nullable=False)
    users = db.relationship("User",
                            secondary=dashboard_users_table,
                            backref="dashboard")

    tasks = db.relationship("Task", backref="dashboard")

    def serialize(self) -> dict:
        return {"id": self.id, "name": self.dashboard_name}
Ejemplo n.º 16
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"))
Ejemplo n.º 17
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"))
Ejemplo n.º 18
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"))
Ejemplo 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"))
Ejemplo n.º 20
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"))
Ejemplo n.º 21
0
class Meets(db.Model):
    __tablename__ = "meets"
    id = db.Column(db.Integer, primary_key=True)
    meetup_name = db.Column(db.String(100), nullable=False)
    meet_volunteers = db.relationship("Volunteer",
                                      secondary=volunteerMeets_table,
                                      back_populates="volunteer_meets")
    elders_id = db.Column(db.Integer, db.ForeignKey("elderly.id"))
    elderly = db.relationship("Elderly", back_populates="meets_elderly")

    def __str__(self):
        return meetup_name

    def __repr__(self):
        return "<Meets: " + self.meetup_name + ">"
Ejemplo n.º 22
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}>'
Ejemplo n.º 23
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}>'
Ejemplo n.º 24
0
class Post(TimeStampedModel):
    __tablename__ = 'posts'

    id = db.Column(db.Integer, primary_key=True)
    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)
    comments = db.relationship('Comment', backref='posts', lazy='dynamic')

    def __init__(self,
                 content,
                 user_id,
                 image=None,
                 upvotes=0,
                 upvoted_by=None):
        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_posts(self):
        return Post.query.all()

    def get_all_posts_user(self, user_id):
        return Post.query.filter_by(user_id=user_id)
Ejemplo n.º 25
0
class Patient(db.Model):
    """docstring for Patient"""

    __tablename__ = "Patient"
    id_patient = db.Column(db.String(10), nullable=True, primary_key=True)
    name = db.Column(db.String(300), nullable=False)
    lastname = db.Column(db.String(30), nullable=False)
    phone = db.Column(db.String(12), nullable=False)
    email = db.Column(db.String(40), nullable=False)
    gender = db.Column(db.String(20), nullable=False)
    weight = db.Column(db.Float(), nullable=False)
    height = db.Column(db.Float(), nullable=False)
    temperature = db.Column(db.Float(), nullable=False)
    heart_rate = db.Column(db.Float(), nullable=False)
    # db.relationship must      be in the parent table
    appointment = db.relationship(
        'Appointment', backref='Patient', cascade="all, delete-orphan")
         
    def __repr__(self):
        return '{},{},{},{},{},{}'.format(self.id_patient, self.name,
                                          self.lastname, self.phone,
                                          self.gender, self.weight,
                                          self.height, self.temperature,
                                          self.heart_rate)
    def fullname(self):
        return '{} {}'.format(self.name, self.lastname)

    def contact(self):
        return '{} {}'.format(self.name, self.lastname), self.phone
Ejemplo n.º 26
0
class username(db.Model):
    """ Stores username from login """

    __tablename__ = "username"
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(400))
    child = db.relationship("character", backref="userid")
Ejemplo n.º 27
0
class User(db.Model):
    """docstring for User"""

    __tablename__ = "User"
    username = db.Column(db.String(30), nullable=False, primary_key=True)
    email = db.Column(db.String(30), nullable=True)
    password = db.Column(db.String(10), nullable=False)
    name = db.Column(db.String(30), nullable=False)
    lastname = db.Column(db.String(30), nullable=False)
    phone = db.Column(db.String(12), nullable=True)
    speciality = db.Column(db.String(30), nullable=False)
    workplace = db.Column(db.String(20), nullable=True)
    doctor = db.Column(db.Boolean(),nullable=True)
    # db.relationship must      be in the parent table
    appointment = db.relationship(
        'Appointment', backref='User', cascade="all, delete-orphan")
    

    def __repr__(self):
        return '{},{},{},{},{},{}'.format(self.username, self.email,
                                          self.password, self.name,
                                          self.lastname, self.phone,
                                          self.speciality, self.workplace,
                                          self.doctor)
    def fullname(self):
        return '{} {}'.format(self.name, self.lastname)
Ejemplo n.º 28
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
        }
Ejemplo n.º 29
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    login = db.Column(db.String(255), unique=True, nullable=False)  # user - vk_id; admin - login
    _password = db.Column(db.Text, nullable=False)  # user - vk_access_token; admin - password
    email = db.Column(db.String(255), unique=True)
    active = db.Column(db.Boolean(), nullable=False)

    roles = db.relationship(
        'Role',
        secondary=roles_users,
        backref=db.backref('users', lazy='dynamic')
    )

    def __init__(self, login='', password='', active=True, roles=[]):
        self.login = login
        self.password = password
        self.active = active
        self.roles = roles

    @hybrid_property
    def password(self):
        return self._password

    @password.setter
    def password(self, password):
        self._password = sha256_crypt.hash(password)

    @hybrid_method
    def verify_hash(self, password):
        return sha256_crypt.verify(password, self._password)

    @staticmethod
    def find_by_login(login):
        return User.query.filter_by(login=login).first()
Ejemplo n.º 30
0
class User(db.Model):
    __tablename__ = "users333"
    id = db.Column('user_id', db.Integer, primary_key=True)
    username = db.Column('username', db.String(20), unique=True, index=True)
    password = db.Column('password', db.String(250))
    email = db.Column('email', db.String(50), unique=True, index=True)
    registered_on = db.Column('registered_on', db.DateTime)
    todos = db.relationship('Todo', backref='user', lazy='dynamic')

    def __init__(self, username, password, email):
        self.username = username
        self.set_password(password)
        self.email = email
        self.registered_on = datetime.utcnow()

    def set_password(self, password):
        self.password = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password, password)

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.id)

    def __repr__(self):
        return '<User %r>' % (self.username)