コード例 #1
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), default='', nullable=False)
    email = db.Column(db.String(100), unique=True, nullable=False)
    _password = db.Column('password', db.String(100), nullable=False)

    def _get_password(self):
        return self._password

    def _set_password(self, password):
        if password:
            password = password.strip()
        self._password = generate_password_hash(password)

    password_descriptor = property(_get_password, _set_password)
    password = synonym('_password', descriptor=password_descriptor)

    def check_password(self, password):
        password = password.strip()
        if not password:
            return False
        return check_password_hash(self.password, password)

    @classmethod
    def authenticate(cls, query, email, password):
        user = query(cls).filter(cls.email == email).first()
        if user is None:
            return None, False
        return user, user.check_password(password)

    def __repr__(self):
        return u'<User id={self.id} email={self.email!r}>'.format(self=self)
コード例 #2
0
ファイル: models.py プロジェクト: l769829723/todo
class User(db.Model, BaseModel):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(128), unique=True)
    password = db.Column(db.String(256))
    email = db.Column(db.String(128), unique=True)
    info = db.relationship('UserInfo', backref='owner')
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)

    # todos = db.relationship('Todo', backref='owner')

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

    def __str__(self):
        return self.username

    def set_password(self, password):
        self.password = generate_password_hash(
            password,
            method=current_app.config['PASSWORD_HASH_ALGORITHM'],
            salt_length=current_app.config['PASSWORD_HASH_LENGTH'],
        )

    def verify_password(self, password):
        return check_password_hash(self.password, password)
コード例 #3
0
class Tasks(db.Model):
    Id = db.Column(db.Integer, primary_key=True)
    taskName = db.Column(db.String(100), nullable=False, unique=True)
    status = db.Column(db.Boolean, default=False)
    tid = db.Column(db.Integer,
                    db.ForeignKey('lists.Id', ondelete='CASCADE'),
                    nullable=False)
コード例 #4
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    tasks = db.relationship('Todo', backref='owner', lazy=True)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({"user_id": self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)["user_id"]
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #5
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    email = db.Column(db.String(120), unique=True)
    bookmarks = db.relationship('Bookmark', backref='user', lazy='dynamic')
    password_hash = db.Column(db.String(300))

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(app.secret_key, expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(app.secret_key)
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

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

    @password.setter
    def password(self, password):
        self.password_hash = generate_password_hash(password)

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

    @staticmethod
    def get_by_username(username):
        return User.query.filter_by(username=username).first()
コード例 #6
0
ファイル: todo.py プロジェクト: hrvCode/flask
class Todo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    task = db.Column(db.Text(), nullable=False)
    owner = db.Column(db.String(225))
    status = db.Column(db.String(100))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __init__(self, data):
        self.id = data.get('id')
        self.task = data.get('task')
        self.owner = data.get('owner')
        self.user_id = data.get('user')
        self.status = data.get('status')

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

        return self.id

    @classmethod
    def get_task(cls, task_id):
        return cls.query.get(task_id)

    @property
    def serialize(self):
        return {
            "id": self.id,
            "task": self.task,
            "owner": self.owner,
            "status": self.status,
            "creator": self.user_id
        }
コード例 #7
0
ファイル: models.py プロジェクト: Robin-shrestha/todo-flask
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(30), unique=True, nullable=False)
    password = db.Column(db.String(100), nullable=False)
    todo_posts = db.relationship('Todo', backref='author', lazy=True)
    
    def __repr__(self):
        return f'({self.username})'
コード例 #8
0
class Admins(db.Model):
    Id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)
    firstName = db.Column(db.String(30), nullable=False)
    lastName = db.Column(db.String(30), nullable=False)

    def __repr__(self):
        return 'Admin<{}>'.format(self.email)
コード例 #9
0
class TaskList(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    task_name = db.Column(db.String(140))
    task_status = db.Column(db.Integer, default=0)
    date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return '<{}>'.format(self.task_name)
コード例 #10
0
ファイル: model.py プロジェクト: Agent-Hellboy/potency
class Tasksum(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    description = db.Column(db.Text(20000), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
    task_id = db.Column(db.Integer, db.ForeignKey("tasks.id"), nullable=False)

    def __repr__(self):
        return f"Task('{self.title}','{self.description}')"
コード例 #11
0
class Gender(db.Model):
    """Модель пола"""
    __tablename__ = 'todo_gender'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), index=True)

    def __str__(self):
        return f'Gender {self.name}'
コード例 #12
0
class Mission(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text, nullable=False)
    done = db.Column(db.Boolean, nullable=False, default=False)
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return '<Mission {}>'.format(self.content)
コード例 #13
0
ファイル: models.py プロジェクト: Robin-shrestha/todo-flask
class Todo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    todo_item = db.Column(db.Text, nullable=False)
    completed = db.Column(db.Boolean, nullable=False, default=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"{self.todo_item}"
コード例 #14
0
class Todo(db.Model):
    __tablename__ = 'todo'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), nullable=False)
    completed = db.Column(db.Boolean, default=False)
    activities = db.relationship('Activities', backref="todo", lazy=True)

    def __repr__(self):
        return f"Todo('{self.todo_name}')"
