Generating the UUID can be can be contained within this function,
thus any other part of the code using it doesn’t have to do the
ID-generating stuff itself.
There shouldn’t be a case where we see a `ValueError` on upload any
more. Our file handling should be robust enough to deal with whatever is
thrown at it.
This commit:
- adds test files with bad data (PNG files with their extensions changed to look
like spreadsheets)
- catches whatever exceptions are raised by trying to parse these files
- returns a helpful flash message to the user
Anything else should raise a `500`, eg if the file can’t be uploaded to S3.
We require users to export their spreadsheets as CSV files before
uploading them. But this seems like the sort of thing a computer should
be able to do.
So this commit adds a wrapper class which:
- takes a the uploaded file
- returns it in a normalised format, or reads it using pyexcel[1]
- gives the data back in CSV format
This allows us to accept `.csv`, `.xlsx`, `.xls` (97 and 95), `.ods`,
`.xlsm` and `.tsv` files. We can upload the resultant CSV just like
normal, and process it for errors as before.
Testing
---
To test this I’ve added a selection of common spreadsheet files as test
data. They all contain the same data, so the tests look to see that the
resultant CSV output is the same for each.
UI changes
---
This commit doesn’t change the UI, apart from to give a different error
message if a user uploads a file type that we still don’t understand.
I intend to do this as a separate pull request, in order to fulfil
https://www.pivotaltracker.com/story/show/119371637
The dashboard looked a bit table-y. This commit makes four main changes:
- show a bar chart (drawn in CSS) for template usage (only shown if
you’ve used more than one template recently)
- only break down template usage by template name, not template type
(because that’s happening with the big numbers)
- change the style of the ‘show more’ links under each section so that
they are all consistent, and a little less busy (one less keyline)
- remove the ‘recent templates‘ title so that the first two sections of
the page group under ‘in the last 7 days’
This commit does two main things:
- adds textboxes to the send yourself a test page, so you can replace
((name)) with ‘Chris’, or whatever your name is
- rejigs the send page a bit to make it clearer what the CSV upload is
for and how to use it
The idea being that, since most users go into ‘send yourself a test’
first, it teaches them about how placeholders work by making them do the
replacing themselves.
When previewing a template on the send page, having the recipient appear
as a placeholder should help reinforce the relationship between the
columns in the CSV and the placeholders.
Then, when previewing a message, having the template populated with the
first recipient’s email address/phone number should reinforce that
relationship again.
Takes the number of emails and SMS fragments sent from:
https://github.com/alphagov/notifications-api/pull/273
Using these numbers it’s possible to show:
- how much of your allowance is left
- or how much you have spent
For now the allowance and rates are hard coded.
Only for users that have manage service.
If they API returns no statistics for a given time period we should
assume that this is equivalent to 0. This means that the template can
always rely on the dictionary having the same keys.
We were getting some weirdness like ‘Failed both’.
This commit fixes the problem, and adds some tests for the page headings
to make sure they don’t break again.
Requested, delivered and failed are the three states stored in the
notification statistics table. They are not discrete, eg a message can
be counted in delivered and failed.
`requested` is incremented *when a notification is created*, and has no
chance of being incremented twice for the same notification.
The template statistics are incremented *when a notification is created
only*.
Therefore the only way to make the numbers line up is to count:
- messages sent as being `requested`
- failure rate being `failed`/`requested` *not*
`failed`/`failed`+`delivered`
The dashboard should only talk about notifications that are *successful* or
*failed*. It should not count notifications that are still queued.
This will stop:
- a situation like ‘0 emails, 14.1% failed’
- the big numbers and the template statistics numbers not adding up to
the same total