diff --git a/scipost_django/submissions/forms/__init__.py b/scipost_django/submissions/forms/__init__.py index 99cdee7c08d3878090ec91c84ccd92d972489790..881d2ed573ea54e0a8267b140c62b76c2328aa58 100644 --- a/scipost_django/submissions/forms/__init__.py +++ b/scipost_django/submissions/forms/__init__.py @@ -2912,7 +2912,8 @@ class ConsiderRefereeInvitationForm(forms.Form): help_text=("The date by which you intend to deliver your report."), ) refusal_reason = forms.ChoiceField( - choices=[(None, "")] + list(EditorialAssignment.REFUSAL_REASONS), required=False + choices=[(None, "-" * 9)] + list(EditorialAssignment.REFUSAL_REASONS), + required=False, ) other_refusal_reason = forms.CharField( required=False, @@ -2967,8 +2968,16 @@ class ConsiderRefereeInvitationForm(forms.Form): "Please select an intended delivery date for your report.", ) - def save(self): - super().save() + def save(self, commit=True): + accepted = self.cleaned_data.get("accept", None) + intended_delivery_date = self.cleaned_data.get("intended_delivery_date", None) + refusal_reason = self.cleaned_data.get("refusal_reason", None) + other_refusal_reason = self.cleaned_data.get("other_refusal_reason", None) + + self.invitation.accepted = accepted + self.invitation.intended_delivery_date = intended_delivery_date + self.invitation.refusal_reason = refusal_reason + self.invitation.other_refusal_reason = other_refusal_reason self.invitation.submission.add_event_for_eic( f"Referee {self.invitation.referee.full_name} set intended report delivery date to {self.invitation.intended_delivery_date}." @@ -2977,6 +2986,11 @@ class ConsiderRefereeInvitationForm(forms.Form): f"A referee has set their intended report delivery date to {self.invitation.intended_delivery_date}." ) + if commit: + self.invitation.save() + + return self.invitation + class ReportIntendedDeliveryForm(forms.ModelForm): """ @@ -2987,6 +3001,9 @@ class ReportIntendedDeliveryForm(forms.ModelForm): class Meta: model = RefereeInvitation() fields = ["intended_delivery_date"] + widgets = { + "intended_delivery_date": forms.DateInput(attrs={"type": "date"}), + } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/scipost_django/submissions/views/__init__.py b/scipost_django/submissions/views/__init__.py index 3af2de875455c9b1cf6d878b3bdd8e2733ab3f39..255a5db4d38890af87fa89c69bae7a3ef79c18c2 100644 --- a/scipost_django/submissions/views/__init__.py +++ b/scipost_django/submissions/views/__init__.py @@ -1893,6 +1893,7 @@ def accept_or_decline_ref_invitations(request, invitation_id=None): form = ConsiderRefereeInvitationForm(request.POST or None, invitation=invitation) if form.is_valid(): + invitation = form.save(commit=False) invitation.date_responded = timezone.now() if form.cleaned_data["accept"] == "True": invitation.accepted = True @@ -2070,9 +2071,14 @@ def _hx_report_intended_delivery_form(request, invitation_id): "You do not have permission to edit the intended delivery date." ) - if invitation.submission.reporting_deadline_has_passed: + if invitation.fulfilled: return HTMXResponse( - "The refereeing deadline has passed. You cannot change the intended delivery date anymore.", + "The report has already been delivered. You may not change the intended delivery date.", + tag="danger", + ) + if invitation.cancelled: + return HTMXResponse( + "The invitation has been cancelled. You may not change the intended delivery date.", tag="danger", )