class AlertsModel(db.Model):
    __tablename__ = 'alerts'

    id = db.Column(db.Integer, primary_key=True)
    errorId = db.Column(db.String(80))
    errorSeverity = db.Column(db.String(80))
    errorCategory = db.Column(db.String(80))
    errorMessage = db.Column(db.String(80))
    longMessage = db.Column(db.String(200))
    errorTime = db.Column(db.Integer)
    selected = db.Column(db.Boolean())
    new = db.Column(db.Boolean())
    expanded = db.Column(db.Boolean())
예제 #2
0
파일: yeast.py 프로젝트: anorum/BeerNotes
class YeastModel(db.Model, BaseModel, SearchableMixin):
    __tablename__ = "yeast"
    __searchable__ = [
        'brand', 'name', 'style', 'yeast_format', 'avg_attenuation',
        'min_temp', 'max_temp'
    ]

    id = db.Column(UUID(as_uuid=True),
                   unique=True,
                   nullable=False,
                   primary_key=True,
                   default=uuid4)
    brand = db.Column(db.String(80))
    name = db.Column(db.String(80), nullable=False)
    style = db.Column(db.String(120))
    yeast_format = db.Column(db.String(80))
    avg_attenuation = db.Column(db.Integer())
    min_temp = db.Column(db.Integer())
    max_temp = db.Column(db.Integer())
    custom = db.Column(db.Boolean(), default=True)
    user_id = db.Column(UUID(as_uuid=True),
                        db.ForeignKey("user.id"),
                        nullable=False)

    user = db.relationship("UserModel")
예제 #3
0
class TaskModel(db.Model):
    __tablename__ = 'tasks'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    to_date = db.Column(db.String(80))
    done = db.Column(db.Boolean())

    milestone_id = db.Column(db.Integer, db.ForeignKey('milestones.id'))
    milestone = db.relationship('MilestoneModel')

    def __init__(self, name, to_date, milestone_id):
        self.name = name
        self.to_date = to_date
        self.done = False
        self.milestone_id = milestone_id

    def json(self):
        return {
            'name': self.name,
            'to_date': self.to_date,
            'done': self.done,
            'milestone_id': self.milestone_id
        }

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

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
class User(db.Model, UserMixin):
    """
    User  Class
    """
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(255))
    last_name = db.Column(db.String(255))
    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())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)
        self.password = utils.hash_password(self.password)

    def edit_update(self, form):
        self.first_name = form.first_name.data
        self.last_name = form.last_name.data
        self.email = form.email.data
        self.password = utils.hash_password(form.password.data)

    def __str__(self):
        return self.email

    def is_active(self):
        return self.active

    def __unicode__(self):
        return self.first_name
예제 #5
0
class UserModel(db.Model):

    __tablename__ = 'users'
    
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80))
    pw_hash = db.Column(db.String(255))
    active = db.Column(db.Boolean(create_constraint=True))

    def __init__(self, username, password, active):
        self.username = username
        self.pw_hash  = generate_password_hash(password)
        self.active = active
    
    def check_password(self, password):
        return check_password_hash(self.pw_hash , password)
    
    def json(self):
        return {'username': self.username, 'active': self.active}

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
    
    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
    
    @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()
예제 #6
0
class OrderModel(db.Model):
    __tablename__ = "tblorders"

    id = db.Column(db.Integer, primary_key=True)
    order_date = db.Column(db.DateTime, default=datetime.datetime.utcnow())
    total_amount = db.Column(db.Float(12, 2), nullable=False)
    order_status = db.Column(db.Boolean(), nullable=False)

    user_id = db.Column(db.Integer,
                        db.ForeignKey("tbluser.id"),
                        nullable=False)
    user = db.relationship("UserModel")

    @classmethod
    def find_by_user_id(cls, user_id: int) -> "OrderModel":
        return cls.query.filter_by(user_id=user_id).first()

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

    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()
