Example #1
0
class Case(db.Model):
    __tablename__ = 'case'
    id = db.Column(db.Integer, primary_key=True)  # noqa
    date = db.Column(db.DateTime,
                     nullable=True,
                     default=datetime.datetime.now())
    diagnosis = db.Column(db.String, nullable=True)
    patient_surename = db.Column(db.String, nullable=True)
    doctor_id = db.Column(
        db.Integer,
        db.ForeignKey('doctor.id', ondelete='CASCADE'),
        index=True,
        nullable=True,
    )
    patient_id = db.Column(
        db.Integer,
        db.ForeignKey('patient.id', ondelete='CASCADE'),
        index=True,
        nullable=True,
    )
    doctor = db.relationship('Doctor', backref='case')
    patient = db.relationship('Patient', backref='case')

    def json_dump(self):
        return {
            'id': self.id,  # noqa
            'date': self.date,
            'diagnosis': self.diagnosis,
            'patient_surename': self.patient_surename,
        }

    def __repr__(self):
        return '<Case {0} {1} {2} {3}>'.format(self.id, self.patient_surename,
                                               self.diagnosis, self.date)
Example #2
0
class Question(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    major_id = db.Column(db.Integer,
                         db.ForeignKey('major.id', ondelete='CASCADE'),
                         nullable=False)
    prof_id = db.Column(db.Integer,
                        db.ForeignKey('prof.id', ondelete='CASCADE'),
                        nullable=False)
    kurs_id = db.Column(db.Integer,
                        db.ForeignKey('kurs.id', ondelete='CASCADE'),
                        nullable=False)
    q_text = db.Column(db.Text, nullable=False)
    img_name = db.Column(db.String(255), nullable=True)
    answ1 = db.Column(db.String(255), nullable=False)
    answ1_true = db.Column(db.SmallInteger, nullable=False)
    answ2 = db.Column(db.String(255), nullable=True)
    answ2_true = db.Column(db.SmallInteger, nullable=True)
    answ3 = db.Column(db.String(255), nullable=True)
    answ3_true = db.Column(db.SmallInteger, nullable=True)

    major = relationship('Major')
    prof = relationship('Prof')
    kurs = relationship('Kurs', backref='questions')

    def __repr__(self):
        return '<Вопрос {}>'.format(self.q_text)
Example #3
0
class Task(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, nullable=False)
    description = db.Column(db.String, nullable=True)
    short_description = db.Column(db.String, nullable=True)
    due_date = db.Column(db.DateTime, nullable=True)
    author = db.Column(db.Integer, db.ForeignKey("user.id"))
    executor = db.Column(db.Integer, db.ForeignKey("user.id"))
    project_id = db.Column(db.Integer, db.ForeignKey("project.id"))
    comments = db.relationship("Comment",
                               backref=db.backref("comment"),
                               lazy=True)
    status = db.Column(db.Integer, db.ForeignKey("status.id"))
    tag = db.relationship("Tag",
                          secondary=tags,
                          backref=db.backref("task_tag"),
                          lazy=True)

    @property
    def is_active(self):
        return self.status == 'active'

    @property
    def is_wait(self):
        return self.status == 'wait'

    @property
    def is_disable(self):
        return self.status == 'disable'

    def __repr__(self):
        return f"<Task {self.title} >"
Example #4
0
class UsersWords(db.Model):
    __tabename__ = 'users_words'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    engword_id = db.Column(db.Integer, db.ForeignKey('English_words.id'))
    frenchword_id = db.Column(db.Integer, db.ForeignKey('French_words.id'))
    user_engword_id = db.Column(
        db.Integer, db.ForeignKey('English_words_added_by_users.id'))
    user_frenchword_id = db.Column(
        db.Integer, db.ForeignKey('French_words_added_by_users.id'))
    imported_time = db.Column(db.DateTime,
                              nullable=True,
                              default=datetime.now())
    status = db.Column(db.String, nullable=True, default='new')
    memorizing_time = db.Column(db.DateTime, nullable=True)
    word_translation = db.Column(db.Integer, nullable=True, default=0)
    translation_word = db.Column(db.Integer, nullable=True, default=0)
    word_write = db.Column(db.Integer, nullable=True, default=0)
    translation_write = db.Column(db.Integer, nullable=True, default=0)
    remember_word = db.Column(db.Integer, nullable=True, default=0)

    users = db.relationship('User', backref='users')
    english_words = db.relationship('EnglishWord', backref='english_words')
    french_words = db.relationship('FrenchWord', backref='french_words')
    user_english_words = db.relationship('EnglishWordOfUser',
                                         backref='user_english_words')
    user_french_words = db.relationship('FrenchWordOfUser',
                                        backref='user_french_words')
Example #5
0
class Favourite(db.Model):
    __tablename__ = "favourite_vacancies"

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    vacancy_id = db.Column(db.Integer,
                           db.ForeignKey('vacancies.id'),
                           nullable=False)
Example #6
0
class List_access(db.Model):
    list_id = db.Column(db.Integer,
                        db.ForeignKey('shopping_list.id'),
                        primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    role = db.Column(db.Integer)
    user = relationship('User')

    def __repr__(self):
        return 'List access {} : {}'.format(self.list_id, self.user_id)
Example #7
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, nullable=False)
    attach = db.Column(db.LargeBinary, nullable=True)
    task = db.Column(db.Integer, db.ForeignKey("task.id"))
    author = db.Column(db.Integer, db.ForeignKey("user.id"))

    def __repr__(self):
        return f"<Comment {self.text}>"
Example #8
0
class Doc(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(64), unique=True, index=True)
    text = db.Column(db.Text)
    timestamp = db.Column(db.DateTime, default=datetime.now)

    category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return '<Doc {}'.format(self.body)
Example #9
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    created = db.Column(db.DateTime, nullable=False, default=datetime.now())
    news_id = db.Column(db.Integer, db.ForeignKey('news.id', ondelete='CASCADE'), index=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'), index=True)
    news = relationship('News', backref='comments')
    user = relationship('User', backref='comments')

    def __repr__(self):
        return '<Comment {} - {}>'.format(self.id, self.text)
Example #10
0
class Message(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    sender_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    recipient_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    body = db.Column(db.String(140))
    timestamp = db.Column(db.DateTime,
                          index=True,
                          default=datetime.datetime.utcnow)

    def __repr__(self):
        return f'<Message {self.body}>'
Example #11
0
class VacancyGrade(db.Model):
    __tablename__ = "vacancy_grades"

    id = db.Column(db.Integer, primary_key=True)
    vacancy_id = db.Column(db.Integer,
                           db.ForeignKey('vacancies.id'),
                           nullable=False)
    prof_area_id = db.Column(db.Integer,
                             db.ForeignKey('prof_areas.id'),
                             nullable=False)
    grade = db.Column(db.DECIMAL(18, 17), nullable=True)
Example #12
0
class Point(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date_add = db.Column(db.DateTime, nullable=False, default=datetime.now())
    time_value = db.Column(db.Integer, nullable=False)
    comment = db.Column(db.Text, nullable=True)
    track_id = db.Column(db.Integer, db.ForeignKey('track.id'), index=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True)
    track = relationship('Track', backref='points')
    user = relationship('User', backref='points')

    def __repr__(self):
        return '<Point = {}>'.format(self.id)
Example #13
0
class CategorySubcategory(db.Model):
    """Category - Subcategory."""

    category_id = db.Column(
        db.Integer,
        db.ForeignKey('category.id', ondelete='CASCADE'),
        primary_key=True,
    )
    subcategory_id = db.Column(
        db.Integer,
        db.ForeignKey('subcategory.id', ondelete='CASCADE'),
        primary_key=True,
    )
Example #14
0
class ReceiptSubcategory(db.Model):
    """Purchase - Subcategory."""

    receipt_id = db.Column(
        db.Integer,
        db.ForeignKey('receipt.id', ondelete='CASCADE'),
        primary_key=True,
    )
    subcategory_id = db.Column(
        db.Integer,
        db.ForeignKey('subcategory.id', ondelete='CASCADE'),
        primary_key=True,
    )
Example #15
0
class Transaction(db.Model):
    __tablename__ = 'transactions'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey(User.id))
    category_id = db.Column(db.Integer, db.ForeignKey(Category.id))
    is_actual = db.Column(db.Boolean, nullable=False)
    value = db.Column(db.DECIMAL(15, 2), nullable=False)
    date = db.Column(db.Date, nullable=False)
    comment = db.Column(db.String(255), nullable=False)

    def __repr__(self):
        return (f"<Transaction: id = {self.id}, value = {self.value},"
                f" date = {self.date}, actual = {self.is_actual}>")
Example #16
0
class PurchaseCategory(db.Model):
    """Purchase - Category."""

    purchase_id = db.Column(
        db.Integer,
        db.ForeignKey('purchase.id', ondelete='CASCADE'),
        primary_key=True,
    )
    category_id = db.Column(
        db.Integer,
        db.ForeignKey('category.id', ondelete='CASCADE'),
        primary_key=True,
    )
Example #17
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    created = db.Column(db.DateTime, nullable=False, default=datetime.now())
    news_id = db.Column(db.Integer,
                        db.ForeignKey('news.id', ondelete='CASCADE'),
                        index=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        index=True)
    # связи для удоброно обращения к моделям из другой модели
    news = relationship('News', backref='comments')
    user = relationship('User', backref='comments')
Example #18
0
class RealtyObject(db.Model):
    __tablename__ = "realty_object"
    id = db.Column(db.Integer, primary_key=True)
    cadastral_number = db.Column(db.String, nullable=False, index=True)
    type_realty = db.Column(db.Integer, db.ForeignKey('type_realty.id'))
    category = db.Column(db.String, db.ForeignKey('categories.id'))
    article = db.Column(db.String, nullable=True)
    current_cadastral_cost = db.Column(db.Float, nullable=True)
    new_cadastral_cost = db.Column(db.Float, nullable=True)
    approved_cadastral_cost = db.Column(db.Float, nullable=True)
    segment = db.Column(db.Integer, nullable=True)
    codervi = db.Column(db.String, nullable=True)
    number_case = db.Column(db.String,
                            db.ForeignKey('case.number_case'),
                            index=True)

    case = relationship('Case', backref='objects')

    @property
    def fcurrent_cadastral_cost(self):
        return locale.format_string("%.2f", (self.current_cadastral_cost),
                                    grouping=True)

    @property
    def fnew_cadastral_cost(self):
        return locale.format_string("%.2f", (self.new_cadastral_cost),
                                    grouping=True)

    @property
    def fapproved_cadastral_cost(self):
        return locale.format_string("%.2f", (self.approved_cadastral_cost),
                                    grouping=True)

    @property
    def percent(self):
        if self.approved_cadastral_cost is not None and self.approved_cadastral_cost > 0:
            return locale.format_string(
                "%.2f", (100 - (self.approved_cadastral_cost /
                                self.current_cadastral_cost * 100)),
                grouping=True)
            #return '{:.2f}'.format(100 - (self.approved_cadastral_cost / self.current_cadastral_cost * 100))
        if self.new_cadastral_cost is not None and self.new_cadastral_cost > 0:
            #return '{:.2f}'.format(100 - (self.new_cadastral_cost / self.current_cadastral_cost * 100))
            return locale.format_string("%.2f", (
                100 -
                (self.new_cadastral_cost / self.current_cadastral_cost * 100)),
                                        grouping=True)
        return '-'

    def __repr__(self):
        return f'<Realty object: {self.cadastral_number} for case {self.number_case}>'
Example #19
0
class Shopping_item(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    list_id = db.Column(db.Integer, db.ForeignKey('shopping_list.id'))
    catalog_id = db.Column(db.Integer, db.ForeignKey('catalog.id'))
    quantity = db.Column(db.Integer)

    catalog = relationship("Catalog", lazy='joined')

    @property
    def name(self):
        return self.catalog.name

    def __repr__(self):
        return '<Shopping item {}>'.format(self.id)
Example #20
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    created = db.Column(db.DateTime, nullable=False, default=datetime.now())
    advert_id = db.Column(db.Integer,
                          db.ForeignKey('advert.id', ondelete='CASCADE'),
                          index=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        index=True)
    advert = relationship("Advert", backref='comments')
    user = relationship("User", backref='comments')

    def __repr__(self):
        return f'<Comment {self.id}>'
Example #21
0
class Purchase_Item(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    purchase_id = db.Column(db.Integer,
                            db.ForeignKey('purchase.id'),
                            nullable=False)
    price_id = db.Column(db.Integer, db.ForeignKey('price.id'), nullable=False)
    quantity = db.Column(db.Float, nullable=False)
    total = db.Column(db.Float)

    price = relationship('Price')

    def __repr__(self):
        return '<{}: {} * {} = {}>'.format(self.price.product.name,
                                           self.price.price, self.quantity,
                                           self.total)
Example #22
0
class Case(db.Model):
    __tablename__ = "case"
    id = db.Column(db.Integer, primary_key=True)
    number_case = db.Column(db.String, unique=True, nullable=False)
    applicant = db.Column(db.String, nullable=False)
    type_applicant = db.Column(db.Integer,
                               db.ForeignKey('type_applicant.id'),
                               default=1)
    appraiser = db.Column(db.String, nullable=True)
    judge = db.Column(db.String, nullable=True)
    status_case = db.Column(db.Integer,
                            db.ForeignKey('status_case.id'),
                            default=1)
    stage = db.Column(db.String, nullable=True)
    comment = db.Column(db.String, nullable=True)
    date_added = db.Column(db.DateTime, nullable=True, default=datetime.now())

    @property
    def fstage(self):
        if self.stage is None:
            return ''
        return self.stage

    @property
    def fcomment(self):
        if self.comment is None:
            return ''
        return self.comment

    def status_case_description(self):
        status = StatusCase.query.filter(
            StatusCase.id == self.status_case).first()
        return status.description

    def count_documents(self):
        return Document.query.filter(
            Document.number_case == self.number_case).count()

    def count_events(self):
        return Event.query.filter(
            Event.number_case == self.number_case).count()

    def count_objects(self):
        return RealtyObject.query.filter(
            RealtyObject.number_case == self.number_case).count()

    def __repr__(self):
        return f'Case: {self.number_case}, id: {self.id}>'
Example #23
0
class Cash_desk(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    shop_id = db.Column(db.Integer, db.ForeignKey('shop.id'), nullable=False)
    fn = db.Column(db.String(16), unique=True, index=True)

    def __repr__(self):
        return '<Cash desk {} ({})>'.format(self.fn, self.shop.query.first())
Example #24
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String, nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.now())
    news_id = db.Column(db.Integer,
                        db.ForeignKey('news.id', ondelete='CASCADE'),
                        index=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        index=True)

    news = relationship('News', backref='comments')
    user = relationship('User', backref='comments')

    def __repr__(self):
        return f'Комментарий {self.id} - {self.text}'
Example #25
0
class Status(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    task = db.Column(db.Integer, db.ForeignKey("task.id"))

    def __repr__(self):
        return f"<Status {self.name}>"
class Account(db.Model):
    """Модель таблицы привязанных аккаунтов Steam.

    Хранит идентификационный номер профиля в БД, идентификационный номер
    профиля на сервисах Steam, логин профиля, логин-токен для входа без пароля,
    sentry-файл для входа без 2FA-кода, ссылку на аватар профиля, никнейм
    профиля, баланс кошелька, валюту кошелька и идентификационный номер
    пользователя, которому принадлежит профиль.
    """

    __tablename__ = "accounts"

    account_id = db.Column(db.Integer, primary_key=True)
    steam_id = db.Column(db.BigInteger, index=True)
    username = db.Column(db.String, index=True, nullable=False)
    login_key = db.Column(db.String, unique=True)
    sentry = db.Column(db.LargeBinary)
    avatar_url = db.Column(db.String)
    nickname = db.Column(db.String)
    wallet_balance = db.Column(db.Integer)
    currency = db.Column(db.String(3))
    user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'))
    items = relationship("Item", cascade="all,delete", backref='accounts',
                         lazy="dynamic")

    def __repr__(self):
        """Определяем формат вывода объекта класса Account."""
        return f"Account {self.username}."
Example #27
0
class Advert(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, nullable=False)
    theme = db.Column(db.String, nullable=True)
    url = db.Column(db.String, unique=True, nullable=False)
    price = db.Column(db.Float, nullable=True)
    published = db.Column(db.DateTime, nullable=False)
    description = db.Column(db.Text, nullable=True)
    address = db.Column(db.Text, nullable=True)
    seller = db.Column(db.String, nullable=True)
    company = db.Column(db.Boolean, nullable=True)
    phone = db.Column(db.Text, nullable=True)
    foto = db.Column(db.Integer, nullable=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        nullable=True,
                        index=True)
    closed = db.Column(db.Boolean, default=False)
    fail_check = db.Column(db.Integer, default=0)

    def comments_count(self):
        return Comment.query.filter(Comment.advert_id == self.id).count()

    def __repr__(self):
        return f'<Advert {self.title} {self.url}>'
Example #28
0
class Event(db.Model):
    __tablename__ = "events"
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.String, nullable=False)
    time = db.Column(db.String, nullable=True)
    comment = db.Column(db.String, nullable=True)
    number_case = db.Column(db.String,
                            db.ForeignKey('case.number_case'),
                            index=True)

    case = relationship('Case', backref='events')

    @property
    def fdate(self):
        return datetime.strptime(self.date, '%Y-%m-%d').strftime('%d.%m.%Y')

    @property
    def ftime(self):
        if self.time is None:
            return ''
        return self.time

    @property
    def fcomment(self):
        if self.comment is None:
            return ''
        return self.comment

    def __repr__(self):
        return f'<Event: {self.date} for case {self.number_case}>'
Example #29
0
class Shopping_list(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    favorit = db.Column(db.Boolean, default=False, nullable=False)
    private = db.Column(db.Boolean, default=True, nullable=False)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    author = relationship("User", lazy="joined")
    items = relationship('Shopping_item',
                         backref='shopping_list',
                         lazy='dynamic')
    access = relationship('List_access')
    date_create = db.Column(db.DateTime, default=datetime.utcnow)
    date_change = db.Column(db.DateTime, default=datetime.utcnow)

    def check_access(self, user_id):
        if self.author_id == user_id:
            return 4
        elif self.private:
            return 0
        else:
            level = self.access.filter_by(user_id=user_id).first()
            if level:
                return level.role
        return 0

    def access_dict(self):
        access_dict = {}
        for access in self.access:
            access_dict[access.user.username] = access.role
        return access_dict

    def __repr__(self):
        return '<Shopping list {}>'.format(self.id)
Example #30
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    login = db.Column(db.String, unique=True, nullable=False)
    password = db.Column(db.String, nullable=False)
    nick = db.Column(db.String)
    first_name = db.Column(db.String)
    last_name = db.Column(db.String)
    middle_name = db.Column(db.String)
    email = db.Column(db.String, unique=True)
    role = db.Column(db.Integer, db.ForeignKey('roles.id'))
    superuser = db.Column(db.Integer)
    photo = db.Column(db.String)

    def set_password(self, password):
        self.password = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password, password)

    @property
    def is_admin(self):
        return self.role == 5  # Администратор

    @property
    def is_lawyer(self):
        return self.role == 3  # Юрист

    @property
    def is_user(self):
        return self.role == 2  # Пользователь

    def __repr__(self):
        return "<Пользователь: {}, ID: {}>".format(self.login, self.id)