Let users choose when to end a broadcast

Different emergencies will need broadcasts to last for a variable amount
of time. We give users some control over this by letting them stop a
broadcast early. But we should also let them set a maximum broadcast
time, for:
- when the duration of the danger is known
- when the broadcast has been live long enough to alert everyone who
  needs to know about it

This code re-uses the pattern for scheduling jobs, which has some
constraints that are probably OK for now:
- end time is limited to an hour
- longest duration is 3 whole days (eg if you start broadcasting Friday
  you have the choice of Saturday, Sunday and all of Monday, up to
  midnight)
This commit is contained in:
Chris Hill-Scott
2020-07-16 10:49:21 +01:00
parent ca292037e7
commit 83156bd16e
9 changed files with 187 additions and 55 deletions

View File

@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime
from notifications_utils.broadcast_areas import broadcast_area_libraries
from notifications_utils.template import BroadcastPreviewTemplate
@@ -33,7 +33,6 @@ class BroadcastMessage(JSONModel):
'approved_by_id',
'cancelled_by_id',
}
DEFAULT_TTL = timedelta(hours=72)
libraries = broadcast_area_libraries
@@ -132,9 +131,9 @@ class BroadcastMessage(JSONModel):
data=kwargs,
)
def request_approval(self):
def request_approval(self, until):
self._update(
finishes_at=(datetime.utcnow() + self.DEFAULT_TTL).isoformat(),
finishes_at=until,
)
self._set_status_to('pending-approval')