diff --git a/app/models.py b/app/models.py index 9af631aaa..336305212 100644 --- a/app/models.py +++ b/app/models.py @@ -1227,6 +1227,10 @@ def communication_method_type(self): return response_type.LETTER if response_type.LETTER in [cm.method_type for cm in communication_methods] else response_type.EMAIL + @property + def event_timestamp(self): + return Events.query.filter_by(response_id=self.id).one().timestamp + def make_public(self): self.privacy = response_privacy.RELEASE_AND_PUBLIC self.release_date = calendar.addbusdays(datetime.utcnow(), RELEASE_PUBLIC_DAYS) diff --git a/app/request/api/views.py b/app/request/api/views.py index d00da7f51..dba87eaff 100644 --- a/app/request/api/views.py +++ b/app/request/api/views.py @@ -210,13 +210,13 @@ def get_request_responses(): current_request = Requests.query.filter_by(id=flask_request.args['request_id']).one() - responses = Responses.query.filter( + responses = Responses.query.join(Events, Responses.id == Events.response_id).filter( Responses.request_id == current_request.id, ~Responses.id.in_([cm.method_id for cm in CommunicationMethods.query.all()]), Responses.type != response_type.EMAIL, Responses.deleted == False ).order_by( - desc(Responses.date_modified) + desc(Events.timestamp) ).all()[start: start + RESPONSES_INCREMENT] template_path = 'request/responses/' diff --git a/app/response/utils.py b/app/response/utils.py index 2fd658e2e..ea57862ce 100644 --- a/app/response/utils.py +++ b/app/response/utils.py @@ -267,12 +267,23 @@ def add_denial(request_id, reason_ids, content, method, letter_template_id): request_id, es_update=False ) - response = Determinations( - request_id, - RELEASE_AND_PUBLIC, - determination_type.DENIAL, - format_determination_reasons(reason_ids) - ) + if not calendar.isbusday(datetime.utcnow()) or datetime.utcnow().date() < request.date_submitted.date(): + # push the denial date to the next business day if it is a weekend/holiday + # or if it is before the date submitted + response = Determinations( + request_id, + RELEASE_AND_PUBLIC, + determination_type.DENIAL, + format_determination_reasons(reason_ids), + date_modified=get_next_business_day() + ) + else: + response = Determinations( + request_id, + RELEASE_AND_PUBLIC, + determination_type.DENIAL, + format_determination_reasons(reason_ids) + ) if method == 'letter': response.reason = 'A letter will be mailed to the requester.' create_object(response) @@ -367,12 +378,23 @@ def add_closing(request_id, reason_ids, content, method, letter_template_id): request_id, es_update=False ) - response = Determinations( - request_id, - RELEASE_AND_PUBLIC, - determination_type.CLOSING, - format_determination_reasons(reason_ids) - ) + if not calendar.isbusday(datetime.utcnow()) or datetime.utcnow().date() < current_request.date_submitted.date(): + # push the closing date to the next business day if it is a weekend/holiday + # or if it is before the date submitted + response = Determinations( + request_id, + RELEASE_AND_PUBLIC, + determination_type.CLOSING, + format_determination_reasons(reason_ids), + date_modified=get_next_business_day() + ) + else: + response = Determinations( + request_id, + RELEASE_AND_PUBLIC, + determination_type.CLOSING, + format_determination_reasons(reason_ids) + ) if method == 'letter': response.reason = 'A letter will be mailed to the requester.' create_object(response) diff --git a/app/templates/request/responses/row.html b/app/templates/request/responses/row.html index 2078cc10b..fb6d17e1d 100644 --- a/app/templates/request/responses/row.html +++ b/app/templates/request/responses/row.html @@ -9,19 +9,19 @@ {% if current_user.is_agency %}
- {{ moment(response.date_modified).format('dddd, MM/DD/YYYY [at] h:mm A') }} + {{ moment(response.event_timestamp).format('dddd, MM/DD/YYYY [at] h:mm A') }}
{% if show_preview and response.preview is not none %} - {{ response.preview | safe}} + {{ response.preview | safe }} {% endif %}
{% else %}
{% if show_preview and response.preview is not none %} - {{ response.preview | safe}} + {{ response.preview | safe }} {% endif %}