Group uploaded letters by day of printing

Some teams have started uploading quite a lot of letters (in the
hundreds per week). They’re also uploading CSVs of emails. This means
the uploads page ends up quite jumbled.

This is because:
- there’s just a lot of items to scan through
- conceptually it’s a bit odd to have batches of things displayed
  alongside individual things on the same page

So instead we’re going to start grouping together uploaded letters. This
will be by the date on which we ‘start’ printing them, or in other
words the time at which they can no longer be cancelled.

This feels like a natural grouping, and it matches what we know about
people’s mental models of ‘batches’ and ‘runs’ when talking about
printing.

This grouping will be done in the API, so all this commit need to do is:
- be ready to display this new type of pseudo-job
- link to the page that displays all the uploaded letters for a given
  print day
This commit is contained in:
Chris Hill-Scott
2020-05-11 10:52:30 +01:00
parent 2800b0a0c3
commit 34f5417844
9 changed files with 115 additions and 53 deletions

View File

@@ -1,5 +1,6 @@
from datetime import datetime
from datetime import datetime, timedelta
import pytz
from notifications_utils.letter_timings import (
CANCELLABLE_JOB_LETTER_STATUSES,
get_letter_timings,
@@ -15,7 +16,7 @@ from app.models import JSONModel, ModelList
from app.notify_client.job_api_client import job_api_client
from app.notify_client.notification_api_client import notification_api_client
from app.notify_client.service_api_client import service_api_client
from app.utils import set_status_filters
from app.utils import get_letter_printing_statement, set_status_filters
class Job(JSONModel):
@@ -159,6 +160,20 @@ class Job(JSONModel):
return True
@property
def letter_printing_statement(self):
if self.upload_type != 'letter_day':
raise TypeError()
return get_letter_printing_statement(
'created',
# We have to make the time just before 5:30pm because a
# letter uploaded at 5:30pm will be printed the next day
(
utc_string_to_aware_gmt_datetime(self.created_at) - timedelta(minutes=1)
).astimezone(pytz.utc).isoformat(),
long_form=False,
)
@cached_property
def all_notifications(self):
return self.get_notifications(set_status_filters({}))['notifications']