Ejemplo n.º 1
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash = db.Column(db.String(128))
    posts = db.relationship('Post', backref='author', lazy='dynamic')
    about_me = db.Column(db.String(140))
    last_seen = db.Column(db.DateTime, default=datetime.utcnow)
    last_message_read_time = db.Column(db.DateTime)
    gposts = db.relationship('Ingroup', backref='writer', lazy='dynamic')
    followed = db.relationship('User',
                               secondary=followers,
                               primaryjoin=(followers.c.follower_id == id),
                               secondaryjoin=(followers.c.followed_id == id),
                               backref=db.backref('followers', lazy='dynamic'),
                               lazy='dynamic')
    comments = db.relationship('Comment', backref='creator', lazy='dynamic')

    def new_messages(self):
        last_read_time = self.last_message_read_time or datetime(1900, 1, 1)
        return Message.query.filter_by(reciever=self.username).filter(
            Message.timestamp > last_read_time).count()

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def set_password(self, password):
        self.password_hash = pwd_context.encrypt(password)

    def check_password(self, password):
        return pwd_context.verify(password, self.password_hash)

    def follow(self, user):
        if not self.is_following(user):
            self.followed.append(user)

    def unfollow(self, user):
        if self.is_following(user):
            self.followed.remove(user)

    def is_following(self, user):
        return self.followed.filter(
            followers.c.followed_id == user.id).count() > 0

    def followed_posts(self):
        followed = Post.query.join(
            followers, (followers.c.followed_id == Post.user_id)).filter(
                followers.c.follower_id == self.id)
        #for p in followed:
        #  form1 = CommentForm()
        # if form1.validate_on_submit():
        #   post = Post(body=form1.post.data, author=current_user)
        #  db.session.add(post)
        # db.session.commit()
        #flash('You just now commented Wohoo XD!')
        #return redirect(url_for('index'))
        own = Post.query.filter_by(user_id=self.id)
        return followed.union(own).order_by(Post.timestamp.desc())
Ejemplo n.º 2
0
class Family(db.Model):
    __tablename__ = "family"

    pk = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False, unique=True)
    members = db.relationship("User",
                              secondary=user_pkentifier,
                              backref="family")
    fridge = db.relationship("Fridge", uselist=False, backref="family")
    grocery_lists = db.relationship("GroceryList", backref="family")
Ejemplo n.º 3
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    email = db.Column(db.String, nullable=False)
    password = db.Column(db.String, nullable=False)
    temp_pass = db.Column(db.String)
    role = db.Column(db.String, nullable=False)
    tasks = db.relationship('TimeEntry', backref='employee')

    def __init__(self,
                 name=None,
                 email=None,
                 password=None,
                 temp_pass=None,
                 role=None):
        self.name = name
        self.email = email
        self.password = password
        self.temp_pass = temp_pass
        self.role = role

    def hash_password(self, password):
        self.password = pwd_context.encrypt(password)

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

    def __repr__(self):
        return '<name: %r>' % self.name
Ejemplo n.º 4
0
class Post(SearchableMixin, db.Model):
    __searchable__ = ['body']
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.String(140))
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    commentS = db.relationship('Comment', backref='POst', lazy='dynamic')
    likes = db.relationship('Like', backref='lik', lazy='dynamic')

    def num(self):
        return Like.query.filter(Like.po == self.id).count()

    #def get_comments(self):
    #   return Comment.query.filter_by(post_id=post.id).order_by(Comment.timestamp.desc())

    def __repr__(self):
        return '<Post {}>'.format(self.body)
class User(db.Model):
    __tablename__ = 'users'
    
    id = db.Column(db.Integer, primary_key=True)
    tasks = db.relationship('Task', backref='poster')
    name = db.Column(db.String, unique=True, nullable=False)
    email = db.Column(db.String, unique=True, nullable=False)
    password = db.Column(db.String, nullable=True)
    tasks = db.relationship('Task', backref='poster')

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

    def __repr__(self):
        return '<User {0}'.format(self.name)
Ejemplo n.º 6
0
def setup_listener(mapper, class_):
    name = class_.__name__
    discriminator = name.lower()
    class_.items = db.relationship(
        Item,
        primaryjoin=db.and_(class_.pk == db.foreign(db.remote(Item.parent_id)),
                            Item.discriminator == discriminator),
        backref=db.backref("parent_%s" % discriminator,
                           primaryjoin=db.remote(class_.pk) == db.foreign(
                               Item.parent_id)))

    @db.event.listens_for(class_.items, "append")
    def append_address(target, value, initiator):
        value.discriminator = discriminator
