Esempio n. 1
0
"""
variable "group" in func getall, compose of id, name and display name
rel_dg_ug is a intermediate table for connecting relationships of device groups and user groups
rel_u_ug is a intermediate table for connecting relationships of users and user groups
"""
from sqlalchemy.sql import func

from app.main import db
from app.main.model.user import sdUser
from app.main.model.status_privilege import sdStatusPrivilege

rel_dg_ug = db.Table(
    'sd15_rel_dg_ug',
    db.Column('device_group_id', db.Integer, db.ForeignKey('sd22_device_groups.id')),
    db.Column('user_group_id', db.Integer, db.ForeignKey('sd13_user_groups.id')))

rel_u_ug = db.Table(
    'sd14_rel_u_ug',
    db.Column('user_id', db.Integer, db.ForeignKey('sd11_users.id')),
    db.Column('user_group_id', db.Integer, db.ForeignKey('sd13_user_groups.id')))

rel_role_ug = db.Table(
    'sd16_rel_role_ug',
    db.Column('role_id', db.Integer, db.ForeignKey('sd18_roles.id')),
    db.Column('user_group_id', db.Integer, db.ForeignKey('sd13_user_groups.id')))


class sdUserGroup(db.Model):
    __tablename__ = "sd13_user_groups"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(20), comment="Name", nullable=False)
Esempio n. 2
0
    __tablename__ = "user_debate"

    user_id = db.Column(db.Integer,
                        db.ForeignKey("users.id"),
                        primary_key=True)
    debate_id = db.Column(db.Integer,
                          db.ForeignKey("debates.id"),
                          primary_key=True)
    user_type = db.Column(db.String(10))
    debate = db.relationship("Debate", back_populates="users")
    user = db.relationship("User", back_populates="debates")


# Direct table (as opposed to a model object class) to link the users with their votes
user_vote_tally = db.Table(
    "user_vote_tally", db.metadata,
    db.Column('user_id', db.Integer, db.ForeignKey('users.id')),
    db.Column('debate_id', db.Integer, db.ForeignKey('debates.id')))


class User(db.Model, UserMixin):
    """Table for all user data, because I'm lazy and scared of making new tables
    and also of refactoring but we can ignore that part"""

    __tablename__ = "users"

    # OAuth columns
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(40), unique=True, nullable=False)
    name = db.Column(db.Text, nullable=True)
    avatar = db.Column(db.Text)
    isVIP = db.Column(db.Boolean, default=False)
Esempio n. 3
0
"""DB Model for imgLink table"""
import datetime
import os
from logging import getLogger

from flask import current_app

from app.main import db

LOG = getLogger(__name__)

imgPostJunction = db.Table(
    'imgPostJunction',
    db.Column('img_id',
              db.Integer,
              db.ForeignKey('imgLink.id'),
              primary_key=True),
    db.Column('post_id', db.Integer, db.ForeignKey('post.post_id')))


class ImgLink(db.Model):
    """
    Description of ImgLink Model
    Rows
    -----------
    :id: int [pk]
    :link: varchar (url)
    """
    __tablename__ = 'imgLink'

    id = db.Column(db.Integer, primary_key=True)
Esempio n. 4
0
# coding:utf-8
from app.main import db
from sqlalchemy.sql import func
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import UserMixin
from datetime import datetime
from flask import session, abort, globals
import functools


sys_user_role = db.Table('sys_user_role',  # 用户角色关联表
    db.Column('userId', db.Integer, db.ForeignKey('sys_user.id')),
    db.Column('roleId', db.Integer, db.ForeignKey('sys_role.id')),
    db.Column('createTime', db.DateTime, default=datetime.now),
)

sys_role_permission = db.Table('sys_role_permission',  # 角色权限关联表
    db.Column('permissionId', db.Integer, db.ForeignKey('sys_permission.id')),
    db.Column('roleId', db.Integer, db.ForeignKey('sys_role.id')),
    db.Column('createTime', db.DateTime, default=datetime.now),
)