コード例 #15
0
class Activities(db.Model):
    __tablename__ = 'activities'
    id = db.Column(db.Integer, primary_key=True)
    activity = db.Column(db.String(50), nullable=False)
    completed = db.Column(db.Boolean, default=False)
    todo_id = db.Column(db.Integer, db.ForeignKey('todo.id'))

    def __repr__(self):
        return f"Activities('{self.activities}')"
コード例 #16
0
class Tag(db.Model, BaseModel):
    __tablename__ = 'blog_tags'
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer, db.ForeignKey('blog_posts.id'))
    name = db.Column(db.String(128), unique=True)
    posts = relationship("Post", back_populates="tags")

    def __repr__(self):
        return self.name
コード例 #17
0
class Task(db.Model):
    """Database table to store Todo tasks."""

    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.Text)
    done = db.Column(db.Boolean, default=False)

    def __repr__(self):
        """Better string representation of our task."""
        return f"<Task(id={self.id}, body={self.body})>"
コード例 #18
0
class Profession(db.Model):
    """Модель класса персонажа"""
    __tablename__ = 'todo_profession'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), index=True)
    extra = db.Column(db.Text, index=True)

    def __str__(self):
        return f'Profession {self.id} {self.name}'
コード例 #19
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), nullable=False)
    image_file = db.Column(db.String(20), nullable=False, default="default.jpg")
    password = db.Column(db.String(60), nullable=False)
    tasks = db.relationship("Tasks", backref="user", lazy=True, passive_deletes=True)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #20
0
ファイル: models.py プロジェクト: ygivenx/todo
class TODO(db.Model):
    """
    Define the TODO app model

    """

    __tablename__ = "todo"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    body = db.Column(db.String(100), default="")
    done = db.Column(db.Boolean, default=False)
コード例 #21
0
class Race(db.Model):
    """Модель рассы"""
    __tablename__ = 'todo_race'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), index=True)
    extra = db.Column(db.Text, index=True)

    def __str__(self):
        return f'Race {self.id} {self.name}'
コード例 #22
0
class Task(db.Model):
    __tablename__ = 'tasks'

    id = db.Column(db.Integer, primary_key=True)
    description = db.Column(db.Text, nullable=False)
    completed_on = db.Column(db.DateTime)
    created_by = db.Column(db.Integer,
                           db.ForeignKey('users.id'),
                           nullable=False)

    creator = db.relationship('User', backref='tasks')
コード例 #23
0
ファイル: models.py プロジェクト: kangaechu/flask-todo
class Entry(db.Model):
    __tablename__ = 'entries'
    id = db.Column(Integer, primary_key=True)
    text = db.Column(Text)
    completed = db.Column(Integer, default=0)
    created_at = db.Column(DateTime, default=datetime.now())
    updated_at = db.Column(DateTime, default=datetime.now())
    elaps = ""

    def __repr__(self):
        return "<Entry id{} = text={!r}>".format(self.id, self.text)
コード例 #24
0
class Entry(db.Model):
    __tablename__ = 'entries'
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text)
    completed = db.Column(db.Integer, default=0)
    created_at = db.Column(db.DateTime, default=datetime.now())
    updated_at = db.Column(db.DateTime, default=datetime.now())

    def __repr__(self):
        return "<Entry id={id} text={text!r}>".format(id=self.id,
                                                      text=self.text)
コード例 #25
0
ファイル: model.py プロジェクト: Agent-Hellboy/potency
class Tasks(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
    todo_id = db.Column(
        db.Integer, db.ForeignKey("todo.id", ondelete="CASCADE"), nullable=False
    )
    tasksum = db.relationship(
        "Tasksum", backref="todo", lazy=True, passive_deletes=True
    )

    def __repr__(self):
        return f"Task('{self.title}','{self.date}','{self.todo_id}')"
コード例 #26
0
class Lists(db.Model):
    Id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200), nullable=False)
    tasks = db.relationship('Tasks',
                            backref='listName',
                            lazy=True,
                            cascade="all")
    uid = db.Column(db.Integer,
                    db.ForeignKey('users.Id', ondelete="CASCADE"),
                    nullable=False)

    def __repr__(self):
        return f'{self.name}: User: {self.username.username}'
コード例 #27
0
ファイル: models.py プロジェクト: l769829723/todo
class Todo(db.Model, BaseModel):
    __tablename__ = 'todos'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128))
    publish_time = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    is_done = db.Column(db.Boolean, default=False)
    is_important = db.Column(db.Boolean, default=False)

    def __repr__(self):
        return '<Todo: %r>' % self.name

    def __str__(self):
        return self.name
コード例 #28
0
class Bookmark(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    url = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    description = db.Column(db.String(300))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    #the many side get the foreign key

    @staticmethod
    def newest():
        return Bookmark.query.order_by(desc(Bookmark.date))

    def __str__(self):
        return f'<Bookmark {self.description}:{self.url}'
コード例 #29
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(60), unique=True, nullable=False)
    password_hash = db.Column(db.String(128))
    missions = db.relationship('Mission', backref='author', lazy='dynamic')

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

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

    def __repr__(self):
        return '<User {}>'.format(self.username)
コード例 #30
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False, unique=True)

    @staticmethod
    def get_tasks(name):
        user = User.query.filter_by(name=name).first()

        if not user:
            raise RecordNotFoundError('User not found.')

        return [get_dict(task) for task in user.tasks]