Esempio n. 1
0
class User(db.Model):
    __tablename__ = "users"

    __table_args__ = (db.UniqueConstraint('email', 'tenant_id'), )

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(60), nullable=False)
    name = db.Column(db.String(30), nullable=False)
    _password = db.Column("password", db.String(), nullable=False)
    is_admin = db.Column(db.Boolean(), nullable=False)
    is_owner = db.Column(db.Boolean(), nullable=False, default=False)
    created_at = db.Column(db.DateTime(timezone=False),
                           nullable=False,
                           server_default=now())
    expires_on = db.Column(db.DateTime(), nullable=False, default=get_expiry)

    tenant_id = db.Column(db.Integer,
                          db.ForeignKey('tenants.id', ondelete="CASCADE"),
                          nullable=False)

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

    @password.setter
    def password(self, password):
        self._password = bcrypt.generate_password_hash(password).decode(
            'utf-8')

    def __repr__(self):
        return f"email:{self.email} -- id:{self.id} -- tenant_id:{self.tenant_id}"
Esempio n. 2
0
class IssuedToken(db.Model):
    __tablename__ = 'issued_tokens'
    product_id = db.Column(db.String(20), primary_key=True, nullable=False)
    consumer_id = db.Column(db.String(20), primary_key=True, nullable=False)
    valid_from = db.Column(db.DateTime(timezone=False),
                           nullable=False,
                           primary_key=True)
    valid_to = db.Column(db.DateTime(timezone=False),
                         nullable=False,
                         primary_key=True)
Esempio n. 3
0
class Test(db.Model):
    __tablename__ = "tests"
    __table_args__ = {"schema": "private"}

    id = db.Column(db.Integer, primary_key=True)
    question_id = db.Column(db.Integer, db.ForeignKey('private.questions.id', ondelete="CASCADE"), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('private.users.id', ondelete="CASCADE"), nullable=False)
    time_started = db.Column(db.DateTime(timezone=False), nullable=False, server_default=now())
    time_submitted = db.Column(db.DateTime(timezone=False))
    user_submitted_query = db.Column(db.String())
    result = db.Column(db.SmallInteger)
Esempio n. 4
0
class Usercontent(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Integer,
                         db.ForeignKey('user.username', ondelete='CASCADE'))
    user = db.relationship('User', backref=db.backref('usercontent_set'))
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    modify_date = db.Column(db.DateTime(), nullable=True)
    filename = db.Column(db.String(200), nullable=False)
    voter = db.relationship('User',
                            secondary=usercontent_like_voter,
                            backref=db.backref('usercontent_voter_set'))
Esempio n. 5
0
class Book(db.Model):
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String(50),nullable=False)
    status = db.Column(db.Enum('on borrow','off borrow'),default=True,server_default="off borrow")
    created_at = db.Column(db.DateTime(timezone=True),nullable=True)
    updated_at = db.Column(db.DateTime(timezone=True),nullable=True)

    def __init__(self, name, status = 'off borrow'):    
      self.name = name
      self.status = status
 
    def __repr__(self):  
      return '<Book name={self.name} status={self.status}>'
class GuestBook(db.Model):
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    description = db.Column(db.Text, nullable=True)
    created_at = db.Column(db.DateTime(timezone=True), nullable=True)
    updated_at = db.Column(db.DateTime(timezone=True), nullable=True)
    user = db.relationship('User')

    def __init__(self, user_id, description=None):
        self.user_id = user_id
        self.description = description

    def __repr__(self):
        return '<GuestBook user_id={self.user_id} description={self.description}>'
Esempio n. 7
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    subject = db.Column(db.String(200), nullable=False)
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    modify_date = db.Column(db.DateTime(), nullable=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        nullable=False)
    # user 속성은 Post모델에서 계정모델(User)을 참조하기 위해서 추가된 속성으로 post.user.username과 같이 사용된다.
    user = db.relationship('User', backref=db.backref('post_set'))
    voter = db.relationship('User',
                            secondary=post_voter,
                            backref=db.backref('post_voter_set'))
Esempio n. 8
0
class Reply(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id',
                                                  ondelete='CASCADE'))
    post = db.relationship('Post', backref=db.backref('reply_set'))
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    modify_date = db.Column(db.DateTime(), nullable=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        nullable=False)
    user = db.relationship('User', backref=db.backref('reply_set'))
    voter = db.relationship('User',
                            secondary=reply_voter,
                            backref=db.backref('reply_voter_set'))
