Ejemplo n.º 1
0
from application.database import db

user_permissions = db.Table(
    'userpermissions', db.Column('userid', db.Integer,
                                 db.ForeignKey('user.id')),
    db.Column('permissionid', db.Integer, db.ForeignKey('permission.id')),
    db.UniqueConstraint('userid', 'permissionid', name='uniqueindex'))
Ejemplo n.º 2
0
from application.database import db
from application.database.model import CommonModel
from application.components.workstation.model import Workstation
from application.components.currency.model import Currency


def default_user_config():
    data = {}
    return data


roles_users = db.Table(
    'roles_users',
    db.Column('user_id',
              UUID(as_uuid=True),
              db.ForeignKey('user.id', ondelete='cascade'),
              primary_key=True),
    db.Column('role_id',
              UUID(as_uuid=True),
              db.ForeignKey('role.id', onupdate='cascade'),
              primary_key=True))


class Role(CommonModel):
    __tablename__ = 'role'
    role_code = db.Column(Integer(), index=True, nullable=True)
    role_name = db.Column(String(100), index=True, nullable=False, unique=True)
    description = db.Column(String(255))
    permissions = db.relationship("Permission", cascade="all")
    tenant_id = db.Column(String(),
                          ForeignKey("tenant.id",
                                     onupdate="RESTRICT",
Ejemplo n.º 3
0
    def __init__(self, first_name, second_name, email, password, role=None):
        self.uuid = str(uuid.uuid4())
        self.first_name = first_name
        self.second_name = second_name
        self.email = email
        self.password = generate_password_hash(password)
        self.role = role


game_genre = db.Table(
    "game_genre",
    db.Column("game_id",
              db.Integer,
              db.ForeignKey("games.id"),
              primary_key=True),
    db.Column("genre_id",
              db.Integer,
              db.ForeignKey("genres.id"),
              primary_key=True),
)


class Game(db.Model):
    __tablename__ = "games"

    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(db.String(36), unique=True)
    title = db.Column(db.String(255))
    details = db.Column(db.Text())
    price = db.Column(db.Float())
from sqlalchemy.orm import relationship
from sqlalchemy.orm import *
from sqlalchemy import *
import uuid


def default_uuid():
    return str(uuid.uuid4())


# consumablesupplies
items_categories = db.Table(
    'items_categories',
    db.Column('item_id',
              UUID(as_uuid=True),
              db.ForeignKey('item.id', onupdate='cascade'),
              primary_key=True),
    db.Column('category_id',
              UUID(as_uuid=True),
              db.ForeignKey('itemcategory.id', onupdate='cascade'),
              primary_key=True))


class ItemCategory(CommonModel):
    __tablename__ = 'itemcategory'
    id = db.Column(UUID(as_uuid=True), primary_key=True, default=default_uuid)
    #organization_id = db.Column(UUID(as_uuid=True), ForeignKey("organization.id", ondelete="set null"))
    tenant_id = db.Column(db.String, index=True)
    category_exid = db.Column(String(100), nullable=True, index=True)
    category_no = db.Column(String(100), nullable=True)
    category_name = db.Column(String(150), nullable=False)
    is_show = db.Column(Boolean(), default=True)
Ejemplo n.º 5
0
                                        onupdate='CASCADE',
                                        ondelete='SET NULL'),
                             index=True,
                             nullable=False)
    start_time_working = db.Column(BigInteger())
    end_time_working = db.Column(BigInteger())
    year = db.Column(Integer)
    month = db.Column(Integer)
    day = db.Column(Integer)
    hour = db.Column(Integer)
    minute = db.Column(Integer)


organization_workstation = db.Table(
    "organization_workstation",
    db.Column("organization_id", UUID(as_uuid=True),
              db.ForeignKey("organization.id", ondelete="cascade")),
    db.Column("workstation_id", UUID(as_uuid=True),
              db.ForeignKey("workstation.id", ondelete="cascade")))

employee_workstation = db.Table(
    "employee_workstation",
    db.Column("employee_id", UUID(as_uuid=True),
              db.ForeignKey("employee.id", ondelete="cascade")),
    db.Column("workstation_id", UUID(as_uuid=True),
              db.ForeignKey("workstation.id", ondelete="cascade")))


