mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-24 01:11:15 -04:00
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:
@@ -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)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from operator import attrgetter
|
||||
|
||||
from flask import Markup, abort, current_app
|
||||
from notifications_utils.field import Field
|
||||
from notifications_utils.formatters import nl2br
|
||||
@@ -7,7 +5,6 @@ from notifications_utils.take import Take
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.models import JSONModel
|
||||
from app.models.event import APIKeyEvents, ServiceEvents
|
||||
from app.models.organisation import Organisation
|
||||
from app.models.user import InvitedUsers, User, Users
|
||||
from app.notify_client.api_key_api_client import api_key_api_client
|
||||
@@ -634,10 +631,3 @@ class Service(JSONModel):
|
||||
):
|
||||
if test:
|
||||
yield BASE + '_incomplete' + tag
|
||||
|
||||
@property
|
||||
def history(self):
|
||||
return sorted(
|
||||
ServiceEvents(self.id) + APIKeyEvents(self.id),
|
||||
key=attrgetter('time'),
|
||||
)
|
||||
|
||||
@@ -44,9 +44,9 @@ def test_history(
|
||||
'10 October',
|
||||
(
|
||||
'6ce466d0-fd6a-11e5-82f5-e0accb9d11a6 11:10am '
|
||||
'Created an API key called ‘Good key’ '
|
||||
'Created this service and called it ‘Example service’ '
|
||||
'6ce466d0-fd6a-11e5-82f5-e0accb9d11a6 11:10am '
|
||||
'Created this service and called it ‘Example service’'
|
||||
'Created an API key called ‘Good key’'
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user