mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Add broadcasts to the dashboard
Shows current and previous broadcasts. Does not add a page for viewing an individual broadcast. Broadcasts are split into live and previous. Draft broadcasts are excluded from the dashboard.
This commit is contained in:
@@ -4,7 +4,7 @@ from notifications_utils.broadcast_areas import broadcast_area_libraries
|
||||
from notifications_utils.template import BroadcastPreviewTemplate
|
||||
from orderedset import OrderedSet
|
||||
|
||||
from app.models import JSONModel
|
||||
from app.models import JSONModel, ModelList
|
||||
from app.notify_client.broadcast_message_api_client import (
|
||||
broadcast_message_api_client,
|
||||
)
|
||||
@@ -24,7 +24,6 @@ class BroadcastMessage(JSONModel):
|
||||
'personalisation',
|
||||
'starts_at',
|
||||
'finishes_at',
|
||||
'status',
|
||||
'created_at',
|
||||
'approved_at',
|
||||
'cancelled_at',
|
||||
@@ -57,6 +56,12 @@ class BroadcastMessage(JSONModel):
|
||||
*self._dict['areas']
|
||||
)
|
||||
|
||||
@property
|
||||
def initial_area_names(self):
|
||||
return [
|
||||
area.name for area in self.areas
|
||||
][:10]
|
||||
|
||||
@property
|
||||
def polygons(self):
|
||||
return broadcast_area_libraries.get_polygons_for_areas_lat_long(
|
||||
@@ -72,6 +77,16 @@ class BroadcastMessage(JSONModel):
|
||||
)
|
||||
return BroadcastPreviewTemplate(response['data'])
|
||||
|
||||
@property
|
||||
def status(self):
|
||||
if (
|
||||
self._dict['status']
|
||||
and self._dict['status'] == 'broadcasting'
|
||||
and self.finishes_at < datetime.utcnow().isoformat()
|
||||
):
|
||||
return 'completed'
|
||||
return self._dict['status']
|
||||
|
||||
def add_areas(self, *new_areas):
|
||||
broadcast_message_api_client.update_broadcast_message(
|
||||
broadcast_message_id=self.id,
|
||||
@@ -109,3 +124,14 @@ class BroadcastMessage(JSONModel):
|
||||
broadcast_message_id=self.id,
|
||||
service_id=self.service_id,
|
||||
)
|
||||
|
||||
|
||||
class BroadcastMessages(ModelList):
|
||||
|
||||
model = BroadcastMessage
|
||||
client_method = broadcast_message_api_client.get_broadcast_messages
|
||||
|
||||
def with_status(self, *statuses):
|
||||
return [
|
||||
broadcast for broadcast in self if broadcast.status in statuses
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user