diff --git a/hypha/apply/funds/models/co_applicants.py b/hypha/apply/funds/models/co_applicants.py index c0cd94575c..504e2eac81 100644 --- a/hypha/apply/funds/models/co_applicants.py +++ b/hypha/apply/funds/models/co_applicants.py @@ -1,4 +1,5 @@ from django.db import models +from django.utils import timezone from django.utils.translation import gettext_lazy as _ from hypha.apply.users.models import User @@ -60,6 +61,11 @@ class Meta: def __str__(self): return f"{self.invited_user_email} invited to {self.submission})" + def respond(self, status): + self.status = status + self.responded_on = timezone.now() + self.save(update_fields=["status", "responded_on"]) + class CoApplicant(models.Model): submission = models.ForeignKey( diff --git a/hypha/apply/funds/utils.py b/hypha/apply/funds/utils.py index a154b4421d..2a07213263 100644 --- a/hypha/apply/funds/utils.py +++ b/hypha/apply/funds/utils.py @@ -1,13 +1,13 @@ import csv import os import re -from datetime import datetime from io import StringIO from itertools import chain from typing import Iterable from django.core.files.storage import default_storage from django.urls import reverse +from django.utils import timezone from django.utils.encoding import force_bytes from django.utils.html import strip_tags from django.utils.http import urlsafe_base64_encode @@ -162,7 +162,7 @@ def get_copied_form_name(original_form_name: str) -> str: str: name of the copied form """ copy_str = _("Copied on {copy_time}") - copy_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-4] + copy_time = timezone.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-4] date_reg = r"(\d{2,4}-?){3} (\d{2}(:|.)?){4}" # match the strftime pattern of %Y-%m-%d %H:%M:%S.%f # Escape the `copy_str` to allow for translations to be matched & replace the diff --git a/hypha/apply/funds/views/co_applicants.py b/hypha/apply/funds/views/co_applicants.py index cbd77c6641..960464f8eb 100644 --- a/hypha/apply/funds/views/co_applicants.py +++ b/hypha/apply/funds/views/co_applicants.py @@ -1,4 +1,3 @@ -import datetime import json from django.conf import settings @@ -153,9 +152,7 @@ def get(self, *args, **kwargs): def post(self, args, **kwargs): action = self.request.POST.get("action") if action == "accept": - self.invite.status = CoApplicantInviteStatus.ACCEPTED - self.invite.responded_on = datetime.datetime.now() - self.invite.save(update_fields=["status", "responded_on"]) + self.invite.respond(CoApplicantInviteStatus.ACCEPTED) # handle auto login/signup user, created = User.objects.get_or_create( @@ -194,9 +191,7 @@ def post(self, args, **kwargs): login(self.request, user) return HttpResponseClientRedirect(self.get_success_url()) - self.invite.status = CoApplicantInviteStatus.REJECTED - self.invite.responded_on = datetime.datetime.now() - self.invite.save(update_fields=["status", "responded_on"]) + self.invite.respond(CoApplicantInviteStatus.REJECTED) if self.request.user.is_authenticated: return HttpResponseClientRedirect(reverse_lazy("dashboard:dashboard")) return HttpResponseClientRedirect("/") diff --git a/hypha/apply/funds/views/revisions.py b/hypha/apply/funds/views/revisions.py index 0c316d9524..785349eb5e 100644 --- a/hypha/apply/funds/views/revisions.py +++ b/hypha/apply/funds/views/revisions.py @@ -174,8 +174,7 @@ def cleanse_stream_fields(self, a_field, b_field) -> List[str]: sanitized_answers.append(f"{heading}{answer}") except AttributeError: - # If it fails to match for some reason just cleanse the fields but leave h2s - answer = nh3.clean(answer, attributes={}, tags={"h2"}) - sanitized_answers.append(field) + # If it fails to match for some reason just cleanse the field but leave h2s + sanitized_answers.append(nh3.clean(field, attributes={}, tags={"h2"})) return sanitized_answers diff --git a/hypha/apply/projects/models/payment.py b/hypha/apply/projects/models/payment.py index 738ee886b8..949ce36f8c 100644 --- a/hypha/apply/projects/models/payment.py +++ b/hypha/apply/projects/models/payment.py @@ -201,7 +201,7 @@ def can_user_delete(self, user): CoApplicantRole, ) - if self.status in (SUBMITTED): + if self.status == SUBMITTED: if user.is_apply_staff: return True if user.is_applicant: diff --git a/hypha/apply/projects/reports/management/commands/notify_report_due.py b/hypha/apply/projects/reports/management/commands/notify_report_due.py index 41b3786580..80bac8c06f 100644 --- a/hypha/apply/projects/reports/management/commands/notify_report_due.py +++ b/hypha/apply/projects/reports/management/commands/notify_report_due.py @@ -45,7 +45,10 @@ def handle(self, *args, **options): delta = frequency.reminder_days * multiplier due_date = today + relativedelta(days=delta) - for project in Project.objects.in_progress(): + # Make sure that project has report_config. + for project in Project.objects.in_progress().filter( + report_config__isnull=False + ): next_report = project.report_config.ensure_due_report() if not next_report: continue