refactor: representatives separated from core
This commit is contained in:
parent
3faa1689e7
commit
d33757e754
|
@ -6,11 +6,7 @@ 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
|
||||
import app.model as models
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.sql.expression import func
|
||||
|
||||
|
@ -19,26 +15,24 @@ class Core(Controller):
|
|||
def home(self):
|
||||
random.seed(int(datetime.today().timestamp()/100))
|
||||
try:
|
||||
g.motd = random.choice(MatterModel.query.filter_by(
|
||||
g.motd = random.choice(models.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(
|
||||
try:
|
||||
g.rotd = random.choice(models.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")
|
||||
).all())
|
||||
except:
|
||||
g.rotd = None
|
||||
g.last_decisions = models.DecisionModel.query.join(
|
||||
models.DecisionModel.recommendation
|
||||
).order_by(models.RecommendationModel.date.desc()).limit(10).all()
|
||||
g.last_stances = models.StanceModel.query.order_by(
|
||||
models.StanceModel.date.desc()
|
||||
).limit(10).all()
|
||||
return render_template("core/home.html")
|
||||
|
||||
def about(self):
|
||||
return render_template("core/about.html")
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# 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")
|
||||
|
|
@ -5,6 +5,7 @@ from app.controller.admin import admin_routes
|
|||
from app.controller.api.country import CountriesApi, CountryApi
|
||||
from app.controller.api.representative import RepresentativesApi, RepresentativeApi
|
||||
from app.controller.core import Core
|
||||
from app.controller.representative import Representative
|
||||
|
||||
|
||||
# Adding admin endpoints
|
||||
|
@ -14,7 +15,7 @@ for route in admin_routes:
|
|||
# Listing normal endpoints
|
||||
routes = [
|
||||
("/", Core.as_view("home")),
|
||||
("/representative/<int:representative_id>", Core.as_view("representative")),
|
||||
("/representative/<int:representative_id>", Representative.as_view("view")),
|
||||
("/about", Core.as_view("about")),
|
||||
("/who", Core.as_view("who")),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue