Exemple #1
0
import datetime as dt

from flask_jwt_extended import current_user
from slugify import slugify

from conduit.database import (Model, SurrogatePK, db, Column, reference_col,
                              relationship)
from conduit.profile.models import UserProfile

moderator_assoc = db.Table(
    "moderator_assoc",
    db.Column("moderator", db.Integer, db.ForeignKey('userprofile.id')),
    db.Column("organization", db.Integer, db.ForeignKey('organization.id')))

member_assoc = db.Table(
    "member_assoc",
    db.Column("member", db.Integer, db.ForeignKey('userprofile.id')),
    db.Column("organization", db.Integer, db.ForeignKey('organization.id')))

article_assoc = db.Table(
    "article_assoc",
    db.Column("article", db.Integer, db.ForeignKey('article.id')),
    db.Column("organization", db.Integer, db.ForeignKey('organization.id')))


class Organization(Model, SurrogatePK):
    __tablename__ = 'organization'

    id = db.Column(db.Integer, primary_key=True)
    name = Column(db.String(100), nullable=False)
    slug = Column(db.Text, nullable=False, unique=True)
Exemple #2
0
# coding: utf-8

import datetime as dt

from flask_jwt_extended import current_user
from slugify import slugify

from conduit.database import (Model, SurrogatePK, db, Column, reference_col,
                              relationship)

tag_follower_assoc = db.Table(
    "tag_follower_assoc",
    db.Column("tag_id", db.Integer, db.ForeignKey("tags.id"),
              primary_key=True),
    db.Column("follower_id",
              db.Integer,
              db.ForeignKey("userprofile.id"),
              primary_key=True))

tag_moderators_assoc = db.Table(
    "tag_moderators_assoc",
    db.Column("tag_id", db.Integer, db.ForeignKey("tags.id"),
              primary_key=True),
    db.Column("moderator_id",
              db.Integer,
              db.ForeignKey("userprofile.id"),
              primary_key=True))

tag_needReviewArticle_assoc = db.Table(
    "tag_needReviewArticle_assoc",
    db.Column("tag_id", db.Integer, db.ForeignKey("tags.id"),
Exemple #3
0
from conduit.database import (Model, SurrogatePK, db, reference_col,
                              relationship)
from flask_jwt import current_identity

followers_assoc = db.Table(
    "followers_assoc",
    db.Column("follower", db.Integer, db.ForeignKey("userprofile.user_id")),
    db.Column("followed_by", db.Integer, db.ForeignKey("userprofile.user_id")))


class UserProfile(Model, SurrogatePK):
    __tablename__ = 'userprofile'

    # id is needed for primary join, it does work with SurrogatePK class
    id = db.Column(db.Integer, primary_key=True)

    user_id = reference_col('users', nullable=False)
    user = relationship('User', backref=db.backref('profile', uselist=False))
    follows = relationship('UserProfile',
                           secondary=followers_assoc,
                           primaryjoin=id == followers_assoc.c.follower,
                           secondaryjoin=id == followers_assoc.c.followed_by,
                           backref='followed_by',
                           lazy='dynamic')

    def __init__(self, user, **kwargs):
        db.Model.__init__(self, user=user, **kwargs)

    def is_following(self, profile):
        return bool(
            self.follows.filter(
Exemple #4
0
# coding: utf-8

import datetime as dt

from flask_jwt_extended import current_user
from slugify import slugify

from conduit.database import (Model, SurrogatePK, db, Column,
                              reference_col, relationship)
from conduit.profile.models import UserProfile

favoriter_assoc = db.Table("favoritor_assoc",
                           db.Column("favoriter", db.Integer, db.ForeignKey("userprofile.id")),
                           db.Column("favorited_article", db.Integer, db.ForeignKey("article.id")))

tag_assoc = db.Table("tag_assoc",
                     db.Column("tag", db.Integer, db.ForeignKey("tags.id")),
                     db.Column("article", db.Integer, db.ForeignKey("article.id")))

class Tags(Model):
    __tablename__ = 'tags'

    id = db.Column(db.Integer, primary_key=True)
    tagname = db.Column(db.String(100))

    def __init__(self, tagname):
        db.Model.__init__(self, tagname=tagname)

    def __repr__(self):
        return self.tagname
Exemple #5
0
# coding: utf-8

import datetime as dt

from flask_jwt_extended import current_user
from slugify import slugify

from conduit.database import (Model, SurrogatePK, db, Column, reference_col,
                              relationship)
from conduit.profile.models import UserProfile

favoriter_assoc = db.Table(
    "favoritor_assoc",
    db.Column("favoriter", db.Integer, db.ForeignKey("userprofile.id")),
    db.Column("favorited_article", db.Integer, db.ForeignKey("article.id")))

tag_assoc = db.Table(
    "tag_assoc", db.Column("tag", db.Integer, db.ForeignKey("tags.id")),
    db.Column("article", db.Integer, db.ForeignKey("article.id")))

category_assoc = db.Table(
    "category_assoc",
    db.Column("category", db.Integer, db.ForeignKey("categories.id")),
    db.Column("article", db.Integer, db.ForeignKey("article.id")))

category_tree = db.Table(
    "category_tree",
    db.Column("parent_id", db.Integer, db.ForeignKey("categories.id")),
    db.Column("children_id", db.Integer, db.ForeignKey("categories.id")))

Exemple #6
0
# coding: utf-8

import datetime as dt

from flask_jwt_extended import current_user
from slugify import slugify

from conduit.database import (Model, SurrogatePK, db, Column, reference_col,
                              relationship)
from conduit.profile.models import UserProfile
from conduit.tags.models import Tags

favoriter_assoc = db.Table(
    "favoritor_assoc",
    db.Column("favoriter", db.Integer, db.ForeignKey("userprofile.id")),
    db.Column("favorited_article", db.Integer, db.ForeignKey("article.id")))

comment_like_assoc = db.Table(
    "comment_like_assoc",
    db.Column("profile_liking_comment", db.Integer,
              db.ForeignKey("userprofile.id")),
    db.Column("comment_liked", db.Integer, db.ForeignKey("comment.id")))

tag_assoc = db.Table(
    "tag_assoc", db.Column("tag", db.Integer, db.ForeignKey("tags.id")),
    db.Column("article", db.Integer, db.ForeignKey("article.id")))

org_assoc = db.Table(
    "org_assoc",
    db.Column("organization", db.Integer, db.ForeignKey("organization.id")),
    db.Column("article", db.Integer, db.ForeignKey("article.id")))