Esempio n. 1
0
class UserRoles(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE'))
    role_id = db.Column(db.Integer(), db.ForeignKey('role.id', ondelete='CASCADE'))

    # Relationships
    user = db.relationship('User', backref='roles')
    role = db.relationship('Role', backref='users')
Esempio n. 2
0
class Image(db.Model):
    __tablename__ = "image"
    id = db.Column(db.Integer, primary_key=True)
    path = db.Column(db.String(255))
    location = db.Column(db.String(255))
    lat = db.Column(db.Float)
    lon = db.Column(db.Float)
    add_at = db.Column(db.DateTime())
    published_at = db.Column(db.DateTime())
    size = db.Column(db.Float)
    desc = db.Column(db.Text)
    source = db.Column(db.Text)
    license = db.Column(db.String(255))
    title = db.Column(db.String(255))
    likes = db.relationship("Like", backref="image")

    @classmethod
    def latest_images(self, count=6):
        images = {}
        for counter, image in enumerate(
                db.session.query(Image).order_by(Image.add_at).limit(count)):
            images[counter] = image

        return images

    @classmethod
    def favourite_images(self, count=6):
        images = {}

        # for counter, image in enumerate(db.session.query(Image).join(Image, Like.image_id).limit(count)):
        #     images[counter] = image

        return images

    @classmethod
    def query_image(self, count, offset):
        return db.session.query(Image).order_by(Image.add_at).limit(count).\
            offset(offset)

    @classmethod
    def get_untouched_image(self, user_id, count=10, offset=0):
        tagged_images = []
        result_images = []
        offset = offset
        res = likes.models.Like.get_user_likes(user_id)
        for r in res:
            tagged_images.append(r.id)
        images = self.query_image(count, offset)
        for im in images:
            if im.id not in tagged_images:
                result_images.append(im)
        while len(result_images) < 1:
            offset = offset + 5
            images = self.query_image(count, offset)
            for im in images:
                if im.id not in tagged_images:
                    result_images.append(im)
        return result_images
Esempio n. 3
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)

    # User email information (required for Flask-User)
    email = db.Column(db.String(255), nullable=False, unique=True)
    confirmed_at = db.Column(db.DateTime())

    # User information
    active = db.Column('is_active',
                       db.Boolean(),
                       nullable=False,
                       server_default='0')
    first_name = db.Column(db.String(50), nullable=False, server_default='')
    last_name = db.Column(db.String(50), nullable=False, server_default='')
    likes = db.relationship("Like", backref="user")
    # Relationships
    user_auth = db.relationship('UserAuth', uselist=False)
    roles = db.relationship('Role',
                            secondary='user_roles',
                            backref=db.backref('users', lazy='dynamic'))
Esempio n. 4
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    user_profile_id = db.Column(db.Integer(), db.ForeignKey('user_profile.id', ondelete='CASCADE'))

    # Flask-User fields
    active = db.Column(db.Boolean(), nullable=False, server_default='0')
    username = db.Column(db.String(50), nullable=False, unique=True)
    email = db.Column(db.String(255), nullable=False, unique=True)
    confirmed_at = db.Column(db.DateTime())
    password = db.Column(db.String(255), nullable=False, server_default='')
    reset_password_token = db.Column(db.String(100), nullable=False, server_default='')

    # Relationships
    user_profile = db.relationship('UserProfile', uselist=False, backref="user")
Esempio n. 5
0
class UserAuth(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer(),
                        db.ForeignKey('user.id', ondelete='CASCADE'))

    # User authentication information (required for Flask-User)
    username = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String(255), nullable=False, server_default='')
    reset_password_token = db.Column(db.String(100),
                                     nullable=False,
                                     server_default='')
    active = db.Column(db.Boolean(), nullable=False, server_default='0')

    # Relationships
    user = db.relationship('User', uselist=False)
Esempio n. 6
0
File: models.py Progetto: kf4x/tcapp
class User(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), nullable=False, unique=True)
    confirmed_at = db.Column(db.DateTime)
    active = db.Column('is_active',
                       db.Boolean(),
                       nullable=False,
                       server_default='0')
    first_name = db.Column(db.String(50), nullable=False, server_default='')
    username = db.Column(db.String(50), nullable=False, unique=True)
    hashed_password = db.Column(db.String)

    # Relationships
    # user has many messages
    # user has many storms
    storms = db.relationship('ThunderStorm', backref='storms', lazy='dynamic')
    # user has many blasts
    blasts = db.relationship('Blast',
                             secondary='user_blasts',
                             backref=db.backref('users', lazy='dynamic'),
                             order_by='Blast.creation')
    conversations = db.relationship('Conversation',
                                    secondary='user_conversations',
                                    backref=db.backref('users',
                                                       lazy='dynamic'))

    # https://flask-login.readthedocs.org/en/latest/#your-user-class
    def is_active(self):
        # a more specific type of registered user. all reg. users will be active.
        return True

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

    def is_authenticated(self):
        # activated their account via email
        # dont want to worry about email when testing
        if app.debug: return True
        return self.active

    def is_anonymous(self):
        # Returns True if this is an anonymous user
        return not self.active

    def get_notifications(self):
        return map(
            lambda u: Object(creater=User.query.get(u.creater).username,
                             rest=u), self.blasts)

    def get_blast(self, b_id):
        to_check = Blast.query.get(b_id)
        #if self.blasts
        return to_check

    def get_pending(self):
        # map reduce
        mapped = map(
            lambda u: Object(creater=User.query.get(u.creater).username,
                             rest=u), self.blasts)
        return filter(lambda x: x.rest.status == "Pending", mapped)

    def get_pending_len(self):
        return len(filter(lambda x: x.status == "Pending", self.blasts))

    # before save hash password..
    # The key needs to be different than what attribute you are changing. More specifically,
    # wtf forms gets all the attributes supplied in the form, it then recursivly sets attributes
    # while they dont match. so If we supply a password field and hash it and save it then wtf
    # forms is going to see its different call __setattr__ again and a infinite loops continues,
    #because we are setting a hash and wtf it trying to set it. so I just look when wtf forms
    # tries to set a field called password and set some other field I didnt supply.
    def __setattr__(self, key, value):
        super(User, self).__setattr__(key, value)
        if key == 'password':
            #pwd = self.password
            hashz = pbkdf2_sha256.encrypt(value, rounds=10, salt_size=16)
            self.hashed_password = hashz