Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #179 from uktrade/chore/replace_received_property
Browse files Browse the repository at this point in the history
Replace received property with date_received field
  • Loading branch information
mforner13 authored Aug 26, 2020
2 parents 2871e80 + 118d2a3 commit dc35096
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/enquiries/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def __init__(self, *args, **kwargs):

class Meta:
model = Enquiry
exclude = ('datahub_project_status',)
exclude = ('datahub_project_status', 'date_received')
5 changes: 0 additions & 5 deletions app/enquiries/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/enquiries/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/enquiries/templates/enquiry_delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h2 class="govuk-heading-l">{{ enquiry.company_name }}</h2>
<dt class="govuk-summary-list__key">
Date received
</dt>
<dd class="govuk-summary-list__value">{{ enquiry|get_field_value:"received" }}</dd>
<dd class="govuk-summary-list__value">{{ enquiry|get_field_value:"date_received" }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Expand Down
2 changes: 1 addition & 1 deletion app/enquiries/templates/enquiry_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h2 class="govuk-heading-l">{{ enquiry.company_name }}</h2>
<dt class="govuk-summary-list__key">
Date received
</dt>
<dd class="govuk-summary-list__value">{{ enquiry|get_field_value:"received" }}</dd>
<dd class="govuk-summary-list__value">{{ enquiry|get_field_value:"date_received" }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Expand Down
2 changes: 1 addition & 1 deletion app/enquiries/templates/enquiry_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2 class="govuk-heading-l">{{ enquiry.company_name }}</h2>
<dt class="govuk-summary-list__key">
Date received
</dt>
<dd class="govuk-summary-list__value">{{ enquiry|get_field_value:"received" }}</dd>
<dd class="govuk-summary-list__value">{{ enquiry|get_field_value:"date_received" }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Expand Down
2 changes: 1 addition & 1 deletion app/enquiries/templates/snippets/enquiry_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h3>
<div class="entity__content-list">
<div class="entity__content-item">
<span class="list-item-label">Date received</span>
<span class="list-item-value">{{ enquiry.received }}</span>
<span class="list-item-value">{{ enquiry.date_received }}</span>
</div>
<div class="entity__content-item">
<span class="list-item-label">Enquiry text</span>
Expand Down
10 changes: 6 additions & 4 deletions app/enquiries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit dc35096

Please sign in to comment.