Esempio n. 9
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    login = db.Column(db.String(255), unique=True, nullable=False)
    password_hash = db.Column(db.String(255), nullable=False)
    registered_on = db.Column(db.DateTime(255), nullable=False)
    firstname = db.Column(db.String(255), nullable=False)
    lastname = db.Column(db.String(255), nullable=False)
    git_login = db.Column(db.String(255), nullable=False)
    git_password = db.Column(db.String(255), nullable=False)
    public_id = db.Column(db.String(500), nullable=False)

    @property
    def password(self):
        raise AttributeError('password: write-only field')

    @password.setter
    def password(self, password):
        self.password_hash = flask_bcrypt.generate_password_hash(
            password).decode('utf-8')

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

    def __repr__(self):
        return "<User '{}'".format(self.login)
Esempio n. 10
0
class AccountData(db.Model):
    __tablename__ = 'data_account'

    id = db.Column(db.Integer, primary_key=True)
    amount = db.Column(db.Integer, nullable=False)
    date = db.Column(db.DateTime(), index=True, default=datetime.now)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    client_id = db.Column(db.Integer, db.ForeignKey('client_account.id'))

    def __init__(self, amount, date, user_id, client_id):
        self.amount = amount
        self.date = date
        self.user_id = user_id
        self.client_id = client_id

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

    def serialize(self):
        return {
            'id': self.id,
            'amount': self.amount,
            'date': self.date,
            'user_id': self.user_id,
            'client_id': self.client_id
        }
Esempio n. 11
0
class ItemModel(db.Model):
    __tablename__ = "items"

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    name = db.Column(db.String(), nullable=False)
    price = db.Column(db.Float, nullable=False)
    created_at = db.Column(db.DateTime(timezone=True),
                           default=func.now(),
                           nullable=False)
    store_id = db.Column(db.Integer, db.ForeignKey("stores.id"))
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))

    def save_to_db(self) -> None:
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self) -> None:
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def find_by_id(cls, id: int) -> "ItemModel":
        return cls.query.filter_by(id=id).first()

    @classmethod
    def fetch_all(cls) -> List["ItemModel"]:
        return cls.query.all()

    @classmethod
    def find_by_name(cls, name: str) -> "ItemModel":
        return cls.query.filter_by(name=name).first()
Esempio n. 12
0
class StoreModel(db.Model):
    __tablename__ = "stores"

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    name = db.Column(db.String(), nullable=False)
    created_at = db.Column(db.DateTime(timezone=True),
                           default=func.now(),
                           nullable=False)
    items = db.relationship("ItemModel", backref="store", lazy=True)
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)

    def save_to_db(self) -> None:
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self) -> None:
        db.session.delete()
        db.session.commit()

    @classmethod
    def fetch_all(cls) -> "StoreModel":
        return cls.query.all()

    @classmethod
    def fetch_by_id(cls, id) -> List["StoreModel"]:
        return cls.query.filter_by(id=id).first()

    @classmethod
    def fetch_by_name(cls, name) -> "StoreModel":
        return cls.query.filter_by(name=name).first()
Esempio n. 13
0
class Submission(db.Model):
    __tablename__ = 'submissions'

    submission_id = db.Column(db.Integer, primary_key=True)
    status = db.Column(db.String(50))
    language = db.Column(db.String(30))
    timestamp = db.Column(db.DateTime())
    task_name = db.Column(db.String(50))

    user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'))
    task_id = db.Column(db.Integer, db.ForeignKey('tasks.task_id'))
    contest_id = db.Column(db.Integer, db.ForeignKey('contests.contest_id'))

    def __init__(self, status, language, timestamp, task_name, user_id, task_id, contest_id):
        self.status = status
        self.language = language
        self.timestamp = timestamp
        self.task_name = task_name
        self.user_id = user_id
        self.task_id = task_id
        self.contest_id = contest_id

    def __repr__(self):
        return 'Submission {}'.format(submission_id)

    def save(self):
        db.session.add(self)
        db.session.commit()
Esempio n. 14
0
class Sales(db.Model):
    __tablename__ = 'sales'
    id = db.Column(db.Integer, primary_key=True)
    quantity = db.Column(db.Integer, nullable=False)

    created_at = db.Column(db.DateTime(timezone=True), default=func.now())
    inventoryId = db.Column(db.Integer,
                            db.ForeignKey('inventories.id'),
                            nullable=False)

    # create
    def create_record(self):
        db.session.add(self)
        db.session.commit()
        return self

    @classmethod
    def fetch_all(cls):
        return cls.query.all()

    def compute_quanity(salesID: int):
        if inv is not None:
            # get the the stock quanity
            total_stock = list(map(lambda obj: obj.quantity, inv.stock))
            total_sales = list(map(lambda obj: obj.quantity, inv.Sales))
            return sum(total_stock) - sum(total_sales)

            return dict(compute_quanity=compute_quanity)