예제 #7
0
파일: hops.py 프로젝트: anorum/BeerNotes
class HopsModel(db.Model, BaseModel, SearchableMixin):
    __tablename__ = "hop"
    __searchable__ = [
        'id', 'brand', 'name', 'alpha', 'aroma', 'typical_beer', 'hop_type',
        'user_id'
    ]

    id = db.Column(UUID(as_uuid=True),
                   unique=True,
                   nullable=False,
                   primary_key=True,
                   default=uuid4)
    brand = db.Column(db.String(80))
    name = db.Column(db.String(80))
    alpha = db.Column(db.Float(precision=1))
    aroma = db.Column(db.String(240))
    typical_beer = db.Column(db.String(240))
    hop_type = db.Column(db.String(80))
    custom = db.Column(db.Boolean(), default=True)

    user_id = db.Column(UUID(as_uuid=True),
                        db.ForeignKey("user.id"),
                        nullable=False)

    user = db.relationship("UserModel")
예제 #8
0
파일: user.py 프로젝트: Ionut094/Flask-Demo
class User(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80))
    password = db.Column(db.String(80))
    is_admin = db.Column(db.Boolean(False))

    def __init__(self, username, password, is_admin):
        self.username = username
        self.password = password
        self.is_admin = is_admin

    @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()

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

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

    def json(self):
        return {'id': self.id, 'username': self.username}
예제 #9
0
class VoucherModel(db.Model):
    __tablename__ = "tblvoucher"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), nullable=False, unique=True)
    description = db.Column(db.String(80), nullable=False)
    valid_until = db.Column(db.String(80), nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow())
    active = db.Column(db.Boolean(), default=False)

    @classmethod
    def find_by_name(cls, name: str) -> "VoucherModel":
        return cls.query.filter_by(name=name).first()

    @classmethod
    def find_by_active(cls, active: str) -> "VoucherModel":
        return cls.query.filter_by(active=active).first()

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

    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()
예제 #10
0
파일: user.py 프로젝트: maxkrieg/cohost
class User(db.Model):

    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    handle = db.Column(
        UUID(as_uuid=True),
        default=uuid.uuid4,
        unique=True,
        nullable=False,
    )
    email = db.Column(db.String(80), unique=True, nullable=False)
    first_name = db.Column(db.String(80), nullable=False)
    last_name = db.Column(db.String(80), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now())
    modified_at = db.Column(db.DateTime,
                            default=datetime.now(),
                            onupdate=datetime.now())
    password = db.Column(db.String(128), nullable=False)
    is_admin = db.Column(db.Boolean(), default=False)

    events = db.relationship("EventUser", back_populates="user")
    items = db.relationship("Item", back_populates="user")

    def hash_password(self):
        self.password = generate_password_hash(self.password).decode("utf8")

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

    def __repr__(self):
        return "<User: id={}, email={}, handle={}>".format(
            self.id, self.email, self.handle)
예제 #11
0
class Article(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Text, nullable=False)
    body = db.Column(db.Text, nullable=False)
    link = db.Column(db.Text, nullable=False)
    guid = db.Column(db.String(255), nullable=False)
    unread = db.Column(db.Boolean(255), default=True, nullable=False)
    source_id = db.Column(db.Integer,
                          db.ForeignKey('source.id'),
                          nullable=False)
    source = db.relationship('Source',
                             backref=db.backref('articles', lazy=True))
    date_added = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    date_published = db.Column(db.DateTime)
    __table_args__ = (db.UniqueConstraint('source_id',
                                          'guid',
                                          name='uc_source_guid'), )

    @classmethod
    def insert_from_feed(cls, source_id, feed_articles):
        stmt = Article.__table__.insert().prefix_with('IGNORE')
        articles = []

        for article in feed_articles:
            articles.append({
                'title': article['title'],
                'body': article['summary'],
                'link': article['link'],
                'guid': article['id'],
                'source_id': source_id,
                'date_published': article['published'],
            })

        db.engine.execute(stmt, articles)
예제 #12
0
class FermentablesModel(BaseModel, db.Model, SearchableMixin):
    """ holds grain database table """
    __tablename__ = "fermentable"
    __searchable__ = ['id', 'brand', 'name', 'lovibond', 'category', 'ppg']

    id = db.Column(UUID(as_uuid=True),
                   unique=True,
                   nullable=False,
                   primary_key=True,
                   default=uuid4)
    brand = db.Column(db.String(80))
    name = db.Column(db.String(80), nullable=False)
    ppg = db.Column(db.Integer(), nullable=False)
    lovibond = db.Column(db.Float(), nullable=False)
    category = db.Column(db.String(80), nullable=False)
    country = db.Column(db.String(80))
    user_id = db.Column(UUID(as_uuid=True),
                        db.ForeignKey("user.id"),
                        nullable=False)
    custom = db.Column(db.Boolean(), default=True)

    user = db.relationship("UserModel")

    @classmethod
    def find_by_ids(cls, ids):
        """ Takes in a list of ids and returns list of Model objects"""
        arr = []
        for id in ids:
            try:
                obj = cls.find_by_id(id)
            except:
                continue
            arr.append(obj)
        return arr
