Exemplo n.º 1
0
class Role(db.Model, RoleMixin):
    """
    Roles indicate the actions that a user is able to take on the site as well
    as the pages that they would be allowed to access.
    """
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))
Exemplo n.º 2
0
class UserProfile(db.Model, UserMixin):
    """
    User Profile Data. I'm torn between keeping social data on the profile. It could be
    just as easily done in a meta data table. I will store data here now to keep the application
    simple atm. Note: that the UserProfile is one of the only tables that is using a custom
    __init__ method. This makes the insert with the bio easier.
    """
    __tablename__ = 'user_profile'
    profile_id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), unique=True)
    first_name = db.Column(db.String(45), default='')
    last_name = db.Column(db.String(45), default='')
    homepage = db.Column(db.String(100), default='')
    github = db.Column(db.String(50), default='')
    google = db.Column(db.String(50), default='')
    facebook = db.Column(db.String(50), default='')
    stackoverflow = db.Column(db.String(50), default='')
    twitter = db.Column(db.String(50), default='')
    updated_at = db.Column(db.DateTime, default=datetime.utcnow())
    bio_text_id = db.Column(db.Integer, db.ForeignKey('user_bio_text.bio_text_id'))

    user = db.relationship('User', uselist=False)
    user_bio_text = db.relationship('UserBioText', uselist=False)

    bio_text = None

    def __init_old__(self, user, first_name='', last_name='', homepage='', github='', facebook='',
                 stackoverflow='', twitter='', updated_at=None, bio_text=""):
        self.user = user
        self.first_name = first_name
        self.last_name = last_name
        self.homepage = homepage
        self.github = github
        self.facebook = facebook
        self.stackoverflow = stackoverflow
        self.twitter = twitter

        if updated_at is None:
            updated_at = datetime.utcnow()

        self.updated_at = updated_at

        # Create bio text entry also when creating a new profile and link it back to here.
        bio_text = UserBioText()
        self.bio_text_id = bio_text.bio_text_id
        self.bio_text = bio_text.bio_text

        db.session.add(self)
        db.session.add(bio_text)

    def __repr__(self):
        return '<class UserProfile user_id: %r, first_name: %r, last_name: %r, homepage: %r, ' \
               'github: %r, facebook: %r, stackoverflow: %r, twitter: %r>' \
               % (self.user_id, self.first_name, self.last_name, self.homepage, self.github,
                  self.facebook,
                  self.stackoverflow, self.twitter)
