Ejemplo n.º 1
0
import re
from flask import g
from unicodedata import normalize
from sqlalchemy import and_
from sqlalchemy.dialects import mysql
from dataviva import db, app
from dataviva.utils.auto_serialize import AutoSerialize

from dataviva.account.models import User
from dataviva.attrs import models as attr_models

TYPE_QUESTION = 0
TYPE_REPLY = 1

question_tags = db.Table('ask_question_tags',
    db.Column('tag_id', db.Integer, db.ForeignKey('ask_tag.id')),
    db.Column('question_id', db.Integer, db.ForeignKey('ask_question.id'))
)


class Vote(db.Model):

    __tablename__ = 'ask_vote'
    type = db.Column(db.SmallInteger, primary_key = True, default=TYPE_QUESTION)
    type_id = db.Column(db.Integer, primary_key = True)
    user_id = db.Column(db.Integer, db.ForeignKey(User.id), primary_key = True)

    def __repr__(self):
        return '<Vote %r:%r by:%r>' % (self.type, self.type_id, self.user_id)

class Question(db.Model, AutoSerialize):
Ejemplo n.º 2
0
            return "/static/img/icons/wld/wld_sabra.png"
        else:
            return "/static/img/icons/wld/wld_%s.png" % (self.id)

    def url(self):
        if self.id == "sabra":
            return "/profiles/bra/all/"
        else:
            return "/profiles/wld/{}/".format(self.id)

    def __repr__(self):
        return '<Wld %r>' % (self.id_3char)


bra_pr = db.Table(
    'attrs_bra_pr',
    db.Column('bra_id', db.Integer, db.ForeignKey('attrs_bra.id')),
    db.Column('pr_id', db.Integer, db.ForeignKey('attrs_bra.id')))


class Bra(db.Model, AutoSerialize, BasicAttr):

    __tablename__ = 'attrs_bra'
    id = db.Column(db.String(10), primary_key=True)
    id_ibge = db.Column(db.Integer(7))

    distance = 0

    # SECEX relations
    ymb = db.relationship("Ymb", backref='bra', lazy='dynamic')
    ymbp = db.relationship("Ymbp", backref='bra', lazy='dynamic')
    ymbw = db.relationship("Ymbw", backref='bra', lazy='dynamic')
Ejemplo n.º 3
0
from dataviva import db
from sqlalchemy import ForeignKey

article_keyword_table = db.Table(
    'scholar_article_keyword',
    db.Column('article_id', db.Integer(), db.ForeignKey('scholar_article.id')),
    db.Column('keyword_id', db.Integer(), db.ForeignKey('scholar_keyword.id')))


class Article(db.Model):
    __tablename__ = 'scholar_article'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(400))
    abstract = db.Column(db.Text())
    file_url = db.Column(db.String(400))
    theme = db.Column(db.String(250))
    postage_date = db.Column(db.DateTime)
    approval_status = db.Column(db.Boolean)
    authors = db.relationship('AuthorScholar',
                              backref='scholar_article',
                              lazy='eager',
                              cascade='all, delete-orphan')
    keywords = db.relationship('KeyWord',
                               secondary=article_keyword_table,
                               backref=db.backref('articles', lazy='dynamic'))

    def authors_str(self):
        author_names = [author.name for author in self.authors]
        return ', '.join(author_names)

    def keywords_str(self):
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-
from flask import g
from dataviva import db, __latest_year__
from dataviva.utils.auto_serialize import AutoSerialize
from dataviva.utils.title_case import title_case
from dataviva.attrs.models import Bra, Isic, Hs, Cbo, Wld

import ast, re

build_ui = db.Table(
    'apps_build_ui',
    db.Column('build_id', db.Integer, db.ForeignKey('apps_build.id')),
    db.Column('ui_id', db.Integer, db.ForeignKey('apps_ui.id')))


class App(db.Model, AutoSerialize):

    __tablename__ = 'apps_app'

    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.String(20))
    name_en = db.Column(db.String(20))
    name_pt = db.Column(db.String(20))
    viz_whiz = db.Column(db.String(20))
    color = db.Column(db.String(7))

    def name(self):
        lang = getattr(g, "locale", "en")
        return getattr(self, "name_" + lang)

    def serialize(self, **kwargs):
Ejemplo n.º 5
0
from sqlalchemy import ForeignKey, Table, Column
from dataviva import db

association_table = db.Table(
    'news_publication_subject',
    db.Column('publication_id', db.Integer,
              db.ForeignKey('news_publication.id')),
    db.Column('subject_id', db.Integer, db.ForeignKey('news_subject.id')))


class Publication(db.Model):
    # TODO - Alter publication.thumb column to db.Column(db.String(400))
    __tablename__ = 'news_publication'
    __searchable__ = ['title', 'author', 'main_subject', 'text_call']

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(400))
    author = db.Column(db.String(100))
    text_call = db.Column(db.String(500))
    text_content = db.Column(db.Text(4194304))
    thumb = db.Column(db.Text(4194304))
    thumb_src = db.Column(db.String(400))
    publish_date = db.Column(db.DateTime)
    last_modification = db.Column(db.DateTime)
    active = db.Column(db.Boolean)
    show_home = db.Column(db.Boolean)
    language = db.Column(db.String(2))
    main_subject = db.Column(db.String(50))

    subjects = db.relationship("PublicationSubject",
                               secondary=association_table,
Ejemplo n.º 6
0
from sqlalchemy import ForeignKey, Table, Column
from sqlalchemy.ext.declarative import declarative_base 
from dataviva import db


association_table = db.Table('blog_post_subject',
    db.Column('post_id', db.Integer, db.ForeignKey('blog_post.id')),
    db.Column('subject_id', db.Integer, db.ForeignKey('blog_subject.id'))
)

class Post(db.Model):
    __tablename__ = 'blog_post'
    __searchable__ = ['title', 'author', 'main_subject', 'text_call']

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(400))
    author = db.Column(db.String(100))
    text_call = db.Column(db.String(500))
    text_content = db.Column(db.Text(4194304))
    thumb = db.Column(db.Text(4194304))
    thumb_src = db.Column(db.String(400))
    publish_date = db.Column(db.DateTime)
    last_modification = db.Column(db.DateTime)
    active = db.Column(db.Boolean)
    show_home = db.Column(db.Boolean)
    language = db.Column(db.String(2))
    main_subject = db.Column(db.String(50))

    subjects = db.relationship(
        "Subject",
        secondary=association_table,