class Workstation(CommonModel):
    __tablename__ = 'workstation'
    name = db.Column(String)
    organization = db.relationship("Organization")
Ejemplo n.º 6
0
from werkzeug.security import generate_password_hash, check_password_hash
from sqlalchemy.orm import relationship
from application.database import db, UUID
from datetime import datetime
import uuid as uuid_ext

user_role_assoc = db.Table('na_user_role_assoc',
                           db.Column('id', db.Integer(), primary_key=True),
                           db.Column('user_uuid',
                                     UUID,
                                     db.ForeignKey('na_user.uuid'),
                                     primary_key=True),
                           db.Column('role_uuid',
                                     UUID,
                                     db.ForeignKey('na_user_role.uuid'),
                                     primary_key=True),
                           extend_existing=True)

role_hierachy_assoc = db.Table('na_user_role_hierachy_assoc',
                               db.Column('id', db.Integer(), primary_key=True),
                               db.Column('parent_role_uuid',
                                         UUID,
                                         db.ForeignKey('na_user_role.uuid'),
                                         primary_key=True),
                               db.Column('child_role_uuid',
                                         UUID,
                                         db.ForeignKey('na_user_role.uuid'),
                                         primary_key=True),
                               extend_existing=True)

#role_ability_assoc = db.Table('na_user_role_ability_assoc',
Ejemplo n.º 7
0
from gatco_restapi import ProcessingException
from application.database import db
from application.database.model import CommonModel, default_uuid
from sqlalchemy.dialects.postgresql import UUID, JSONB
from application.models.model_danhmuc import QuocGia, TinhThanh, QuanHuyen, XaPhuong, ThonXom


def default_uuid():
    return str(uuid.uuid4())


# Database define

roles_users = db.Table(
    'roles_users', db.Column('user_id', String(), db.ForeignKey('user.id')),
    db.Column('role_id', String(), db.ForeignKey('role.id')))


class User(CommonModel):
    __tablename__ = 'user'
    id = db.Column(String, primary_key=True, default=default_uuid)
    name = db.Column(String())
    unsigned_name = db.Column(String())
    email = db.Column(String(255))
    phone = db.Column(String())
    password = db.Column(String(255))
    accountName = db.Column(String(255))
    salt = db.Column(String())

    active = db.Column(SmallInteger(), default=0)
Ejemplo n.º 8
0
from sqlalchemy.orm import relationship, backref
from sqlalchemy.orm.collections import attribute_mapped_collection

from application.database import db

from application.database.model import CommonModel

import uuid


def default_uuid():
    return str(uuid.uuid4())


roles_users = db.Table(
    'roles_users',
    db.Column('user_id', UUID(as_uuid=True), db.ForeignKey('user.id')),
    db.Column('role_id', db.Integer(), db.ForeignKey('role.id')))


#Enum
class TuyenDonViEnum(object):
    TW = 1
    soyte = 2
    cosodaotao = 3
    bvydct = 4
    khoaydct = 5
    quanhuyen = 6
    bvtructhuocso = 7
    moidangky = 99

Ejemplo n.º 9
0
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.now, onupdate=datetime.now)

    books = db.relationship('Book', backref='owner', lazy=True)
    categories = db.relationship('Category', backref='owner', lazy=True)

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


book_category = db.Table(
    'book_category',
    db.Column('series_id', db.Integer, db.ForeignKey('books.series_id'), primary_key=True, nullable=False),
    db.Column('category_id', db.Integer, db.ForeignKey('categories.category_id'), primary_key=True, nullable=False),
)


