Skip to content

Commit ff5afdd

Browse files
committed
Display information about prepub sync status on the Admin dashboard
The styles here are very rudimentary, and will probably need some fixing up before we'd want this to go live.
1 parent 34dd1d8 commit ff5afdd

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

dashboard/templates/dashboard/shortcuts_panel.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,24 @@
2727
{% endwith %}
2828
</ul>
2929
</section>
30+
{% if prepub_sync_completed_at %}
31+
<section class="panel nice-padding" style="font-size: 1.5em; line-height: 1.6">
32+
<p><strong>Prepublication Incidents Sync</strong>
33+
<br>
34+
Completed at: {{ prepub_sync_completed_at|date:"SHORT_DATETIME_FORMAT" }}
35+
{% if not prepub_sync_extended_message %}
36+
<br>
37+
{{ prepub_sync_message }}
38+
{% endif %}
39+
</p>
40+
{% if prepub_sync_extended_message %}
41+
<p>
42+
Sync did not succeed.
43+
</p>
44+
<details>
45+
<summary>Details</summary>
46+
{{ prepub_sync_message }}
47+
</details>
48+
{% endif %}
49+
</section>
50+
{% endif %}

dashboard/tests/test_dashboard.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
from wagtail import hooks
2-
31
from django.urls import reverse
4-
from wagtail.test.utils import WagtailPageTestCase
2+
3+
from wagtail import hooks
54
from wagtail.models import Page, Site
5+
from wagtail.test.utils import WagtailPageTestCase
66

77
from common.models.settings import (
88
SearchSettings,
99
)
10+
from dashboard.wagtail_hooks import add_shortcuts_panel
11+
from incident.models import PrepublicationIncidentSync
1012
from incident.tests.factories import (
1113
IncidentIndexPageFactory,
1214
)
13-
from dashboard.wagtail_hooks import add_shortcuts_panel
1415

1516

1617
class ShortcutsPanelTest(WagtailPageTestCase):
@@ -37,3 +38,21 @@ def test_image_shortcut(self):
3738
def test_incident_shortcut(self):
3839
response = self.client.get(reverse('wagtailadmin_home'))
3940
self.assertContains(response, 'Add a new incident')
41+
42+
@hooks.register_temporarily('construct_homepage_panels', add_shortcuts_panel)
43+
def test_prepublication_status(self):
44+
prepub_sync = PrepublicationIncidentSync.objects.create(
45+
status=PrepublicationIncidentSync.Status.SUCCESS,
46+
message='3 incidents retrieved.',
47+
)
48+
response = self.client.get(reverse('wagtailadmin_home'))
49+
self.assertContains(response, '3 incidents retrieved.')
50+
51+
@hooks.register_temporarily('construct_homepage_panels', add_shortcuts_panel)
52+
def test_prepublication_sync_failed_message(self):
53+
prepub_sync = PrepublicationIncidentSync.objects.create(
54+
status=PrepublicationIncidentSync.Status.INVALID_DATA,
55+
message='Row 3: Invalid date Jan 13, 2010',
56+
)
57+
response = self.client.get(reverse('wagtailadmin_home'))
58+
self.assertContains(response, 'Sync did not succeed')

dashboard/wagtail_hooks.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
from wagtail import hooks
22
from wagtail.admin.ui.components import Component
33

4+
from incident.models import PrepublicationIncidentSync
5+
46

57
class ShortcutsPanel(Component):
68
# This is an ordering number that is the minimum multiple of 10 to place
79
# this panel underneath the built-in Wagtail panels.
810
order = 100
911
template_name = 'dashboard/shortcuts_panel.html'
1012

13+
def get_context_data(self, parent_context):
14+
context = super().get_context_data(parent_context)
15+
prepub_sync = PrepublicationIncidentSync.objects.first()
16+
if prepub_sync:
17+
context['prepub_sync_completed_at'] = prepub_sync.completed_at
18+
context['prepub_sync_message'] = prepub_sync.message
19+
if prepub_sync.status == PrepublicationIncidentSync.Status.SUCCESS:
20+
context['prepub_sync_extended_message'] = False
21+
else:
22+
context['prepub_sync_extended_message'] = True
23+
return context
24+
1125

1226
@hooks.register('construct_homepage_panels')
1327
def add_shortcuts_panel(request, panels):

0 commit comments

Comments
 (0)