예제 #13
0
class MenuModel(db.Model):
    __tablename__ = "tblmenu"

    id = db.Column(db.Integer, primary_key=True)
    menu_name = db.Column(db.String(80), nullable=False)
    price = db.Column(db.Float(12, 2), nullable=False)
    ingredients = db.Column(db.String(500), nullable=False)
    additional = db.Column(db.String(500), nullable=True)
    menu_status = db.Column(db.Boolean(), default=True)

    menu_id = db.Column(db.Integer,
                        db.ForeignKey("tblmenutype.id"),
                        nullable=False)
    menu = db.relationship("MenuTypeModel")

    @classmethod
    def find_by_menuname(cls, menuname: str) -> "MenuModel":
        return cls.query.filter_by(menuname=menuname).first()

    @classmethod
    def find_by_price(cls, price: float) -> "MenuModel":
        return cls.query.filter_by(price=price).first()

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

    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()
예제 #14
0
class Courses(db.Model):
    __tablename__ = 'courses'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(16))
    student_enrolled = db.Column(db.Integer)
    is_active = db.Column(db.Boolean())
    created_datetime = db.Column(db.DateTime(), nullable=False)
    modified_datetime = db.Column(db.DateTime(), nullable=False)
예제 #15
0
class Users(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(16))
    role_id = db.Column(db.Integer)
    password = db.Column(db.String(16))
    first_name = db.Column(db.String(16))
    last_name = db.Column(db.String(16))
    father_name = db.Column(db.String(20))
    roll_no = db.Column(db.Integer)
    class_no = db.Column(db.String(11))
    address = db.Column(db.String(40))
    section = db.Column(db.String(100))
    admission_date = db.Column(db.Date())
    is_active = db.Column(db.Boolean())
    is_delete = db.Column(db.Boolean())
    modified_datetime = db.Column(db.DateTime(), nullable=False)
예제 #16
0
class UserModel(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)

    # User email information
    email = db.Column(db.String(255), nullable=False, unique=True)
    confirmed_at = db.Column(db.DateTime())

    # User information
    is_enabled = db.Column(db.Boolean(), nullable=False, default=False)
    first_name = db.Column(db.String(50), nullable=False, default='')
    last_name = db.Column(db.String(50), nullable=False, default='')
    birth_year = db.Column(db.Integer(), nullable=False)

    # User authentication information
    username = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String(255), nullable=False, default='')

    # meters = db.relationship('Meter', backref='owner', lazy='dynamic')

    def __init__(self, email, username, password, first_name, last_name,
                 birth_year):
        self.email = email
        self.username = username
        self.set_password(password)
        self.first_name = first_name
        self.last_name = last_name
        self.birth_year = birth_year

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

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

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

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

    def is_active(self):
        return self.is_enabled

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

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

    def json(self):
        return {'username': self.username, 'email': self.email}
예제 #17
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    nick_name = db.Column(db.String(255), unique=True)
    first_name = db.Column(db.String(255))
    last_name = db.Column(db.String(255))
    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())
    avatar_hash = db.Column(db.String(32))
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)
        if self.email is not None and self.avatar_hash is None:
            self.avatar_hash = hashlib.md5(
                self.email.encode('utf-8')).hexdigest()

    def __str__(self):
        return self.email

    def gravatar(self, size=40, default='identicon', rating='g'):
        # if request.is_secure:
        #     url = 'https://secure.gravatar.com/avatar'
        # else:
        #     url = 'http://www.gravatar.com/avatar'
        url = 'http://gravatar.duoshuo.com/avatar'
        hash = self.avatar_hash or hashlib.md5(
            self.email.encode('utf-8')).hexdigest()
        return '{url}/{hash}?s={size}&d={default}&r={rating}'.format(
            url=url, hash=hash, size=size, default=default, rating=rating)

    @staticmethod
    def insert_root():
        user = User(first_name='Adam',
                    last_name='Huang',
                    email='*****@*****.**',
                    password='******',
                    active=True)
        if User.query.filter_by(email=user.email).first() is None:
            db.session.add(user)
            db.session.commit()

    def verify_password(self, password):
        return verify_password(password, self.password)

    def verify_and_update_password(self, old_password, new_password):
        if verify_password(old_password, self.password):
            self.password = encrypt_password(new_password)
            db.session.add(self)
            db.session.commit()
            return True

        return False
