# encoding: utf-8 from datetime import datetime import random from flask import g, render_template from app.controller.controller import Controller from app.model.decision import DecisionModel from app.model.matter import MatterModel from app.model.recommendation import RecommendationModel from app.model.representative import RepresentativeModel from app.model.stance import StanceModel from sqlalchemy import desc from sqlalchemy.sql.expression import func class Core(Controller): def home(self): random.seed(int(datetime.today().timestamp()/100)) try: g.motd = random.choice(MatterModel.query.filter_by( active=True ).all()) except: g.motd = None g.rotd = random.choice(RepresentativeModel.query.filter_by( active=True ).all()) g.last_decisions = DecisionModel.query.join(DecisionModel.recommendation).order_by(RecommendationModel.date.desc()).limit(10).all() g.last_stances = StanceModel.query.order_by(StanceModel.date.desc()).limit(10).all() return render_template("core/home.html") def representative(self, representative_id=None): if representative_id is None: representative_id = random.choice(RepresentativeModel.query.filter_by( active=True ).all()).id g.representative = RepresentativeModel.query.get(representative_id) g.title = g.representative.name return render_template("core/representative.html") def about(self): return render_template("core/about.html") def who(self): return render_template("core/who.html")