From 118d2a3b2b7e387d4e8bbd716d547495dc4063d3 Mon Sep 17 00:00:00 2001 From: Miriam Forner Date: Tue, 25 Aug 2020 10:42:45 +0100 Subject: [PATCH] Replace received property with date_received field As all enquiries now have a value for date_received, the model property 'received' is no longer needed. --- app/enquiries/forms.py | 2 +- app/enquiries/models.py | 5 ----- app/enquiries/serializers.py | 2 +- app/enquiries/templates/enquiry_delete.html | 2 +- app/enquiries/templates/enquiry_detail.html | 2 +- app/enquiries/templates/enquiry_edit.html | 2 +- app/enquiries/templates/snippets/enquiry_item.html | 2 +- app/enquiries/views.py | 10 ++++++---- app/settings/common.py | 2 +- 9 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/enquiries/forms.py b/app/enquiries/forms.py index d6ea3110..5a3408d8 100644 --- a/app/enquiries/forms.py +++ b/app/enquiries/forms.py @@ -48,4 +48,4 @@ def __init__(self, *args, **kwargs): class Meta: model = Enquiry - exclude = ('datahub_project_status',) + exclude = ('datahub_project_status', 'date_received') diff --git a/app/enquiries/models.py b/app/enquiries/models.py index f16a9292..d574b2b2 100644 --- a/app/enquiries/models.py +++ b/app/enquiries/models.py @@ -245,11 +245,6 @@ class Enquiry(TimeStampedModel): help_text="Address of the company in Data Hub", ) - # Handles cases where the optional date_received field is not set. - @property - def received(self): - return self.date_received or self.created - class Meta: ordering = ["-created"] verbose_name_plural = "Enquiries" diff --git a/app/enquiries/serializers.py b/app/enquiries/serializers.py index 382533c2..7b3cd281 100644 --- a/app/enquiries/serializers.py +++ b/app/enquiries/serializers.py @@ -80,7 +80,7 @@ class EnquiryDetailSerializer(serializers.ModelSerializer): ) date_added_to_datahub = serializers.DateField(format="%d %B %Y") project_success_date = serializers.DateField(format="%d %B %Y") - received = serializers.DateTimeField(format="%d %B %Y") + date_received = serializers.DateTimeField(format="%d %B %Y") class Meta: model = models.Enquiry diff --git a/app/enquiries/templates/enquiry_delete.html b/app/enquiries/templates/enquiry_delete.html index 57e00851..3a392e60 100644 --- a/app/enquiries/templates/enquiry_delete.html +++ b/app/enquiries/templates/enquiry_delete.html @@ -38,7 +38,7 @@

{{ enquiry.company_name }}

Date received
-
{{ enquiry|get_field_value:"received" }}
+
{{ enquiry|get_field_value:"date_received" }}
diff --git a/app/enquiries/templates/enquiry_detail.html b/app/enquiries/templates/enquiry_detail.html index d2e9bab9..dbaaff83 100644 --- a/app/enquiries/templates/enquiry_detail.html +++ b/app/enquiries/templates/enquiry_detail.html @@ -54,7 +54,7 @@

{{ enquiry.company_name }}

Date received
-
{{ enquiry|get_field_value:"received" }}
+
{{ enquiry|get_field_value:"date_received" }}
diff --git a/app/enquiries/templates/enquiry_edit.html b/app/enquiries/templates/enquiry_edit.html index d5103fa6..6db0a77b 100644 --- a/app/enquiries/templates/enquiry_edit.html +++ b/app/enquiries/templates/enquiry_edit.html @@ -48,7 +48,7 @@

{{ enquiry.company_name }}

Date received
-
{{ enquiry|get_field_value:"received" }}
+
{{ enquiry|get_field_value:"date_received" }}
diff --git a/app/enquiries/templates/snippets/enquiry_item.html b/app/enquiries/templates/snippets/enquiry_item.html index 5f6013e6..eb7c0c20 100644 --- a/app/enquiries/templates/snippets/enquiry_item.html +++ b/app/enquiries/templates/snippets/enquiry_item.html @@ -27,7 +27,7 @@

Date received - {{ enquiry.received }} + {{ enquiry.date_received }}
Enquiry text diff --git a/app/enquiries/views.py b/app/enquiries/views.py index 554faedc..baf4f92e 100644 --- a/app/enquiries/views.py +++ b/app/enquiries/views.py @@ -224,18 +224,20 @@ def filter_owner_id(self, queryset, name, value): def filter_received_lt(self, queryset, name, value): """ - Returns a queryset only with entities having the ``received`` date less than ``value``. + Returns a queryset with entities which have a ``date_received`` + less than ``value``. """ received = datetime.combine(value, datetime.min.time()) - q = Q(date_received__lt=received) | Q(date_received__isnull=True, created__lt=received,) + q = Q(date_received__lt=received) return queryset.filter(q) def filter_received_gt(self, queryset, name, value): """ - Returns a queryset only with entities having the ``received`` date greater than ``value``. + Returns a queryset with entities which have a ``date_received`` + greater than ``value``. """ received = datetime.combine(value, datetime.min.time()) - q = Q(date_received__gt=received) | Q(date_received__isnull=True, created__gt=received,) + q = Q(date_received__gt=received) return queryset.filter(q) class Meta: diff --git a/app/settings/common.py b/app/settings/common.py index 93d02b3d..9195f369 100644 --- a/app/settings/common.py +++ b/app/settings/common.py @@ -252,7 +252,7 @@ 'google_campaign', 'how_they_heard_dit', 'investment_readiness', 'investment_type', 'ist_sector', 'marketing_channel', 'notes', 'owner', 'owner.first_name', 'owner.last_name', 'primary_sector', 'project_code', 'project_name', 'project_success_date', 'quality', - 'received', 'region', 'second_hpo_selection', 'third_hpo_selection', 'website'] + 'region', 'second_hpo_selection', 'third_hpo_selection', 'website'] # Data Hub settings DATA_HUB_METADATA_URL = env('DATA_HUB_METADATA_URL')