politikorama/app/controller/representative.py

26 lines
798 B
Python

# encoding: utf-8
from datetime import datetime
import random
from flask import g, redirect, render_template, url_for
from app.controller.controller import Controller
import app.model as models
from sqlalchemy import desc
from sqlalchemy.sql.expression import func
class Representative(Controller):
def view(self, representative_id=None):
if representative_id is None:
representative_id = random.choice(
models.RepresentativeModel.query.filter_by(active=True).all()
).id
g.representative = models.RepresentativeModel.query.get(representative_id)
if g.representative is None:
return redirect(url_for("core.home"))
g.title = g.representative.name
return render_template("representative/view.html")