Ejemplo n.º 7
0
class Track(db.Model):
    """ Song Information """

    __tablename__ = 'tracks'
    uri = db.Column(db.String, primary_key=True)
    id = db.Column(db.String)
    name = db.Column(db.String)
    energy = db.Column(db.Numeric(4, 3))
    valence = db.Column(db.Numeric(4, 3))
    users = db.relationship('User', secondary='user_track', backref='tracks')

    def __repr__(self):
        """Provide helpful representation when printed."""

        return f"<Track id={self.id}>"
Ejemplo n.º 8
0
def setup_listener(mapper, class_):
    name = class_.__name__
    discriminator = name.lower()
    class_.items = db.relationship(Item,
        primaryjoin=db.and_(
            class_.pk == db.foreign(db.remote(Item.parent_id)),
            Item.discriminator == discriminator
        ),
        backref=db.backref(
                "parent_%s" % discriminator,
                primaryjoin=db.remote(class_.pk) == db.foreign(Item.parent_id)
                )
        )
    @db.event.listens_for(class_.items, "append")
    def append_address(target, value, initiator):
        value.discriminator = discriminator
Ejemplo n.º 9
0
class Post(db.Model):
    __tablename__ = 'blogposts'

    postid = db.Column(db.Integer, primary_key=True)
    subject = db.Column(db.String, nullable=False, default='text')
    header = db.Column(db.String, nullable=False)
    digest = db.Column(db.String, nullable=False)
    body = db.Column(db.String, nullable=True)
    date = db.Column(db.Date, default=datetime.datetime.now)
    comments = db.relationship('Comment', backref='commentor')

    def __init__(self, subject, header, digest, body):
        self.subject = subject
        self.header = header
        self.digest = digest
        self.body = body

    def __repr__(self):
        return '<header{0}>'.format(self.header)
Ejemplo n.º 10
0
class User(db.Model):

    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True, nullable=False)
    email = db.Column(db.String, unique=True, nullable=False)
    password = db.Column(db.String, nullable=False)
    tasks = db.relationship('Task', backref='poster')
    role = db.Column(db.String, default="user")

    def __init__(self, name, email, password, role=None):
        self.name = name
        self.email = email
        self.password = password
        self.role = role

    def __repr__(self):
        return "<name %r>" % self.name
Ejemplo n.º 11
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True, nullable=False)
    email = db.Column(db.String, unique=True, nullable=False)
    password = db.Column(db.String, nullable=False)
    expenses = db.relationship('Expense', backref='poster')
    role = db.Column(db.String, default='user')

    #def __init__(self, name=None, email=None, password=None):
    def __init__(self, name=None, email=None, password=None, role=None):
        self.name = name
        self.email = email
        self.password = password
        self.role = role

    def __repr__(self):
        return '<User {0}>'.format(self.name)
Ejemplo n.º 12
0
class Video(db.Model):
    __tablename__ = 'videos'

    video_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    video_type = db.Column(db.String, nullable=False)
    digest = db.Column(db.String, nullable=False)
    thumbnail = db.Column(db.String, nullable=False)
    address = db.Column(db.String, nullable=False)
    comments = db.relationship('videoComment', backref='commentor')

    def __init__(self, name, video_type, digest, address, thumbnail):
        self.name = name
        self.video_type = video_type
        self.digest = digest
        self.address = address
        self.thumbnail = thumbnail

    def __repr__(self):
        return self.name
Ejemplo n.º 13
0
class User(db.Model):
    # Store user data
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True, nullable=False)
    email = db.Column(db.String, unique=True, nullable=False)
    password = db.Column(db.String, nullable=False)
    # the user is referred as 'poster' in this backref
    tasks = db.relationship('Task', backref='poster')
    role = db.Column(db.String, default='user')

    def __init__(self, name=None, email=None, password=None, role=None):
        self.name = name
        self.email = email
        self.password = password
        self.role = role

    def __repr__(self):
        return f'<User> {self.name}'
Ejemplo n.º 14
0
class Short_Answer_Question(db.Model):

    __tablename__ = 'short_answer_questions'

    id = db.Column(db.Integer, primary_key=True)
    question = db.Column(db.Text, nullable=False)
    answer = db.Column(db.Text)

    subject_id = db.Column(db.Integer, db.ForeignKey('subjects.id'))
    subject = db.relationship('Subject',
                              backref=db.backref('short_answer_questions',
                                                 lazy='dynamic'))

    def __init__(self, subject, question, answer=None):
        self.question = question
        self.answer = answer
        self.subject = subject

    def __repr__(self):
        return 'SAQuestion %r>' % self.question[:10]