From d715b08daa2d113e41960d758bd0ce415e94ce5b Mon Sep 17 00:00:00 2001 From: erikvw Date: Fri, 2 Feb 2024 10:08:55 -0600 Subject: [PATCH] add system_check to check reference_model matches --- edc_action_item/models/action_item.py | 1 - edc_action_item/system_checks.py | 33 ++++++++++++++++++- .../bootstrap3/action_item_with_popover.html | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/edc_action_item/models/action_item.py b/edc_action_item/models/action_item.py index 835c87f..db378ce 100644 --- a/edc_action_item/models/action_item.py +++ b/edc_action_item/models/action_item.py @@ -176,7 +176,6 @@ def save(self, *args, **kwargs): self.priority = self.priority or self.action_type.priority self.reference_model = self.action_type.reference_model self.related_reference_model = self.action_type.related_reference_model - self.instructions = self.action_type.instructions else: if ( self.status in [NEW, CANCELLED] diff --git a/edc_action_item/system_checks.py b/edc_action_item/system_checks.py index 026cb60..0f2a81c 100644 --- a/edc_action_item/system_checks.py +++ b/edc_action_item/system_checks.py @@ -1,5 +1,6 @@ -from django.core.checks import Warning +from django.core.checks import Error, Warning +from .models import ActionItem from .site_action_items import site_action_items @@ -19,7 +20,37 @@ def edc_action_item_check(app_configs, **kwargs): ), hint="History manager is need to detect changes.", obj=action_cls, + id="edc_action_item.W001", + ) + ) + for action_item in ActionItem.objects.all(): + if action_item.reference_model != action_item.action_type.reference_model: + errors.append( + Error( + ( + "Action item reference model value does not match " + "action_type.reference_model. " + f"Got {action_item.reference_model} != " + f"{action_item.action_type.reference_model}" + ), + obj=action_item, id="edc_action_item.E001", ) ) + if ( + action_item.related_reference_model + != action_item.action_type.related_reference_model + ): + errors.append( + Error( + ( + "Action item related_reference_modell value does not match " + "action_type.related_reference_model. " + f"Got {action_item.related_reference_model} != " + f"{action_item.action_type.related_reference_model}" + ), + obj=action_item, + id="edc_action_item.E002", + ) + ) return errors diff --git a/edc_action_item/templates/edc_action_item/bootstrap3/action_item_with_popover.html b/edc_action_item/templates/edc_action_item/bootstrap3/action_item_with_popover.html index e7b51ee..ce8f37c 100644 --- a/edc_action_item/templates/edc_action_item/bootstrap3/action_item_with_popover.html +++ b/edc_action_item/templates/edc_action_item/bootstrap3/action_item_with_popover.html @@ -22,7 +22,7 @@ {{ action_item.get_priority_display|title }}
{{ action_item.display_name|default:'alert' }}

{% render_action_item_reason action_item %}

-{% if action_item.instructions %}

{{ action_item.instructions|truncatechars:250 }}

{% endif %} +{% if action_item.action_type.instructions %}

{{ action_item.action_type.instructions|truncatechars:250 }}

{% endif %}

{% trans "Opened on" %} {{ report_datetime }}. {% if date_last_updated %}{% trans "Last updated on" %} {{date_last_updated}} {% if user_last_updated %}{% trans "by" %} {{user_last_updated}}{% endif %}{% else %}{% trans "This action item has not been updated." %}{% endif %}