예제 #18
0
class CustomerResultModel(db.Model):
    # tell SQLAlchemy table name
    __tablename__ = 'customer_results'

    id = db.Column(db.Integer(), primary_key=True, autoincrement=True)
    probability_of_default_next_month = db.Column(
        db.Numeric(precision=2,
                   scale=2,
                   asdecimal=False,
                   decimal_return_scale=None))
    feedback_did_default = db.Column(db.Boolean(), nullable=True)

    # One to One bidirectional (one customer_result to one customer)
    # cascading: delete customers if delete customerresult (cascade on delete) (default value of cascade is save-update, merge)
    customer = db.relationship('CustomerModel',
                               back_populates='customer_result',
                               lazy='dynamic',
                               cascade='delete, save-update, merge')

    last_updated = db.Column(db.TIMESTAMP(timezone=False))

    def __init__(self, probability_of_default_next_month,
                 feedback_did_default):
        self.probability_of_default_next_month = probability_of_default_next_month
        self.feedback_did_default = feedback_did_default
        self.last_updated = datetime.utcnow().strftime(
            '%Y-%m-%d %H:%M:%S')  # generate createdAt date on our server

    def update_customer_result(self, probability_of_default_next_month,
                               feedback_did_default):
        self.probability_of_default_next_month = probability_of_default_next_month
        self.feedback_did_default = feedback_did_default
        self.last_updated = datetime.utcnow().strftime(
            '%Y-%m-%d %H:%M:%S')  # generate createdAt date on our server

    # calling json() method is slow when calling self.chat_posts.all() due to lazy='dynamic' relationship
    def json(self):
        return {
            'id': self.id,
            'probability_of_default_next_month':
            self.probability_of_default_next_month,
            'feedback_did_default': self.feedback_did_default,
            'last_updated': self.last_updated.strftime('%Y-%m-%d %H:%M:%S')
        }

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

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

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()
예제 #19
0
class RecipeModel(db.Model, BaseModel, SearchableMixin):
    __tablename__ = "recipe"

    id = db.Column(UUID(as_uuid=True),
                   nullable=False,
                   primary_key=True,
                   default=uuid4)
    user_id = db.Column(UUID(as_uuid=True),
                        db.ForeignKey("user.id"),
                        nullable=False)
    name = db.Column(db.String(240), nullable=False)
    target_abv = db.Column(db.Float(precision=3))
    actual_abv = db.Column(db.Float(precision=3))
    target_og = db.Column(db.Float(precision=3))
    actual_og = db.Column(db.Float(precision=3))
    target_fg = db.Column(db.Float(precision=3))
    actual_fg = db.Column(db.Float(precision=3))
    batch_size = db.Column(db.Float(precision=1))
    boil_time = db.Column(db.Integer())
    efficiency = db.Column(db.Integer())
    IBU = db.Column(db.Integer())
    SRM = db.Column(db.Float(precision=3))
    hex_color = db.Column(db.String(10))
    description = db.Column(db.UnicodeText())
    style = db.Column(db.String(240), nullable=False)
    method = db.Column(db.String(240), nullable=False)
    instructions = db.Column(ARRAY(db.String(1200)))
    private_recipe = db.Column(db.Boolean(), default=False)
    published = db.Column(db.Boolean(), default=False)
    created_date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    icon = db.Column(db.String(40), nullable=False)
    finished = db.Column(db.Boolean(), default=False)
    priming_level = db.Column(db.Float(), nullable=False)

    user = db.relationship("UserModel")
    fermentables = db.relationship("RecipeFermentables",
                                   cascade="all, delete-orphan")
    hops = db.relationship("RecipeHops", cascade="all, delete-orphan")
    grains = db.relationship("RecipeGrains", cascade="all, delete-orphan")
    yeasts = db.relationship("RecipeYeasts", cascade="all, delete-orphan")
    mash_steps = db.relationship("RecipeMashSteps",
                                 cascade="all, delete-orphan")