Esempio n. 15
0
class Calendar(db.Model):
    """Model for the calendar table"""
    __tablename__ = 'Calendar'

    id = db.Column(db.Integer(), primary_key=True)
    username = db.Column(db.String(50), nullable=False)
    facility = db.Column(db.String(50))
    integrator = db.Column(db.String(50))
    totalTime = db.Column(db.Integer())
    startDate = db.Column(db.DateTime(), nullable=False)
    private = db.Column(db.Boolean())
    title = db.Column(db.String(50))
    requestId = db.Column(db.Integer())
    rangeId = db.Column(db.Integer())
    beam = db.Column(db.Boolean())
    energy = db.Column(db.Float())

    def create_entry(self):
        result = ""
        try:
            db.session.add(self)
            db.session.commit()
            result = {'success': True}
        except Exception as e:
            print(e)
            result = {
                'error': "Unable to create calendar entry",
                'success': False
            }
        return result

    def __repr__(self):
        return "<Calendar(username=%s)>" % (self.username)
Esempio n. 16
0
class ScheduledTaskResult(db.Model):
    __tablename__ = "scheduled_task_result"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    start_time = db.Column(db.DateTime(True), nullable=False)
    duration = db.Column(db.Interval, nullable=False)
    result = db.Column(db.JSON, nullable=False)

    def __init__(self, job_name):
        self.name = job_name
        self.start_time = pendulum.now()
        self.result = {}

    def finish(self):
        self.duration = pendulum.now() - self.start_time

    @classmethod
    def get_latest_run(cls, name):
        return (
            cls.query.filter_by(name=name)
            .order_by(ScheduledTaskResult.start_time.desc())
            .limit(1)
            .one_or_none()
        )

    @classmethod
    def cleanup(cls):
        """ Delete results older than a week """
        cls.query.filter(
            cls.start_time < pendulum.now() - pendulum.duration(days=7)
        ).delete()
Esempio n. 17
0
class TaskModel(db.Model):
    __tablename__ = 'tasks'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(), nullable=False)
    description = db.Column(db.String(), nullable=False)
    completed = db.Column(db.Integer, nullable=False, default=0)
    created_at = db.Column(db.DateTime(timezone=True), default=func.now())
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))

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

    @classmethod
    def fetch_all(cls):
        return cls.query.all()

    @classmethod
    def fetch_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()

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

    def save_to_db(self):
        db.session.commit()
Esempio n. 18
0
class Contest(db.Model):
	__tablename__ = 'contests'

	contest_id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.String(50))
	start = db.Column(db.DateTime())
	duration = db.Column(db.Integer)
	author_id = db.Column(db.Integer, db.ForeignKey('users.user_id'))

	tasks = db.relationship('Task', secondary=contest_tasks, lazy='dynamic')
	users = db.relationship('User', secondary=contest_users, lazy='dynamic')

	def __init__(self, name, start, duration, author_id):
		self.name = name
		self.start = start
		self.duration = duration
		self.author_id = author_id

	def __repr__(self):
		return 'Contest(%r)' % (self.name)

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

	def set_tasks(self, tasks):
		self.tasks = tasks
Esempio n. 19
0
class Ranges(db.Model):
    """Model for the facility table"""
    __tablename__ = 'Ranges'

    id = db.Column(db.Integer(), primary_key=True)
    org_id = db.Column(db.Integer())
    start_date = db.Column(db.DateTime())
    facility = db.Column(db.String())
    hours = db.Column(db.Integer())
    scheduled = db.Column(db.Boolean())

    def create_range(self):
        result = ""
        try:
            db.session.add(self)
            db.session.commit()
            result = {'success': True}
        except Exception as e:
            print(e)
            result = {
                'error': "Unable to create range entry",
                'success': False
            }
        return result

    def __repr__(self):
        return "<Range(id=%s, facility=%s)>" % (self.org_id, self.facility)
Esempio n. 20
0
class Holidays(db.Model):
    __tablename__ = 'holidays'
    id = db.Column('id', db.Integer(), primary_key=True, autoincrement=True)
    holiday_date = db.Column('holiday_date', db.DateTime(timezone=True))
    holiday_name = db.Column('holiday_name', db.String())

    def tojson(self):
        return {"date": self.holiday_date, "name": self.holiday_name}
Esempio n. 21
0
class StockModel(db.Model):
    __tablename__ = 'stocks'
    id = db.Column(db.Integer, primary_key=True)
    quantity = db.Column(db.Integer, nullable=False)
    created_at = db.Column(db.DateTime(timezone=True), default=func.now())
    inv_id = db.Column(db.Integer,
                       db.ForeignKey('inventories.id'),
                       nullable=False)
Esempio n. 22
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        nullable=False)
    user = db.relationship('User', backref=db.backref('comment_set'))
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    modify_date = db.Column(db.DateTime(), nullable=True)
    usercontent_id = db.Column(db.Integer,
                               db.ForeignKey('usercontent.id',
                                             ondelete='CASCADE'),
                               nullable=True)
    usercontent = db.relationship('Usercontent',
                                  backref=db.backref('comment_set'))
    voter = db.relationship('User',
                            secondary=comment_like_voter,
                            backref=db.backref('comment_voter_set'))
