From 1f0da86227897451baeff9a20d726db17e4a2974 Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Mon, 24 Jul 2017 18:36:02 +0200 Subject: [PATCH] Add basic `add_event` method to Submission --- submissions/forms.py | 2 +- submissions/managers.py | 16 +++++++-- .../migrations/0056_auto_20170724_1818.py | 20 +++++++++++ submissions/models.py | 33 +++++++++++++++---- 4 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 submissions/migrations/0056_auto_20170724_1818.py diff --git a/submissions/forms.py b/submissions/forms.py index 8500b892e..fc5bcf13b 100644 --- a/submissions/forms.py +++ b/submissions/forms.py @@ -628,6 +628,6 @@ class SubmissionCycleChoiceForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['refereeing_cycle'].default = None - other_submission = self.instance.other_versions().first() + other_submission = self.instance.other_versions[0] if other_submission: self.fields['referees_reinvite'].queryset = other_submission.referee_invitations.all() diff --git a/submissions/managers.py b/submissions/managers.py index 878269b0f..7bff9d5ac 100644 --- a/submissions/managers.py +++ b/submissions/managers.py @@ -4,8 +4,8 @@ from django.db.models import Q from .constants import SUBMISSION_STATUS_OUT_OF_POOL, SUBMISSION_STATUS_PUBLICLY_UNLISTED,\ SUBMISSION_STATUS_PUBLICLY_INVISIBLE, STATUS_UNVETTED, STATUS_VETTED,\ STATUS_UNCLEAR, STATUS_INCORRECT, STATUS_NOT_USEFUL, STATUS_NOT_ACADEMIC,\ - SUBMISSION_HTTP404_ON_EDITORIAL_PAGE, STATUS_DRAFT,\ - SUBMISSION_EXCLUDE_FROM_REPORTING + SUBMISSION_HTTP404_ON_EDITORIAL_PAGE, SUBMISSION_EXCLUDE_FROM_REPORTING,\ + STATUS_DRAFT, EVENT_GENERAL, EVENT_FOR_AUTHOR, EVENT_FOR_EIC class SubmissionManager(models.Manager): @@ -83,7 +83,17 @@ class SubmissionManager(models.Manager): class SubmissionEventQuerySet(models.QuerySet): - pass + def for_author(self): + """ + Return all events that are meant to be for the author(s) of a submission. + """ + return self.filter(event__in=[EVENT_FOR_AUTHOR, EVENT_GENERAL]) + + def for_eic(self): + """ + Return all events that are meant to be for the Editor-in-charge of a submission. + """ + return self.filter(event__in=[EVENT_FOR_EIC, EVENT_GENERAL]) class EditorialAssignmentManager(models.Manager): diff --git a/submissions/migrations/0056_auto_20170724_1818.py b/submissions/migrations/0056_auto_20170724_1818.py new file mode 100644 index 000000000..aa28c5210 --- /dev/null +++ b/submissions/migrations/0056_auto_20170724_1818.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-24 16:18 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('submissions', '0055_auto_20170724_1734'), + ] + + operations = [ + migrations.RenameField( + model_name='submissionevent', + old_name='blub', + new_name='text', + ), + ] diff --git a/submissions/models.py b/submissions/models.py index 3c67c2d08..5ec885d4e 100644 --- a/submissions/models.py +++ b/submissions/models.py @@ -11,7 +11,7 @@ from .constants import ASSIGNMENT_REFUSAL_REASONS, ASSIGNMENT_NULLBOOL,\ RANKING_CHOICES, REPORT_REC, SUBMISSION_STATUS, STATUS_UNASSIGNED,\ REPORT_STATUSES, STATUS_UNVETTED, SUBMISSION_EIC_RECOMMENDATION_REQUIRED,\ SUBMISSION_CYCLES, CYCLE_DEFAULT, CYCLE_SHORT, CYCLE_DIRECT_REC,\ - EVENT_GENERAL, EVENT_TYPES + EVENT_GENERAL, EVENT_TYPES, EVENT_FOR_AUTHOR, EVENT_FOR_EIC from .managers import SubmissionManager, EditorialAssignmentManager, EICRecommendationManager,\ ReportManager, SubmissionEventQuerySet from .utils import ShortSubmissionCycle, DirectRecommendationSubmissionCycle,\ @@ -134,6 +134,7 @@ class Submission(models.Model): def reporting_deadline_has_passed(self): return timezone.now() > self.reporting_deadline + @cached_property def other_versions(self): return Submission.objects.filter( arxiv_identifier_wo_vn_nr=self.arxiv_identifier_wo_vn_nr @@ -158,11 +159,29 @@ class Submission(models.Model): def count_obtained_reports(self): return self.reports.accepted().filter(invited__isnull=False).count() - def count_refused_reports(self): - return self.reports.rejected().count() - - def count_awaiting_vetting(self): - return self.reports.awaiting_vetting().count() + def add_general_event(self, message): + event = SubmissionEvent( + submission=self, + event=EVENT_GENERAL, + text=message, + ) + event.save() + + def add_event_for_author(self, message): + event = SubmissionEvent( + submission=self, + event=EVENT_FOR_AUTHOR, + text=message, + ) + event.save() + + def add_event_for_eic(self, message): + event = SubmissionEvent( + submission=self, + event=EVENT_FOR_EIC, + text=message, + ) + event.save() class SubmissionEvent(TimeStampedModel): @@ -179,7 +198,7 @@ class SubmissionEvent(TimeStampedModel): submission = models.ForeignKey('submissions.Submission', on_delete=models.CASCADE, related_name='events') event = models.CharField(max_length=4, choices=EVENT_TYPES, default=EVENT_GENERAL) - blub = models.TextField() + text = models.TextField() objects = SubmissionEventQuerySet.as_manager() -- GitLab