diff --git a/submissions/forms.py b/submissions/forms.py index 2f79c675e5f06d1655702977633683e4d340c546..a76c5c609e8864f181bf41795faad0c5d6fc42fd 100644 --- a/submissions/forms.py +++ b/submissions/forms.py @@ -6,7 +6,8 @@ from guardian.shortcuts import assign_perm from .constants import ASSIGNMENT_BOOL, ASSIGNMENT_REFUSAL_REASONS, STATUS_RESUBMITTED,\ REPORT_ACTION_CHOICES, REPORT_REFUSAL_CHOICES, STATUS_REVISION_REQUESTED,\ - STATUS_REJECTED, STATUS_REJECTED_VISIBLE, STATUS_RESUBMISSION_INCOMING + STATUS_REJECTED, STATUS_REJECTED_VISIBLE, STATUS_RESUBMISSION_INCOMING,\ + STATUS_DRAFT, STATUS_UNVETTED from .models import Submission, RefereeInvitation, Report, EICRecommendation, EditorialAssignment from scipost.constants import SCIPOST_SUBJECT_AREAS @@ -417,17 +418,38 @@ class ReportForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ReportForm, self).__init__(*args, **kwargs) - self.fields['strengths'].widget.attrs.update( - {'placeholder': 'Give a point-by-point (numbered 1-, 2-, ...) list of the paper\'s strengths', - 'rows': 10, 'cols': 100}) - self.fields['weaknesses'].widget.attrs.update( - {'placeholder': 'Give a point-by-point (numbered 1-, 2-, ...) list of the paper\'s weaknesses', - 'rows': 10, 'cols': 100}) + self.fields['strengths'].widget.attrs.update({ + 'placeholder': ('Give a point-by-point ' + '(numbered 1-, 2-, ...) list of the paper\'s strengths'), + 'rows': 10, + 'cols': 100 + }) + self.fields['weaknesses'].widget.attrs.update({ + 'placeholder': ('Give a point-by-point ' + '(numbered 1-, 2-, ...) list of the paper\'s weaknesses'), + 'rows': 10, + 'cols': 100 + }) self.fields['report'].widget.attrs.update({'placeholder': 'Your general remarks', 'rows': 10, 'cols': 100}) - self.fields['requested_changes'].widget.attrs.update( - {'placeholder': 'Give a numbered (1-, 2-, ...) list of specifically requested changes', - 'cols': 100}) + self.fields['requested_changes'].widget.attrs.update({ + 'placeholder': 'Give a numbered (1-, 2-, ...) list of specifically requested changes', + 'cols': 100 + }) + + def save(self, commit=False): + """ + Possibly overwrite the default status if user asks for saving as draft. + """ + report = super().save(commit=False) + if 'save_draft' in self.data: + report.status = STATUS_DRAFT + elif 'save_submit' in self.data: + report.status = STATUS_UNVETTED + + if commit: + report.save() + return report class VetReportForm(forms.Form): diff --git a/submissions/templates/submissions/submission_detail.html b/submissions/templates/submissions/submission_detail.html index c10ff311dbc77527b3a1fd60c593d843f299b907..f255cf191d11632a6776dda1ba0baf10e76e4ffd 100644 --- a/submissions/templates/submissions/submission_detail.html +++ b/submissions/templates/submissions/submission_detail.html @@ -58,6 +58,12 @@ {% endfor %} </div> {% endif %} + + {% if unfinished_report_for_user %} + <blockquote class="blockquote"> + <p class="mb-0">You have an unfinished report for this submission, <a href="{% url 'submissions:submit_report' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}">finish your report here.</a></p> + </blockquote> + {% endif %} </div> </div> @@ -110,7 +116,8 @@ {% if submission.open_for_reporting %} {% if perms.scipost.can_referee and not is_author and not is_author_unchecked %} <li> - <h3><a href="{% url 'submissions:submit_report' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}">Contribute a Report</a></h3> + + <h3><a href="{% url 'submissions:submit_report' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}">{% if unfinished_report_for_user %}Finish your report{% else %}Contribute a Report{% endif %}</a></h3> <div class="text-danger">Deadline for reporting: {{ submission.reporting_deadline|date:"Y-m-d" }}</div> </li> {% elif is_author_unchecked %} diff --git a/submissions/templates/submissions/submit_report.html b/submissions/templates/submissions/submit_report.html index 72a253c84058ac31f315ed052402b541edd3d08b..63f80e447b69a04de026d1a51db389b58df83e29 100644 --- a/submissions/templates/submissions/submit_report.html +++ b/submissions/templates/submissions/submit_report.html @@ -88,8 +88,9 @@ <form action="{% url 'submissions:submit_report' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}" method="post"> {% csrf_token %} {{ form|bootstrap:'3,9' }} - <input class="btn btn-primary" type="submit" value="Submit your report"/> - <div class="mt-2"> + <input class="btn btn-primary" type="submit" name="save_submit" value="Submit your report"/> + <input class="btn btn-secondary ml-2" type="submit" name="save_draft" value="Save your report as draft"/> + <div class="my-4"> <em>By clicking on Submit, you state that you abide by the <a href="{% url 'journals:journals_terms_and_conditions' %}#referee_code_of_conduct">referee code of conduct</a>.</em> </div> </form> diff --git a/submissions/views.py b/submissions/views.py index afc17c842eccc0fc61a97064508c0b6a43b8f36f..95105dd106a2d2ce972ecff946b0cc49f0ef57bb 100644 --- a/submissions/views.py +++ b/submissions/views.py @@ -16,7 +16,8 @@ from guardian.decorators import permission_required_or_403 from guardian.shortcuts import assign_perm from .constants import SUBMISSION_STATUS_VOTING_DEPRECATED, STATUS_VETTED, STATUS_EIC_ASSIGNED,\ - SUBMISSION_STATUS_PUBLICLY_INVISIBLE, SUBMISSION_STATUS, ED_COMM_CHOICES + SUBMISSION_STATUS_PUBLICLY_INVISIBLE, SUBMISSION_STATUS, ED_COMM_CHOICES,\ + STATUS_DRAFT from .models import Submission, EICRecommendation, EditorialAssignment,\ RefereeInvitation, Report, EditorialCommunication from .forms import SubmissionIdentifierForm, RequestSubmissionForm, SubmissionSearchForm,\ @@ -167,12 +168,18 @@ def submission_detail(request, arxiv_identifier_w_vn_nr): submission = get_object_or_404(Submission, arxiv_identifier_w_vn_nr=arxiv_identifier_w_vn_nr) try: is_author = request.user.contributor in submission.authors.all() - is_author_unchecked = (not is_author and not - (request.user.contributor in submission.authors_false_claims.all()) and - (request.user.last_name in submission.author_list)) + is_author_unchecked = (not is_author and + request.user.contributor not in submission.authors_false_claims.all() + and request.user.last_name in submission.author_list) + try: + unfinished_report_for_user = (submission.reports.in_draft() + .get(author=request.user.contributor)) + except Report.DoesNotExist: + unfinished_report_for_user = None except AttributeError: is_author = False is_author_unchecked = False + unfinished_report_for_user = None if (submission.status in SUBMISSION_STATUS_PUBLICLY_INVISIBLE and not request.user.groups.filter(name__in=['SciPost Administrators', 'Editorial Administrators', @@ -187,8 +194,10 @@ def submission_detail(request, arxiv_identifier_w_vn_nr): invited_reports = submission.reports.accepted().filter(invited=True) contributed_reports = submission.reports.accepted().filter(invited=False) - comments = submission.comments.vetted().filter(is_author_reply=False).order_by('-date_submitted') - author_replies = submission.comments.vetted().filter(is_author_reply=True).order_by('-date_submitted') + comments = (submission.comments.vetted() + .filter(is_author_reply=False).order_by('-date_submitted')) + author_replies = (submission.comments.vetted() + .filter(is_author_reply=True).order_by('-date_submitted')) try: recommendation = (EICRecommendation.objects.filter_for_user(request.user) @@ -202,6 +211,7 @@ def submission_detail(request, arxiv_identifier_w_vn_nr): 'comments': comments, 'invited_reports': invited_reports, 'contributed_reports': contributed_reports, + 'unfinished_report_for_user': unfinished_report_for_user, 'author_replies': author_replies, 'form': form, 'is_author': is_author, @@ -1001,6 +1011,7 @@ def submit_report(request, arxiv_identifier_w_vn_nr): if not invitation and timezone.now() > submission.reporting_deadline + datetime.timedelta(days=1): errormessage = ('The reporting deadline has passed. You cannot submit' ' a Report anymore.') + # Also, delete possible report in draft here? if is_author: errormessage = 'You are an author of this Submission and cannot submit a Report.' if is_author_unchecked: @@ -1011,12 +1022,26 @@ def submit_report(request, arxiv_identifier_w_vn_nr): messages.warning(request, errormessage) return redirect(reverse('scipost:personal_page')) - form = ReportForm(request.POST or None) + try: + report_in_draft = submission.reports.in_draft().get(author=request.user.contributor) + except Report.DoesNotExist: + report_in_draft = None + form = ReportForm(request.POST or None, instance=report_in_draft) if form.is_valid(): author = request.user.contributor newreport = form.save(commit=False) newreport.submission = submission newreport.author = request.user.contributor + + newreport.date_submitted = timezone.now() + newreport.save() + + if newreport.status == STATUS_DRAFT: + messages.success(request, ('Your Report has been saved. ' + 'You may leave the page and finish it later.')) + context = {'submission': submission, 'form': form} + return render(request, 'submissions/submit_report.html', context) + if invitation: invitation.fulfilled = True newreport.invited = True @@ -1026,9 +1051,6 @@ def submit_report(request, arxiv_identifier_w_vn_nr): if author.user.last_name in submission.referees_flagged: newreport.flagged = True - newreport.date_submitted = timezone.now() - newreport.save() - # Update user stats author.nr_reports = Report.objects.filter(author=author).count() author.save()