Ejemplo n.º 1
0
class Tweets(db.Model):
    """ Creating the table tweets for storing all the user tweets """
    id = db.Column(db.Integer, primary_key=True)
    tweet = db.Column(db.String(500))
    username = db.Column(db.String(80))
    retweet = db.Column(db.Integer)
    likes = db.Column(db.Integer)
    email = db.Column(db.String(80))
    profile_photo = db.Column(db.String(80))
    date = db.Column(db.String(30))

    def __init__(self,
                 tweet,
                 username,
                 email,
                 profile_photo,
                 date,
                 retweet=0,
                 likes=0):
        """ Initializing the table tweets """
        self.tweet = tweet
        self.username = username
        self.email = email
        self.profile_photo = profile_photo
        self.retweet = retweet
        self.likes = likes
        self.date = date
Ejemplo n.º 2
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)
    posts = db.relationship('Post', backref='author', lazy=True)

    def get_rest_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}')"
Ejemplo n.º 3
0
class Profile(db.Model):
    """ Creating the table for storing User profile personal information """
    id = db.Column(db.Integer, primary_key=True)
    bio = db.Column(db.String(80))
    location = db.Column(db.String(80))
    website = db.Column(db.String(80))
    profile_photo = db.Column(db.String(80))
    header_photo = db.Column(db.String(80))
    tweets = db.Column(db.Integer)
    following = db.Column(db.Integer)
    followers = db.Column(db.Integer)
    signup_id = db.Column(db.Integer, db.ForeignKey('signup.id'))

    def __init__(self,
                 signup_id,
                 bio='Hi there!',
                 location='',
                 website='',
                 profile_photo='sample_photo.svg',
                 header_photo='sample_header.jpg',
                 tweets=0,
                 following=0,
                 followers=0):
        """ Initializing the table profile"""
        self.bio = bio
        self.location = location
        self.website = website
        self.profile_photo = profile_photo
        self.header_photo = header_photo
        self.tweets = tweets
        self.following = following
        self.followers = followers
        self.signup_id = signup_id
Ejemplo n.º 4
0
class Following(db.Model):
    """ Creating the table following to store all the user who is following others """
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80))
    following = db.Column(db.String(80))

    def __init__(self, username, following):
        """ Initializing the table following """
        self.username = username
        self.following = following
Ejemplo n.º 5
0
class ChatMessages(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    msg = db.Column(db.Text, nullable=False)
    sender_text = db.Column(db.String(50), nullable=False)
    receiver_text = db.Column(db.String(50), nullable=False)

    def __repr__(self):
        return f"User('{self.date_posted}')"
Ejemplo n.º 6
0
class Notifications(db.Model):
    """ Creating the table notifications to store all the user notifications and delete
        them after they are checked """
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80))
    follower_name = db.Column(db.String(80))

    def __init__(self, username, follower_name):
        """ Initialzing the table notifications """
        self.username = username
        self.follower_name = follower_name
Ejemplo n.º 7
0
class Followers(db.Model):
    """ Creating the table followers to store all the followers of each user """
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80))
    followers = db.Column(db.String(80))
    date = db.Column(db.String(30))

    def __init__(self, username, followers, date):
        """ Initializing the table followers """
        self.username = username
        self.followers = followers
        self.date = date
Ejemplo n.º 8
0
class Signup(UserMixin, db.Model):
    """Creating a table for storing user registered info"""
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), unique=True)
    email = db.Column(db.String(30))
    password = db.Column(db.String(80))
    date = db.Column(db.String(30))
    profile = db.relationship('Profile', backref='signup', lazy='dynamic')

    def __init__(self, username, email, password, date):
        """Initialzing the class variables"""
        self.username = username
        self.email = email
        self.password = password
        self.date = date

    def __repr__(self):
        """ Representation of the user instance """
        return '<User {}>'.format(self.username)