From db9d16dfb5bcadc299a4f29460ebd9ff1d54327c Mon Sep 17 00:00:00 2001 From: Caitlin Barnard <54268863+CaitBarnard@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:11:05 +0000 Subject: [PATCH] FFT-104 Validation for Add Vacancy form (#544) --- ...0_alter_vacancy_appointee_name_and_more.py | 59 +++++++++++++++++++ ...1_alter_vacancy_appointee_name_and_more.py | 59 +++++++++++++++++++ payroll/models.py | 37 +++++++++++- .../templates/payroll/page/add_vacancy.html | 18 +++--- .../payroll/partials/_error_summary.html | 26 ++++++++ .../{ => payroll/partials}/_form_field.html | 0 6 files changed, 188 insertions(+), 11 deletions(-) create mode 100644 payroll/migrations/0010_alter_vacancy_appointee_name_and_more.py create mode 100644 payroll/migrations/0011_alter_vacancy_appointee_name_and_more.py create mode 100644 payroll/templates/payroll/partials/_error_summary.html rename payroll/templates/{ => payroll/partials}/_form_field.html (100%) diff --git a/payroll/migrations/0010_alter_vacancy_appointee_name_and_more.py b/payroll/migrations/0010_alter_vacancy_appointee_name_and_more.py new file mode 100644 index 00000000..23dd74ba --- /dev/null +++ b/payroll/migrations/0010_alter_vacancy_appointee_name_and_more.py @@ -0,0 +1,59 @@ +# Generated by Django 4.2.16 on 2024-11-18 12:07 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("payroll", "0009_remove_vacancy_programme_switch_vacancy"), + ] + + operations = [ + migrations.AlterField( + model_name="vacancy", + name="appointee_name", + field=models.CharField( + blank=True, + max_length=255, + null=True, + validators=[ + django.core.validators.RegexValidator( + message="Only letters, spaces, - and ' are allowed", + regex="^[a-zA-Z '-]*$", + ) + ], + ), + ), + migrations.AlterField( + model_name="vacancy", + name="hiring_manager", + field=models.CharField( + blank=True, + max_length=255, + null=True, + validators=[ + django.core.validators.RegexValidator( + message="Only letters, spaces, - and ' are allowed", + regex="^[a-zA-Z '-]*$", + ) + ], + ), + ), + migrations.AlterField( + model_name="vacancy", + name="hr_ref", + field=models.CharField( + blank=True, + max_length=255, + null=True, + validators=[ + django.core.validators.RegexValidator( + message="Only letters, spaces, - and ' are allowed", + regex="^[a-zA-Z '-]*$", + ) + ], + ), + ), + ] diff --git a/payroll/migrations/0011_alter_vacancy_appointee_name_and_more.py b/payroll/migrations/0011_alter_vacancy_appointee_name_and_more.py new file mode 100644 index 00000000..61a1897a --- /dev/null +++ b/payroll/migrations/0011_alter_vacancy_appointee_name_and_more.py @@ -0,0 +1,59 @@ +# Generated by Django 4.2.16 on 2024-11-18 13:52 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("payroll", "0010_alter_vacancy_appointee_name_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="vacancy", + name="appointee_name", + field=models.CharField( + blank=True, + max_length=255, + null=True, + validators=[ + django.core.validators.RegexValidator( + message="Only letters, spaces, - and ' are allowed.", + regex="^[a-zA-Z '-]*$", + ) + ], + ), + ), + migrations.AlterField( + model_name="vacancy", + name="hiring_manager", + field=models.CharField( + blank=True, + max_length=255, + null=True, + validators=[ + django.core.validators.RegexValidator( + message="Only letters, spaces, - and ' are allowed.", + regex="^[a-zA-Z '-]*$", + ) + ], + ), + ), + migrations.AlterField( + model_name="vacancy", + name="hr_ref", + field=models.CharField( + blank=True, + max_length=255, + null=True, + validators=[ + django.core.validators.RegexValidator( + message="Only letters, spaces, - and ' are allowed.", + regex="^[a-zA-Z '-]*$", + ) + ], + ), + ), + ] diff --git a/payroll/models.py b/payroll/models.py index 9ce1e5e9..807c36d6 100644 --- a/payroll/models.py +++ b/payroll/models.py @@ -1,3 +1,4 @@ +from django.core.validators import RegexValidator from django.db import models @@ -154,6 +155,36 @@ class Meta: choices=RecruitmentStage.choices, default=RecruitmentStage.PREPARING ) - appointee_name = models.CharField(max_length=255, null=True, blank=True) - hiring_manager = models.CharField(max_length=255, null=True, blank=True) - hr_ref = models.CharField(max_length=255, null=True, blank=True) + appointee_name = models.CharField( + max_length=255, + null=True, + blank=True, + validators=[ + RegexValidator( + regex=r"^[a-zA-Z '-]*$", + message="Only letters, spaces, - and ' are allowed.", + ) + ], + ) + hiring_manager = models.CharField( + max_length=255, + null=True, + blank=True, + validators=[ + RegexValidator( + regex=r"^[a-zA-Z '-]*$", + message="Only letters, spaces, - and ' are allowed.", + ) + ], + ) + hr_ref = models.CharField( + max_length=255, + null=True, + blank=True, + validators=[ + RegexValidator( + regex=r"^[a-zA-Z '-]*$", + message="Only letters, spaces, - and ' are allowed.", + ) + ], + ) diff --git a/payroll/templates/payroll/page/add_vacancy.html b/payroll/templates/payroll/page/add_vacancy.html index 7df2ae8f..e824fa8e 100644 --- a/payroll/templates/payroll/page/add_vacancy.html +++ b/payroll/templates/payroll/page/add_vacancy.html @@ -13,16 +13,18 @@ {% block content %}