예제 #1
0
class TodoModel(db.Model):
    __tablename__ = 'todo'

    id = db.Column(db.Integer(), primary_key=True)
    text = db.Column(db.Unicode())
    completed = db.Column(db.Boolean(), default=False)

    user_id = db.Column(None, db.ForeignKey('user.id'))
예제 #2
0
class UserModel(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255))
    password = db.Column(db.String(60))
    right_id = db.Column(db.Integer, db.ForeignKey('rights.id'), default=1)
    right = db.relationship('UserRightModel', back_populates="users")

    username = db.Column(db.String(100), default='')
    position = db.Column(db.String(100), default='')
    hide = db.Column(db.Boolean(), default=0)

    @validates('email')
    def validate_email(self, key, email):
        assert '@' in email
        return email

    def __init__(self, email, password):
        self.email = email
        self.password = password

    def json(self):
        right = UserRightModel.find_by_id(self.right_id)
        return {
            'id': self.id,
            'email': self.email,
            'right_id': self.right_id,
            'right': self.right.json(),
            'username': self.username,
            'position': self.position,
            'hide': self.hide
        }

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

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

    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 create_random_password(cls):
        return secrets.tocken_hex(8)
예제 #3
0
class ShoppingItemModel(db.Model):
    __tablename__ = 'shopping_item'

    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.Unicode())
    quantity = db.Column(db.Integer())
    unit = db.Column(db.Enum(Unit), nullable=False, default=Unit.kg)
    done = db.Column(db.Boolean(), default=False)

    user_id = db.Column(None, db.ForeignKey('user.id'))
    shopping_list_id = db.Column(None, db.ForeignKey('shopping_list.id'))
예제 #4
0
class Registration(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    username = db.Column(db.Text(), unique=True)
    blob = db.Column(db.Text())
    _priority = db.Column("priority", db.Integer())
    _confirmed = db.Column("confirmed", db.Boolean())
    uni_id = db.Column(db.Integer(), db.ForeignKey("uni.id"))
    uni = db.relationship(
        "Uni",
        backref=db.backref("Registrations",
                           lazy="dynamic",
                           cascade="all, delete-orphan"),
    )

    @property
    def user(self):
        return User.get(self.username)

    @property
    def is_guaranteed(self):
        return any(
            map(self.user.is_in_group,
                current_app.config["ZAPF_GUARANTEED_GROUPS"]))

    @property
    def confirmed(self):
        return self._confirmed or self.is_guaranteed

    @confirmed.setter
    def confirmed(self, value):
        if not self.is_guaranteed:
            self._confirmed = value

    @property
    def priority(self):
        return self._priority if not self.is_guaranteed else -1

    @priority.setter
    def priority(self, value):
        self._priority = value if not self.is_guaranteed else None

    @property
    def data(self):
        return json.loads(self.blob)

    @data.setter
    def data(self, value):
        self.blob = json.dumps(value)

    @property
    def is_zapf_attendee(self):
        return self.confirmed and self.priority < self.uni.slots
예제 #5
0
파일: models.py 프로젝트: rplevka/qpd
class User(db.Model, UserMixin):
    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 __str__(self):
        return self.email

    def set_password(self, password):
        self.password = encrypt_password(password)
예제 #6
0
class Users(UserMixin, db.Model):
    """Admin Model
    model for user admin models, user is allowed to add a question to poll
    """

    __tablename__ = "users"
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(30), unique=True, nullable=False)
    admin = db.Column(db.Boolean, nullable=False, default=False)
    mail = db.Column(db.String(40), unique=True, nullable = False)
    password = db.Column(db.String(), nullable=False)
    confirmed = db.Column(db.Boolean(), nullable = False, default=False)
    confimed_on = db.Column(db.DateTime(), default = datetime.now())

    def __repr__(self):
        return f'{self.id}, {self.username}, {self.mail}, {self.password}'
예제 #7
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column('username',
                         db.String(80),
                         unique=True,
                         nullable=False)
    pw_hash = db.Column('password', db.String())
    email = db.Column('email', db.String())
    has_info = db.Column('has_info', db.Boolean())
    room_id = db.Column(db.Integer, db.ForeignKey('rooms.id'))

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

    def is_active(self):
        """All users will be active"""
        return True

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

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

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

    def is_authenticated(self):
        """We don't support users that aren't 
        logged if the object is in memory 
        they will be authenticated
    """
        return True

    def is_anonymous(self):
        """We do not support anonymous users"""
        return False

    def __repr__(self):
        return '<User {0}>'.format(self.username)
예제 #8
0
class CountryModel(db.Model):
    __tablename__ = 'countries'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50))
    description = db.Column(db.String(250), default="")
    hide = db.Column(db.Boolean(), default=0)

    regions = db.relationship("RegionModel", lazy="dynamic")

    def __init__(self, title):
        self.title = title

    def json(self):
        return {
            "id": self.id,
            "title": self.title,
            "description": self.description
        }

    @classmethod
    def find_by_title(cls, title):
        return cls.query.filter_by(title=title).first()

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

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

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

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