class Book(db.Model):
    __tablename__ = 'books'

    book_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    series_id = db.Column(db.Integer, nullable=False)
    book_name = db.Column(db.String(256), nullable=False)
    vol = db.Column(db.Integer, nullable=False, default=1)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'),
                        nullable=False)

    categories = db.relationship('Category', secondary=book_category, lazy='subquery',
Ejemplo n.º 10
0
            db.session.commit()

    def unlike_post(self, post):
        if self.has_liked_post(post):  #if the user has already liked the post,
            Like.query.filter_by(user_id=self.id, post_id=post.id).delete()

    def has_liked_post(self, post):
        return Like.query.filter(Like.user_id == self.id, Like.post_id
                                 == post.id).count() > 0

    def __repr__(self):
        return f"User({self.username}, {self.email}, {self.gender}, {self.bio}, {self.image_file})"


tag_table = db.Table(
    'tag_association', db.Column('id', db.Integer, db.ForeignKey('post.id')),
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.tag_id')))


class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    draft = db.Column(db.Integer)
    tags = db.relationship("Tag",
                           secondary=tag_table,
                           backref=db.backref('posts', lazy='dynamic'),
                           lazy='dynamic')  #Tag.posts
Ejemplo n.º 11
0
    extra_attributes = db.Column(JSONB())
    extra_data = db.Column(JSONB())
    social_info = db.Column(JSONB()) # list of social
    # workstation_id = db.Column(UUID(as_uuid=True), ForeignKey("workstation.id", onupdate="CASCADE", ondelete="RESTRICT"))
    tenant_id = db.Column(String(), ForeignKey("tenant.id", onupdate="CASCADE", ondelete="RESTRICT"), nullable=False)

    __table_args__ = (UniqueConstraint('tenant_id', 'phone', name='uq_contact_tenant_id_phone'),)

    # Methods
    def __repr__(self):
        return '<Contact: {}>'.format(self.contact_name)


contacts_categories = db.Table('contacts_categories',
                      db.Column('contact_id', UUID(as_uuid=True), db.ForeignKey('contact.id', ondelete='cascade'), primary_key=True),
                      db.Column('category_id', UUID(as_uuid=True), db.ForeignKey('contactcategory.id', ondelete='cascade'), primary_key=True))

class ContactCategory(CommonModel):
    __tablename__ = 'contactcategory'
    category_exid = db.Column(String(100), nullable=True, index=True)
    category_no = db.Column(String(20), nullable=True)
    category_name = db.Column(String(150), nullable=False)
    is_default = db.Column(Boolean(), default=False)
    extra_data = db.Column(JSONB())
    contacts = db.relationship("Contact", secondary=contacts_categories, lazy='dynamic')
    workstation_id = db.Column(UUID(as_uuid=True), ForeignKey("workstation.id", ondelete="RESTRICT"))
    tenant_id = db.Column(String(), ForeignKey("tenant.id", onupdate="CASCADE", ondelete="RESTRICT"), nullable=False)
    def __repr__(self):
        return '<ContactCategory: {}>'.format(self.category_name)
Ejemplo n.º 12
0
from werkzeug.security import generate_password_hash, check_password_hash
from application.database import db

users_roles = db.Table(
    'users_roles',
    db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
    db.Column('role_id', db.Integer, db.ForeignKey('role.id'))
)

class Role(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), index=True, unique=True)

    def __repr__(self):
        return '<Role {}>'.format(self.name)

class User(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))
    roles = db.relationship(
        'Role', secondary=users_roles,
        backref='User',
        lazy='dynamic')

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)
    
    def check_password(self, password):
        return check_password_hash(self.password_hash, password)
Ejemplo n.º 13
0
                        ForeignKey, Float)

from sqlalchemy import (Column, String, Integer, DateTime, Date, Boolean,
                        DECIMAL, ForeignKey, Text)
from sqlalchemy.dialects.postgresql import UUID

from sqlalchemy.orm import relationship, backref

from application.database import db
from application.database.model import CommonModel, default_uuid

roles_users = db.Table(
    'roles_users',
    db.Column('user_id',
              Integer,
              db.ForeignKey('users.id', ondelete='cascade'),
              primary_key=True),
    db.Column('role_id',
              Integer,
              db.ForeignKey('role.id', onupdate='cascade'),
              primary_key=True))


class Role(CommonModel):
    __tablename__ = 'role'
    id = db.Column(Integer, autoincrement=True, primary_key=True)
    role_name = db.Column(String(100), index=True, nullable=False, unique=True)
    display_name = db.Column(String(255), nullable=False)
    description = db.Column(String(255))
    user = db.relationship(
        "User",
        secondary="roles_users",