diff --git a/app/main/forms.py b/app/main/forms.py index afec80f9f..90a4409fc 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -50,6 +50,7 @@ from app.main.validators import ( CommonlyUsedPassword, CsvFileValidator, DoesNotStartWithDoubleZero, + FieldCannotContainComma, LettersNumbersSingleQuotesFullStopsAndUnderscoresOnly, MustContainAlphanumericCharacters, NoCommasInPlaceHolders, @@ -1650,7 +1651,11 @@ def get_placeholder_form_instance( ) # TODO: replace with us_mobile_number else: field = GovukTextInputField( - placeholder_name, validators=[DataRequired(message="Cannot be empty")] + placeholder_name, + validators=[ + DataRequired(message="Cannot be empty"), + FieldCannotContainComma(), + ], ) PlaceholderForm.placeholder_value = field diff --git a/app/main/validators.py b/app/main/validators.py index 4dd04017b..1dfc97c48 100644 --- a/app/main/validators.py +++ b/app/main/validators.py @@ -161,6 +161,15 @@ class DoesNotStartWithDoubleZero: raise ValidationError(self.message) +class FieldCannotContainComma: + def __init__(self, message="Cannot contain a comma"): + self.message = message + + def __call__(self, form, field): + if field.data and "," in field.data: + raise ValidationError(self.message) + + class MustContainAlphanumericCharacters: regex = re.compile(r".*[a-zA-Z0-9].*[a-zA-Z0-9].*") diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 4c70b85fd..4966c0300 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -1,5 +1,4 @@ import calendar -from collections import defaultdict from datetime import datetime from functools import partial from itertools import groupby @@ -13,7 +12,6 @@ from app import ( billing_api_client, current_service, job_api_client, - notification_api_client, service_api_client, socketio, template_statistics_client, @@ -83,18 +81,9 @@ def service_dashboard(service_id): return redirect(url_for("main.choose_template", service_id=service_id)) job_response = job_api_client.get_jobs(service_id)["data"] - notifications_response = notification_api_client.get_notifications_for_service( - service_id - )["notifications"] service_data_retention_days = 7 - aggregate_notifications_by_job = defaultdict(list) - for notification in notifications_response: - job_id = notification.get("job", {}).get("id", None) - if job_id: - aggregate_notifications_by_job[job_id].append(notification) - - job_and_notifications = [ + jobs = [ { "job_id": job["id"], "time_left": get_time_left(job["created_at"]), @@ -105,20 +94,20 @@ def service_dashboard(service_id): ".view_job", service_id=current_service.id, job_id=job["id"] ), "created_at": job["created_at"], - "processing_finished": job["processing_finished"], - "processing_started": job["processing_started"], + "processing_finished": job.get("processing_finished"), + "processing_started": job.get("processing_started"), "notification_count": job["notification_count"], "created_by": job["created_by"], - "notifications": aggregate_notifications_by_job.get(job["id"], []), + "template_name": job["template_name"], + "original_file_name": job["original_file_name"], } for job in job_response - if aggregate_notifications_by_job.get(job["id"], []) ] return render_template( "views/dashboard/dashboard.html", updates_url=url_for(".service_dashboard_updates", service_id=service_id), partials=get_dashboard_partials(service_id), - job_and_notifications=job_and_notifications, + jobs=jobs, service_data_retention_days=service_data_retention_days, ) diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index aba7d2ac6..e8e5ec633 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -55,31 +55,30 @@
- {% if job_and_notifications %} - {% for job in job_and_notifications[:5] %} - {% if job.job_id and job.notifications %} + {% if jobs %} + {% for job in jobs[:5] %} {% set notification = job.notifications[0] %}