diff --git a/src/genlab_bestilling/forms.py b/src/genlab_bestilling/forms.py index d28798dd..1596aa89 100644 --- a/src/genlab_bestilling/forms.py +++ b/src/genlab_bestilling/forms.py @@ -352,17 +352,6 @@ def clean_contact_email_results(self) -> str: raise forms.ValidationError(msg) from ValidationError(msg) return ", ".join(emails) - def clean_contact_person_results(self) -> str: - names_raw = self.cleaned_data.get("contact_person_results", "") - names = [n.strip() for n in names_raw.split(",") if n.strip()] - - for name in names: - # Optionally allow hyphens and apostrophes in names - if not all(c.isalpha() or c.isspace() or c in "-'" for c in name): - msg = f"Invalid name: {name}" - raise forms.ValidationError(msg) from ValidationError(msg) - return ", ".join(names) - def save(self, commit: bool = True) -> Model: if not commit: msg = "This form is always committed" @@ -386,26 +375,16 @@ def save(self, commit: bool = True) -> Model: # Delete old entries first (in case of resubmission) obj.results_contacts.all().delete() - names = [ - strip_tags(n.strip()) - for n in self.cleaned_data["contact_person_results"].split(",") - if n.strip() - ] emails = [ strip_tags(e.strip()) for e in self.cleaned_data["contact_email_results"].split(",") if e.strip() ] - if names and emails: - if len(names) != len(emails): - msg = "The number of names must match the number of emails." - raise ValidationError(msg) - - for name, email in zip(names, emails, strict=False): + if emails: + for email in emails: AnalysisOrderResultsCommunication.objects.create( analysis_order=obj, - contact_person_results=name, contact_email_results=email, ) @@ -418,12 +397,6 @@ def clean(self) -> None: msg = "An extraction order must be selected" raise ValidationError(msg) - contact_person_results = forms.CharField( - label="Contact person(s) for results", - help_text="Comma-separated list of names to contact with results", - required=True, - ) - contact_email_results = forms.CharField( label="Contact email(s) for results", help_text="Comma-separated list of emails to contact with results (must match order of names)", # noqa: E501 diff --git a/src/genlab_bestilling/migrations/0037_remove_analysisorderresultscommunication_contact_person_results.py b/src/genlab_bestilling/migrations/0037_remove_analysisorderresultscommunication_contact_person_results.py new file mode 100644 index 00000000..8c4a2545 --- /dev/null +++ b/src/genlab_bestilling/migrations/0037_remove_analysisorderresultscommunication_contact_person_results.py @@ -0,0 +1,16 @@ +# Generated by Django 5.2.3 on 2025-07-29 12:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("genlab_bestilling", "0036_sample_markers"), + ] + + operations = [ + migrations.RemoveField( + model_name="analysisorderresultscommunication", + name="contact_person_results", + ), + ] diff --git a/src/genlab_bestilling/models.py b/src/genlab_bestilling/models.py index f59d7de6..095cfa9b 100644 --- a/src/genlab_bestilling/models.py +++ b/src/genlab_bestilling/models.py @@ -561,11 +561,6 @@ class AnalysisOrderResultsCommunication(models.Model): on_delete=models.CASCADE, related_name="results_contacts", ) - contact_person_results = models.CharField( - null=True, - blank=False, - help_text="Person to contact for analysis resuls", - ) contact_email_results = models.EmailField( null=True, blank=False, @@ -573,7 +568,7 @@ class AnalysisOrderResultsCommunication(models.Model): ) def __str__(self): - return f"{str(self.analysis_order)} {str(self.contact_person_results)} {str(self.contact_email_results)}" # noqa: E501 + return f"{str(self.analysis_order)} {str(self.contact_email_results)}" class AnalysisOrder(Order): diff --git a/src/staff/templatetags/order_tags.py b/src/staff/templatetags/order_tags.py index 173d8d99..4069543b 100644 --- a/src/staff/templatetags/order_tags.py +++ b/src/staff/templatetags/order_tags.py @@ -372,21 +372,21 @@ def contact_detail_table(order: Order) -> dict: if isinstance(order, AnalysisOrder): result_contacts = ( AnalysisOrderResultsCommunication.objects.filter(analysis_order=order) - .values_list("contact_person_results", "contact_email_results") + .values_list("contact_email_results") .distinct() ) if result_contacts: result_contacts_html = format_html_join( - "\n", - '
{} — {}
', # noqa: E501 - [(name, email, email) for name, email in result_contacts], + "; ", + '{}', # noqa: E501 + [(email[0], email[0]) for email in result_contacts], ) fields = { "Samples owner of genetic project": order.genrequest.samples_owner, "Responsible genetic researcher": order.contact_person, "Responsible genetic researcher email": order.contact_email, - "Contact name and email for analysis results": result_contacts_html, + "Contact email for analysis results": result_contacts_html, } return {