Esempio n. 23
0
class PostLike(db.Model):
    __tablename__ = "post_likes"

    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer, db.ForeignKey("posts.id"), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)
    created_at = db.Column(db.DateTime(), nullable=False)

    def __repr__(self):
        return f"<PostLike {self.id}>"
Esempio n. 24
0
class User(db.Model):
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    username = db.Column(db.String(50),nullable=False)
    email = db.Column(db.String(50),nullable=False,index=True)
    password = db.Column(db.Text,nullable=False)
    role = db.Column(db.Enum('admin','user'),default=True,server_default="user")
    photo = db.Column(db.String(50),default=True,server_default="user.png")
    created_at = db.Column(db.DateTime(timezone=True),nullable=True)
    updated_at = db.Column(db.DateTime(timezone=True),nullable=True)
    
    def __init__(self, username, email, password, role = "user", photo = "user.png"):
      self.username = username
      self.email = email
      self.password = password
      self.role = role
      self.photo = photo
 
    def __repr__(self):     
      return '<User username={self.username} email={self.email}  password={self.password} photo={self.photo} role={self.role}>'
Esempio n. 25
0
File: Post.py Progetto: sam-don/t3a3
class Post(db.Model):
    __tablename__ = "posts"

    id = db.Column(db.Integer, primary_key=True)
    caption = db.Column(db.String())
    created_at = db.Column(db.DateTime(),
                           nullable=False,
                           default=datetime.now())
    updated_at = db.Column(db.DateTime(), nullable=False)
    total_likes = db.Column(db.Integer, nullable=False, default=0)
    total_dislikes = db.Column(db.Integer, nullable=False, default=0)
    total_comments = db.Column(db.Integer, default=0)
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)
    post_image = db.relationship("PostImage", backref="posts", uselist=False)
    post_like = db.relationship("PostLike", backref="posts")
    post_dislike = db.relationship("PostDislike", backref="posts")

    def __repr__(self):
        return f"<Post {self.id}>"
Esempio n. 26
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    token = db.Column(db.String(200))
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))
Esempio n. 27
0
class Symptoms(db.Model):
    id = db.Column(db.Integer, nullable=False, primary_key=True)
    cough = db.Column(db.Boolean, default=False)
    resp = db.Column(db.Boolean, default=False)
    fever = db.Column(db.Boolean, default=False)
    fatigue = db.Column(db.Boolean, default=False)
    other = db.Column(db.String(100))
    date_added = db.Column(db.DateTime())
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    specifics = db.relationship('Specifics', backref='symptom', uselist=False)
Esempio n. 28
0
class SalesModel(db.Model):
    __tablename__="sales"
    id = db.Column(db.Integer, primary_key=True)
    inventory_id =db.Column(db.Integer, db.ForeignKey('inventories.id'))
    quantity = db.Column(db.Integer, nullable=False)
    created_at = db.Column(db.DateTime(timezone=True), default=func.now())

    def create_record(self):
        db.session.add(self)
        db.session.commit()
Esempio n. 29
0
class Order(db.Model):
    __tablename__ = "user_order"

    id = db.Column(db.Integer, db.Sequence('order_id_seq'), primary_key=True)
    date_time = db.Column(db.DateTime(timezone=True), nullable=False, server_default=func.now())
    menu_id = db.Column(db.Integer, db.ForeignKey("menu.id"), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)
    
    def __repr__(self):
        return f"<Order {self.id}, {self.date_time}>"
Esempio n. 30
0
class UserModel(db.Model):
    __tablename__='users'
    id=db.Column(db.Integer,primary_key=True)
    full_name=db.Column(db.String(),nullable=False)
    email=db.Column(db.String(),nullable=False)
    password=db.Column(db.String(),nullable=False,default=0)
    created_at=db.Column(db.DateTime(timezone=True),default=func.now())
    tasks=db.relationship('TaskModel',backref='user', lazy=True)
    

    def create_record(self):
        db.session.add(self)
        db.session.commit()
        return self

    @classmethod
    def fetch_all(cls):
        return cls.query.all()

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

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

    @classmethod
    def check_email_exist(cls,email):
        mail=cls.query.filter_by(email=email).first()
        if mail:
            return True
        else:
            return False

    @classmethod
    def validate_password(cls,email,password):
        record=cls.query.filter_by(email=email).first()

        if record and check_password_hash(record.password,password):
            return True
        else:
            return False

        
    @classmethod
    def get_user_id(cls,email):
        
        return cls.query.filter_by(email=email).first().id

    @classmethod
    def get_userby_id(cls,id):
        
        return cls.query.filter_by(id=id).first()