Refactor history off the service model

Directly referencing the `ModelList` instances will let us more easily
make choices at the view layer about which kinds of events to show, and
is one less layer of indirection to jump through.
This commit is contained in:
Chris Hill-Scott
2019-10-21 12:14:41 +01:00
parent b2ebaf153a
commit d93ebd99d3
3 changed files with 10 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ from flask import render_template
from app import current_service, format_date_numeric
from app.main import main
from app.models.event import APIKeyEvents, ServiceEvents
from app.utils import user_has_permissions
@@ -12,10 +13,16 @@ from app.utils import user_has_permissions
def history(service_id):
return render_template(
'views/temp-history.html',
days=_chunk_events_by_day(current_service.history)
days=_chunk_events_by_day(
_get_events(current_service.id)
)
)
def _get_events(service_id):
return APIKeyEvents(service_id) + ServiceEvents(service_id)
def _chunk_events_by_day(events):
days = defaultdict(list)