예제 #20
0
class UserModel(db.Model):
    __tablename__ = "tbluser"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), nullable=False, unique=True)
    password = db.Column(db.String(150), nullable=False)
    email = db.Column(db.String(80), nullable=False, unique=True)
    isAdmin = db.Column(db.Boolean(), default=False)


    @property
    def most_recent_confirmation(self) -> "ConfirmationModel":
        # ordered by expiration time (in descending order)
        return self.confirmation.order_by(db.desc(ConfirmationModel.expire_at)).first()

    @classmethod
    def find_by_username(cls, username: str) -> "UserModel":
        return cls.query.filter_by(username=username).first()

    @classmethod
    def find_by_email(cls, email: str) -> "UserModel":
        return cls.query.filter_by(email=email).first()

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

    @classmethod
    def find_all(cls) -> List["UserModel"]:
        return cls.query.filter_by().first()

    def send_confirmation_email(self) -> Response:
        # configure e-mail contents
        subject = "Registration Confirmation"
        link = request.url_root[:-1] + url_for(
            "confirmation", confirmation_id=self.most_recent_confirmation.id
        )
        # string[:-1] means copying from start (inclusive) to the last index (exclusive), a more detailed link below:
        # from `http://127.0.0.1:5000/` to `http://127.0.0.1:5000`, since the url_for() would also contain a `/`
        # https://stackoverflow.com/questions/509211/understanding-pythons-slice-notation
        text = f"Please click the link to confirm your registration: {link}"
        html = f"<html>Please click the link to confirm your registration: <a href={link}>link</a></html>"
        # send e-mail with MailGun
        return Mailgun.send_email([self.email], subject, text, html)

    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()
예제 #21
0
class ItemModel(db.Model):
    __tablename__ = 'item'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String())
    description = db.Column(db.String())
    category = db.Column(db.String())
    is_featured = db.Column(db.Boolean())
    price = db.Column(db.Float(precision=2))
    image_URL = db.Column(db.String())

    def __init__(self, name, description, category, is_featured, price, image_URL):
        self.name = name
        self.description = description
        self.category = category
        self.is_featured = is_featured
        self.price = price
        self.image_URL = image_URL

    def json_item(self):
        return {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'category': self.category,
            'isFeatured': self.is_featured,
            'price': self.price,
            'imageUrl': self.image_URL
        }

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

    @classmethod
    def find_by_fav_id(cls, fav_item_ids):
        list = []
        for _id in fav_item_ids:
            list.append(cls.query.filter_by(id=_id).all())
        favObjs = [item for sublist in list for item in sublist]
        return favObjs

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

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

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
예제 #22
0
class User(db.Model, Serializrable):
    __tablename__ = 'users'
    id = db.Column(db.Integer, db.Sequence('id_seq'), primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    u_id = db.Column(db.String(32), unique=True, nullable=False)
    u_password = db.Column(db.String(32), unique=True, nullable=False)
    u_authority = db.Column(db.String(256), unique=True, nullable=False)
    u_department = db.Column(db.String(32), unique=True, nullable=False)
    is_delete = db.Column(db.Boolean())
    u_email = db.Column(db.String(120), unique=True, nullable=False)

    def __repr__(self):
        return '<User %r>' % self.username
예제 #23
0
파일: User.py 프로젝트: justandrewm/wcbh
class UserSettingsModel(db.Model):
    __tablename__ = "user_settings"
    id = db.Column(db.Integer, primary_key=True)

    notifications = db.Column(db.Boolean(), default=bool(True))
    public = db.Column(db.Boolean(), default=bool(True))
    language = db.Column(db.Text(), default=str('English'))

    user_id = db.Column(db.String(50), db.ForeignKey(
        "users.id"), nullable=False)
    user = db.relationship("UserModel")

    @classmethod
    def find_by_user(cls, user_id) -> "UserSettingsModel":
        return cls.query.filter_by(user_id=user_id).first()

    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()
예제 #24
0
파일: user.py 프로젝트: alexmtnezf/Stores
class UserModel(db.Model, BaseModel):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)
    username = db.Column(db.String(80))
    password = db.Column(
        db.String(256)
    )  # OJO: no podemos dejar de ponerle maxlength en SQLite a los campos de tabla
    is_admin = db.Column(db.Boolean())

    def __init__(self, name, username, password, is_admin):
        self.username = username
        self.name = name
        self.password = UserModel.generate_hash(
            password)  # Encrypt password before save it
        self.is_admin = is_admin

    def __str__(self):
        return "User(id='%s')" % self.id

    def json(self):
        return {'id': self.id, 'username': self.username, 'name': self.name}

    # Class methods
    @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()

    @classmethod
    def delete_all(cls):
        try:
            num_rows_deleted = db.session.query(cls).delete()
            db.session.commit()
            return {'message': '{} row(s) deleted'.format(num_rows_deleted)}
        except:
            return {'message': 'Something went wrong'}

    # Static methods
    @staticmethod
    def generate_hash(password):
        return sha256.hash(password)

    @staticmethod
    def verify_hash(password, hash):
        return sha256.verify(password, hash)
