Ejemplo n.º 1
0
class User(db.Model, UserMixin):
    post_author = db.relationship('Post', backref='author', lazy=True)
    project_admin = db.relationship('Project', backref='admin', lazy=True)

    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='profile_pics\default.jpg')
    password = db.Column(db.String(60), nullable=False)
    is_admin = db.Column(db.Boolean)

    def __repr__(self):
        return self.username

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

    @staticmethod
    def validate_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)
class User(db.Model, UserMixin):

    post_author = db.relationship('Post', backref='author', lazy=True)
    project_admin = db.relationship('Project', backref='admin', lazy=True)
    # projects = db.relationship('Project', secondary="contributor_table", lazy=True)
    #sqlalchemy.exc.ArgumentError: Error creating backref 'contributor' on relationship 'Project.contributor_id': property of that name exists on mapper 'mapped class User->user'

    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='profile_pics\default.jpg')
    password = db.Column(db.String(60), nullable=False)
    is_admin = db.Column(db.Boolean)

    def __repr__(self):
        return self.username

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

    @staticmethod
    def validate_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)
Ejemplo n.º 3
0
class Project(db.Model):
    contributors = db.relationship('User',
                                   secondary='contributor_table',
                                   backref='contribution_id')

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(120), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    github_repo = db.Column(db.String(120), nullable=True, unique=True)
    admin_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    tag = db.Column(db.String, nullable=True)

    def __repr__(self):
        return "Project('{}','{}','{}')".format(self.title, self.date,
                                                self.content)
Ejemplo n.º 4
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(120), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    project_id = db.Column(db.Integer,
                           db.ForeignKey('project.id'),
                           nullable=False)

    def __repr__(self):
        return "Post('{}','{}','{}')".format(self.title, self.date,
                                             self.user_id)