class BasicAttr(object): name_en = db.Column(db.String(200)) name_pt = db.Column(db.String(200)) color = db.Column(db.String(7)) gender_pt = db.Column(db.String(1)) plural_pt = db.Column(db.Boolean()) article_pt = db.Column(db.Boolean()) def name(self): lang = getattr(g, "locale", "en") return title_case(getattr(self, "name_" + lang)) def preposition(self, preposition): if g.locale == "en": return '' else: return get_article(self, preposition) def article(self): if self.article_pt: if self.gender_pt == 'm': return 'o' + ('s' if self.plural_pt else '') else: return 'a' + ('s' if self.plural_pt else '') else: return ''
class Short(db.Model): __tablename__ = 'apps_short' slug = db.Column(db.String(30), unique=True, primary_key=True) long_url = db.Column(db.String(255), unique=True) created = db.Column(db.DateTime, default=datetime.now) clicks = db.Column(db.Integer, default=0) @staticmethod def make_unique_slug(long_url): # Helper to generate random URL string # Thx EJF: https://github.com/ericjohnf/urlshort def id_generator(size=6, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for x in range(size)) # test if it already exists short = Short.query.filter_by(long_url=long_url).first() if short: return short.slug else: while True: new_slug = id_generator() if Short.query.filter_by(slug=new_slug).first() == None: break return new_slug def __repr__(self): return "<ShortURL: '%s'>" % self.long_url
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): keyword_names = [keyword.name for keyword in self.keywords] return ', '.join(keyword_names) def date_str(self): return self.postage_date.strftime('%d/%m/%Y') def __repr__(self): return '<Article %r>' % (self.title)
class Wld(db.Model, AutoSerialize, BasicAttr): __tablename__ = 'attrs_wld' id = db.Column(db.String(5), primary_key=True) id_2char = db.Column(db.String(2)) id_3char = db.Column(db.String(3)) id_num = db.Column(db.Integer(11)) id_mdic = db.Column(db.Integer(11)) ymw = db.relationship("Ymw", backref='wld', lazy='dynamic') ympw = db.relationship("Ympw", backref='wld', lazy='dynamic') ymbw = db.relationship("Ymbw", backref='wld', lazy='dynamic') ymbpw = db.relationship("Ymbpw", backref='wld', lazy='dynamic') def icon(self): if self.id == "all": 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)
class University(db.Model, AutoSerialize, ExpandedAttr): __tablename__ = 'attrs_university' id = db.Column(db.String(8), primary_key=True) school_type_id = db.Column(db.String(1)) school_type_en = db.Column(db.String(32)) school_type_pt = db.Column(db.String(32)) yu = db.relationship("Yu", backref='university', lazy='dynamic') yuc = db.relationship("Yuc", backref='university', lazy='dynamic') ybu = db.relationship("Ybu", backref='university', lazy='dynamic') ybuc = db.relationship("Ybuc", backref='university', lazy='dynamic') def icon(self): return "/static/img/icons/university/university_{}.png".format( self.school_type_id.lower()) def school_type(self): lang = getattr(g, "locale", "en") return getattr(self, "school_type_" + lang) def url(self): return "/profiles/university/{}/".format(self.id) def __repr__(self): return '<University %r>' % (self.name_en)
class Crosswalk_pi(db.Model): __tablename__ = 'crosswalk_pi' hs_id = db.Column(db.String(6), primary_key=True) cnae_id = db.Column(db.String(5), primary_key=True) def get_id(self, dataset): if dataset == "rais": return self.hs_id return self.cnae_id
class Starred(db.Model, AutoSerialize): __tablename__ = 'account_starred' app_id = db.Column(db.String(80), primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey(User.id), primary_key=True) app_name = db.Column(db.String(255)) timestamp = db.Column(db.DateTime) def __repr__(self): return '<App %r starred by %r>' % (self.app_id, self.user.nickname)
class Crosswalk_oc(db.Model): __tablename__ = 'crosswalk_oc' cbo_id = db.Column(db.String(4), db.ForeignKey(Cbo.id), primary_key = True) course_hedu_id = db.Column(db.String(6), db.ForeignKey(Course_hedu.id), primary_key = True) def get_id(self, dataset): if dataset == "rais": return self.course_hedu_id return self.cbo_id
class Ybi_reqs(db.Model, AutoSerialize): __tablename__ = 'rais_ybi_required' year = db.Column(db.Integer(4), primary_key=True) bra_id = db.Column(db.String(8), db.ForeignKey(Bra.id), primary_key=True) cnae_id = db.Column(db.String(5), db.ForeignKey(Cnae.id), primary_key=True) required_bras = db.Column(db.String(255)) def __repr__(self): return '<Ybi_reqs %d.%s.%s>' % (self.year, self.bra_id, self.cnae_id)
class BasicAttr(object): name_en = db.Column(db.String(200)) name_pt = db.Column(db.String(200)) color = db.Column(db.String(7)) gender_pt = db.Column(db.String(1)) plural_pt = db.Column(db.Boolean()) article_pt = db.Column(db.Boolean()) def name(self): lang = getattr(g, "locale", "en") return title_case(getattr(self, "name_" + lang))
class Bs(db.Model, AutoSerialize): __tablename__ = 'attrs_bs' bra_id = db.Column(db.String(10), db.ForeignKey(Bra.id), primary_key=True) stat_id = db.Column(db.String(20), db.ForeignKey(Stat.id), primary_key=True) stat_val = db.Column(db.String(40)) def __repr__(self): return "<Bs {}.{}>".format(self.bra_id, self.stat_id)
class Ybc_hedu(Hedu): __tablename__ = 'hedu_ybc' year = db.Column(db.Integer(4), primary_key=True) bra_id = db.Column(db.String(9), db.ForeignKey(Bra.id), primary_key=True) course_hedu_id = db.Column(db.String(6), db.ForeignKey(Course_hedu.id), primary_key=True) bra_id_len = db.Column(db.Integer(1)) course_hedu_id_len = db.Column(db.Integer(1)) def __repr__(self): return '<Ybc {}.{}.{}>'.format(self.year, self.bra_id, self.course_hedu_id)
class Ybs(db.Model, AutoSerialize): __tablename__ = 'attrs_ybs' year = db.Column(db.Integer(4), primary_key=True) bra_id = db.Column(db.String(10), db.ForeignKey(Bra.id), primary_key=True) stat_id = db.Column(db.String(20), db.ForeignKey(Stat.id), primary_key=True) stat_val = db.Column(db.Float) def __repr__(self): return "<Ybs {}.{}.{}>".format(self.year, self.bra_id, self.stat_id)
class SearchSelector(db.Model): __tablename__ = 'search_selector' id = db.Column(db.String(50), primary_key=True) name_pt = db.Column(db.String(50)) name_en = db.Column(db.String(50)) def name(self): lang = getattr(g, "locale", "en") return title_case(getattr(self, "name_" + lang)) def __repr__(self): return '<SearchSelector %r>' % (self.name)
class HelpSubject(db.Model): __tablename__ = 'help_subject' id = db.Column(db.Integer, primary_key=True) name_en = db.Column(db.String(50)) name_pt = db.Column(db.String(50)) def name(self): lang = getattr(g, "locale", "en") return title_case(getattr(self, "name_" + lang)) def __repr__(self): return '<Subject %r>' % (self.name())
class Ybo(BaseRais, db.Model, AutoSerialize): __tablename__ = 'rais_ybo' year = db.Column(db.Integer(4), primary_key=True) bra_id = db.Column(db.String(8), db.ForeignKey(Bra.id), primary_key=True) cbo_id = db.Column(db.String(6), db.ForeignKey(Cbo.id), primary_key=True) bra_id_len = db.Column(db.Integer(1)) cbo_id_len = db.Column(db.Integer(1)) def __repr__(self): return '<Ybo %d.%s.%s>' % (self.year, self.bra_id, self.cbo_id)
class Yio(BaseRais, db.Model, AutoSerialize): __tablename__ = 'rais_yio' cnae_id = db.Column(db.String(5), db.ForeignKey(Cnae.id), primary_key=True) cbo_id = db.Column(db.String(6), db.ForeignKey(Cbo.id), primary_key=True) importance = db.Column(db.Float()) cnae_id_len = db.Column(db.Integer(1)) cbo_id_len = db.Column(db.Integer(1)) def __repr__(self): return '<Yio %d.%s.%s>' % (self.year, self.cnae_id, self.cbo_id)
class Ybu(Hedu): __tablename__ = 'hedu_ybu' year = db.Column(db.Integer(4), primary_key=True) bra_id = db.Column(db.String(9), db.ForeignKey(Bra.id), primary_key=True) university_id = db.Column(db.String(5), db.ForeignKey(University.id), primary_key=True) bra_id_len = db.Column(db.Integer(1)) def __repr__(self): return '<Ybu {}.{}.{}>'.format(self.year, self.bra_id, self.university_id)
class PublicationSubject(db.Model): __tablename__ = 'news_subject' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) language = db.Column(db.String(2)) def __init__(self, name=None, language=None): self.name = name self.language = language def __repr__(self): return '<PublicationSubject %r (%r)>' % (self.name, self.language)
class Ypp(db.Model, AutoSerialize): __tablename__ = 'attrs_ypp' year = db.Column(db.Integer(4), primary_key=True) hs_id = db.Column(db.String(8), db.ForeignKey(Hs.id), primary_key=True) hs_id_target = db.Column(db.String(8), db.ForeignKey(Hs.id), primary_key=True) prox_bra = db.Column(db.Float) def __repr__(self): return "<Ypp {}.{}.{}>".format(self.year, self.hs_id, self.hs_id_target)
class Yoo(db.Model, AutoSerialize): __tablename__ = 'attrs_yoo' year = db.Column(db.Integer(4), primary_key=True) cbo_id = db.Column(db.String(6), db.ForeignKey(Cbo.id), primary_key=True) cbo_id_target = db.Column(db.String(6), db.ForeignKey(Cbo.id), primary_key=True) prox_bra = db.Column(db.Float) def __repr__(self): return "<Yoo {}.{}.{}>".format(self.year, self.cbo_id, self.cbo_id_target)
class SearchProfile(db.Model): __tablename__ = 'search_profile' id = db.Column(db.String(50), primary_key=True) name_pt = db.Column(db.String(50)) name_en = db.Column(db.String(50)) questions = db.relationship("SearchQuestion", backref='search_question') def name(self): lang = getattr(g, "locale", "en") return title_case(getattr(self, "name_" + lang)) def __repr__(self): return '<SearchProfile %r>' % (self.name)
class Yww(db.Model, AutoSerialize): __tablename__ = 'attrs_yww' year = db.Column(db.Integer(4), primary_key=True) wld_id = db.Column(db.String(5), db.ForeignKey(Wld.id), primary_key=True) wld_id_target = db.Column(db.String(5), db.ForeignKey(Wld.id), primary_key=True) prox_bra = db.Column(db.Float) def __repr__(self): return "<Yww {}.{}.{}>".format(self.year, self.wld_id, self.wld_id_target)
class Ysc(Sc): __tablename__ = 'sc_ysc' school_id = db.Column(db.String(8), primary_key=True) course_sc_id = db.Column(db.String(5), db.ForeignKey(Course_sc.id), primary_key=True) course_sc_id_len = db.Column(db.Integer(1)) def __repr__(self): return '<Ysc %d.%s.%s>' % (self.year, self.school_id)
class Ybc_sc(Sc): __tablename__ = 'sc_ybc' bra_id = db.Column(db.String(9), db.ForeignKey(Bra.id), primary_key=True) course_sc_id = db.Column(db.String(5), db.ForeignKey(Course_sc.id), primary_key=True) bra_id_len = db.Column(db.Integer(1)) course_sc_id_len = db.Column(db.Integer(1)) def __repr__(self): return '<Ybc %d.%s.%s>' % (self.year, self.bra_id, self.course_sc_id)
class Ybs(Sc): __tablename__ = 'sc_ybs' bra_id = db.Column(db.String(9), db.ForeignKey(Bra.id), primary_key=True) school_id = db.Column(db.String(8), db.ForeignKey(School.id), primary_key=True) bra_id_len = db.Column(db.Integer(1)) def __repr__(self): return '<Ybs %d.%s.%s>' % (self.year, self.bra_id, self.school_id)
class Form(db.Model): __tablename__ = 'contact_message' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) email = db.Column(db.String(100)) subject = db.Column(db.String(200)) message = db.Column(db.Text()) postage_date = db.Column(db.DateTime) def date_str(self): return self.postage_date.strftime('%d/%m/%Y') def __repr__(self): return '<Form %r>' % (self.name)
class Ypw(db.Model, AutoSerialize): __tablename__ = 'secex_ypw' year = db.Column(db.Integer(4), primary_key=True) hs_id = db.Column(db.String(6), db.ForeignKey(Hs.id), primary_key=True) wld_id = db.Column(db.String(5), db.ForeignKey(Wld.id), primary_key=True) val_usd = db.Column(db.Numeric(16, 2)) val_usd_growth_pct = db.Column(db.Float()) val_usd_growth_pct_5 = db.Column(db.Float()) val_usd_growth_val = db.Column(db.Numeric(16, 2)) val_usd_growth_val_5 = db.Column(db.Numeric(16, 2)) def __repr__(self): return '<Ypw %d.%s.%s>' % (self.year, self.hs_id, self.wld_id)
class Tag(db.Model): __tablename__ = 'ask_tag' id = db.Column(db.Integer, primary_key=True) attr_type = db.Column(db.String(20)) attr_id = db.Column(db.String(12)) def __repr__(self): return '<%r: %r>' % (self.attr_type, self.attr_id) def to_attr(self): attr = getattr(attr_models, self.attr_type.title()) attr = attr.query.get(self.attr_id) return attr
class SearchQuestion(db.Model): __tablename__ = 'search_question' id = db.Column(db.Integer, primary_key=True) description_pt = db.Column(db.String(400)) description_en = db.Column(db.String(400)) answer = db.Column(db.String(400)) profile_id = db.Column(db.String(50), ForeignKey('search_profile.id')) selectors = db.Column(db.String(400)) def description(self): lang = getattr(g, "locale", "en") return getattr(self, "description_" + lang) def __repr__(self): return '<SearchQuestion %r>' % (self.description())