예제 #25
0
class User(SerializableModel, db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    alt_id = db.Column(db.String(64), unique=True, nullable=False)
    alias = db.Column(db.String(128), nullable=False)
    email = db.Column(db.String(128), unique=True, nullable=False)
    password = db.Column(db.String(128), nullable=False)
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())

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

    def get_id(self):
        return self.alt_id
예제 #26
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(255), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(64), nullable=False)
    verified = db.Column(db.Boolean(), default=False, nullable=False)

    def __init__(self, username, email, password):
        self.username = username
        self.email = email
        self.password = password
        self.verified = False

    def save(self):
        db.session.add(self)
        db.session.commit()
예제 #27
0
class User(db.Model, UserMixin):
    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True)

    # User Authentication fields
    email = db.Column(db.String(255), nullable=True, unique=True)
    email_confirmed_at = db.Column(db.DateTime())
    username = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String(255), nullable=False)

    # User fields
    active = db.Column(db.Boolean()),
    first_name = db.Column(db.String(50), nullable=True)
    last_name = db.Column(db.String(50), nullable=True)

    games = db.relationship('GameModel', secondary='collection')
예제 #28
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, nullable=False)
    email = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255), nullable=False)
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    package = db.Column(db.Integer,
                        db.ForeignKey('packages.id'),
                        nullable=False)
    language = db.Column(db.String, nullable=False)
    first_name = db.Column(db.String, nullable=False)
    last_name = db.Column(db.String, nullable=False)
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))
예제 #29
0
class FileTempModel(db.Model, Serializrable):
    __tablename__ = 'filetemp'
    id = db.Column(db.Integer,
                   db.Sequence('id_seq'),
                   primary_key=True,
                   autoincrement=True)
    f_key = db.Column(db.String(80), nullable=False)
    f_des = db.Column(db.String(80), nullable=False)
    f_id = db.Column(db.Integer)
    create_at = db.Column(db.DateTime, default=datetime.datetime.now)
    update_at = db.Column(db.DateTime,
                          default=datetime.datetime.now,
                          onupdate=datetime.datetime.now)
    is_delete = db.Column(db.Boolean())

    def __repr__(self):
        return '<File %r>' % self.f_id
예제 #30
0
파일: user.py 프로젝트: timoxue/restful
class User(db.Model, Serializrable):
    __tablename__ = 'users'

    id = db.Column(db.Integer, db.Sequence('id_seq'), primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    u_id = db.Column(db.String(32), unique=True, nullable=False)
    u_password = db.Column(db.String(32), nullable=False)
    u_authority = db.Column(db.String(256), nullable=False)
    u_createtime = db.Column(db.DateTime, default=datetime.datetime.now)
    u_department = db.Column(db.String(32), nullable=False)
    u_name = db.Column(db.String(256), nullable=False)
    u_tele = db.Column(db.String(256))
    is_delete = db.Column(db.Boolean(), default=False)
    u_email = db.Column(db.String(120))
    u_status = db.Column(db.Integer, default=0)  #初始状态为0

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