sys_role_menu = db.Table('sys_role_menu',  # 用户菜单关联表
    db.Column('roleId', db.Integer, db.ForeignKey('sys_role.id')),
    db.Column('menuId', db.Integer, db.ForeignKey('sys_menu.id')),
    db.Column('createdTime', db.DateTime, default=datetime.now),
    db.Column('isDelete', db.Boolean, default=False),
)


# 用户
Esempio n. 5
0
                                   'documents',
                                   lazy='dynamic',
                                   cascade='all, delete-orphan'))

    def get_recipients(self, round_org_id):
        receipt = self.doc_receipts.filter_by(round_org_id=round_org_id,
                                              doc_id=self.id).first()
        if receipt:
            return receipt.members
        else:
            return []


receipt_receivers = db.Table(
    'doc_receipt_receivers_assoc',
    db.Column('receipt_id', db.Integer,
              db.ForeignKey('doc_receive_records.id')),
    db.Column('personal_info_id', db.Integer,
              db.ForeignKey('staff_personal_info.id')))


class DocReceiveRecord(db.Model):
    __tablename__ = 'doc_receive_records'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    predefined_comment = db.Column(
        db.String(255),
        info={
            'label':
            'Predefined Comment',
            'choices':
            [(c, c) for c in
             [u'แจ้งเพื่อทราบ', u'แจ้งเพื่อพิจารณา', u'ขอความร่วมมือเข้าร่วม']]
Esempio n. 6
0
                remove_from_index(obj.__tablename__, obj)
        session._changes = None

    @classmethod
    def reindex(cls):
        for obj in cls.query:
            add_to_index(cls.__tablename__, obj)


db.event.listen(db.session, "before_commit", SearchableMixin.before_commit)
db.event.listen(db.session, "after_commit", SearchableMixin.after_commit)


followers = db.Table(
    "followers",
    db.Column("follower_id", db.Integer, db.ForeignKey("user.id")),
    db.Column("followed_id", db.Integer, db.ForeignKey("user.id")),
)


likes = db.Table(
    "likes",
    db.Column("post_id", db.Integer, db.ForeignKey("post.id")),
    db.Column("user_id", db.Integer, db.ForeignKey("user.id")),
)


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)
Esempio n. 7
0
import datetime

from app.main import db, flask_bcrypt
import jwt
from app.main.model.blacklist import BlacklistToken
from ..config import key

# many to many table between users and card lists
user_card_list = db.Table(
    'user_card_list',
    db.Column('user_id',
              db.Integer,
              db.ForeignKey('user.id'),
              primary_key=True),
    db.Column('card_list_id',
              db.Integer,
              db.ForeignKey('card_list.id'),
              primary_key=True),
)


class UserModel(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    email = db.Column(db.String(255), unique=True, nullable=False)
    username = db.Column(db.String(50), unique=True)
    password_hash = db.Column(db.String(100))

    role_id = db.Column(db.Integer, db.ForeignKey('role.id'), nullable=False)
Esempio n. 8
0
import datetime

from flask_bcrypt import check_password_hash, generate_password_hash
from flask_login import UserMixin
from sqlalchemy.sql import and_, select

from app.main import db, login_manager
from app.main.models.enums import PriorityType
from app.main.models.payments import Payment
from app.main.models.posts import Post
from app.main.models.tags import Tag

userTagJunction = db.Table('userTagJunction',
                           db.Column('user_id', db.Integer,
                                     db.ForeignKey('user.id'), primary_key=True),
                           db.Column('keyword_id', db.Integer, db.ForeignKey('tag.id'),
                                     primary_key=True),
                           db.Column('priority', db.Enum(PriorityType),
                                     default=PriorityType.follow)
                           )

userPostInteraction = db.Table('userPostInteraction',
                               db.Column('user_id', db.Integer,
                                         db.ForeignKey('user.id'), primary_key=True),
                               db.Column('post_id', db.Integer,
                                         db.ForeignKey('post.post_id'), primary_key=True),
                               db.Column('rating', db.Integer, default=0),
                               db.Column('save', db.Boolean, default=True)
                               )


class User(db.Model, UserMixin):
Esempio n. 9
0
from app.main import db

user_follows_course = db.Table(
    'user_follows_course',
    db.Column('user_id',
              db.String(255),
              db.ForeignKey('user.id'),
              primary_key=True),
    db.Column('course_id',
              db.Integer,
              db.ForeignKey('course.id'),
              primary_key=True),
)
from app.main import db
import datetime
from sqlalchemy.sql import func

from app.main import db
import datetime
from sqlalchemy.sql import func

association_table = db.Table(
    'ASSOCIATION_CC_TT', db.Model.metadata,
    db.Column('tt_code', db.String(32), db.ForeignKey('CONTENT.id')),
    db.Column('cc_code', db.String(32), db.ForeignKey('COMPANY.id')))


class Content(db.Model):
    __tablename__ = "CONTENT"
    id = db.Column(db.String(32), primary_key=True)
    companies = db.relationship("Company",
                                secondary=association_table,
                                back_populates="contents")


class Company(db.Model):
    __tablename__ = "COMPANY"
    id = db.Column(db.String(32), primary_key=True)
    name = db.Column(db.String(256), index=True, unique=True)
    link = db.Column(db.String(256), index=True, unique=True)
    contents = db.relationship("Content",
                               secondary=association_table,
                               back_populates="companies")
Esempio n. 11
0
import datetime
from random import sample

from sqlalchemy.ext.hybrid import hybrid_property

# from . import *
from app.main import db
from app.main.models.enums import PostType
# from app.main.models.users import User
from app.main.models.errors import LoginError
from app.main.models.imgLinks import imgPostJunction

postTagJunction = db.Table(
    'postTagJunction',
    db.Column('post_id',
              db.Integer,
              db.ForeignKey('post.post_id'),
              primary_key=True),
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True))


class Post(db.Model):
    """
    Description of Post model.
    Rows
    -----------
    :post_id: int [pk]
    :authorId: varchar [ref: > users.id]
    :title: varchar
    :body: text
    :post_time: timestamp [not null]
Esempio n. 12
0
# -*- coding:utf-8 -*-
from app.main import db
from app.staff.models import StaffAccount

course_instructors = db.Table('eduqa_course_instructor_assoc',
                              db.Column('course_id', db.Integer, db.ForeignKey('eduqa_courses.id')),
                              db.Column('instructor_id', db.Integer, db.ForeignKey('eduqa_course_instructors.id'))
                              )

session_instructors = db.Table('eduqa_session_instructor_assoc',
                               db.Column('session_id', db.Integer, db.ForeignKey('eduqa_course_sessions.id')),
                               db.Column('instructor_id', db.Integer, db.ForeignKey('eduqa_course_instructors.id'))
                               )


class EduQAProgram(db.Model):
    __tablename__ = 'eduqa_programs'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), nullable=False,
                     info={'label': u'ชื่อ'})
    degree = db.Column(db.String(), nullable=False,
                       info={'label': u'ระดับ',
                             'choices': (('undergraduate', 'undergraduate'),
                                         ('graudate', 'graduate'))
                             })


class EduQACurriculum(db.Model):
    __tablename__ = 'eduqa_curriculums'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    program_id = db.Column(db.ForeignKey('eduqa_programs.id'),
Esempio n. 13
0
from sqlalchemy import String

from app.main import db

truck_shipment = db.Table(
    'truck_shipment', db.Column('truck_id', String, db.ForeignKey('truck.id')),
    db.Column('shipment_id', String, db.ForeignKey('shipment.id'),
              unique=True))