Exemplo n.º 3
0
class User(db.Model, UserMixin):
    """
    User private information. This table is used for registration, security and
    tracking. See `UserProfile` for a more public/social description of a user.
    """
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(32), unique=True)
    email = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))
    # provider is the
    provider = db.Column(db.Integer(1), default=0)
    active = db.Column(db.Boolean())
    # Time user confirmed registration via email
    confirmed_at = db.Column(db.DateTime())
    # Login tracking extras integrated via flask_security.
    last_login_at = db.Column(db.DateTime())
    current_login_at = db.Column(db.DateTime())
    last_login_ip = db.Column(db.String(64))
    current_login_ip = db.Column(db.String(64))
    login_count = db.Column(db.Integer())
    # For roles, required to give varied levels of security through permissions to
    # perform certain tasks described by a users role.
    roles = db.relationship('Role', secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    provider_list = ["client", "facebook", "google", "github"]

    def get_provider_id(self, provider=None):
        """
        Get the provider id by looking it up in this list. The provider is who provided the
        users initial account information upon registration. There is no tightly coupled behavior
        linked to this data, meaning it is more informational than functional at this time. It
        could be useful for instance if a user signed up and then came back to the site after being
        away for a few months and they tried to use the login form or to reset their password
        forgetting that they signed up with Facebook and not the user form. We could inform the
        user to sign in using Facebook.

        :param provider:
        :return integer:
        """
        if provider in self.provider_list:
            return self.provider_list.index(provider)
        return 0

    def __repr__(self):
        return '<User %r>' % self.email
Exemplo n.º 4
0
class DocDoc(db.Model):
    """
    Every Document or Article will be stored similar to a user. This will make it easier to
    aggregate data on an article over time. I am thinking to maybe abstract base_url in the
    future to another table so that the base_url of a page is like a category and entire
    sites could be cataloged. This way when a new article is added to a page and a user surfs
    to that page while having the "doc doc browser extension" installed the extension will be
    smart enough to ask for a review or at least note the page somehow.
    """
    __tablename__ = "doc_doc"
    doc_id = db.Column("doc_id", db.Integer, primary_key=True)
    full_url = db.Column(db.String(440), nullable=False)
    port = db.Column(db.Integer, nullable=True)
    base_url = db.Column(db.String(120), nullable=False)
    pathname = db.Column(db.String(120), default="", nullable=False)
    fragment = db.Column(db.String(100), default="", nullable=True)
    query_string = db.Column(db.String(100), default="", nullable=True)
    params = db.Column(db.String(100), default="", nullable=True)
    discoverer = db.Column(db.Integer, db.ForeignKey("user.id"))
    discovered = db.Column(db.DateTime, default=datetime.utcnow())
    visits = db.Column(db.Integer, default=1)
    meta_data_id = db.Column(db.Integer, db.ForeignKey("doc_site_meta.meta_id"))

    # doc_site_meta = db.relationship("DocSiteMeta", lazy="joined")
    doc_site_meta = db.relationship("DocSiteMeta")
    user = db.relationship("User")

    def __repr__(self):
        return '<class DocDoc doc_id: %r, base_url: %r, pathname: %r, fragment: %r, ' \
               'query_string: %r, params %r, discoverer: %r, discovered: %r, visits: %r, ' \
               'meta_data_id: %r, doc_site_meta: %r, user: %r>' % \
               (self.doc_id, self.base_url, self.pathname, self.fragment,
                self.query_string, self.params, self.discoverer, self.discovered, self.visits,
                self.meta_data_id, self.doc_site_meta, self.user)
Exemplo n.º 5
0
class DocTerm(db.Model):
    """
    A Term can relate to any object. Right now it only links using Reviews through the
    review_term association (top of file). This is many-to-many relationship handled by
    SQL Alchemy.
    """
    __tablename__ = "doc_term"
    term_id = db.Column(db.Integer, primary_key=True)
    term = db.Column(db.String(64))
    # reviews = db.relationship("DocReview", secondary=reviews_terms, back_populates="terms")
    reviews = db.relationship("DocReview", secondary=reviews_terms)

    def __repr__(self):
        return "<class DocTerm term_id: %r, term: %r>" % \
               (self.term_id, self.term)
Exemplo n.º 6
0
class CommunityApproval(db.Model):
    """
    Community Approvals are the votes made by users on reviews, ratings, and detours that
    other users have made. It's possible that there won't be a need to approval on a rating so I
    will stick to using the detours and reviews. Each user can only vote one time on their
    approval of a thing.
    """
    __tablename__ = 'community_approval'
    vote_id = db.Column(db.Integer, primary_key=True)
    doc_id = db.Column('doc_id', db.Integer, db.ForeignKey('doc_review.doc_review_id'))
    user_id = db.Column('user_id', db.Integer, db.ForeignKey('doc_review.doc_review_id'))
    # Possible values for type are 'rating', 'review', 'detour'.
    type = db.Column('type', db.String(12), default='review')
    # True = up-vote and False = down-vote
    vote = db.Column(db.Boolean, default=True)
    db.UniqueConstraint('doc_id', 'user_id', 'type')

    def __repr__(self):
        return """<class DocReviewBody %r>""" % self.doc_review_id
Exemplo n.º 7
0
class DocSiteMeta(db.Model):
    """
    Site meta is the og:meta data parsed from a site when it is initially added to DocDocs.
    The image right now will just be a link but in the future it would probably be good to save
    the image. I'm not sure. I know that a lot of sites are trying to stop people from remotely
    displaying their content so it might be needed to actually download the images from sites.
    But that's a lot of images, although they could be compressed a lot.
    """
    __tablename__ = "doc_site_meta"
    meta_id = db.Column(db.Integer, primary_key=True)
    image = db.Column(db.String(255), nullable=True, default="")
    title = db.Column(db.String(255), nullable=True, default="")
    url = db.Column(db.String(300))
    site_type = db.Column(db.String(255), nullable=True, default="")
    locale = db.Column(db.String(20), nullable=True, default="")
    locale_alternate = db.Column(db.String(100), nullable=True, default="")
    site_name = db.Column(db.String(255), nullable=True, default="")
    description = db.Column(db.String(300), nullable=True, default="")
    determiner = db.Column(db.String(10), nullable=True, default="")
    video = db.Column(db.String(140), nullable=True, default="")
    audio = db.Column(db.String(140), nullable=True, default="")

    doc_doc = db.relationship("DocDoc")