diff --git a/submissions/__init__.py b/submissions/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..1c2ca927d5cf740e7bfc6703a73f1e0f550ea623 100644 --- a/submissions/__init__.py +++ b/submissions/__init__.py @@ -0,0 +1 @@ +default_app_config = 'submissions.apps.SubmissionsConfig' diff --git a/submissions/apps.py b/submissions/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..51d7411cf0f3b4c3d4c41624e4b11733d3bded4f --- /dev/null +++ b/submissions/apps.py @@ -0,0 +1,19 @@ +from django.apps import AppConfig +from django.db.models.signals import post_save + + +class SubmissionsConfig(AppConfig): + name = 'submissions' + + def ready(self): + super().ready() + + from . import models, signals + post_save.connect(signals.notify_new_manuscript_submitted, + sender=models.Submission) + post_save.connect(signals.notify_new_editorial_recommendation, + sender=models.EICRecommendation) + post_save.connect(signals.notify_new_editorial_assignment, + sender=models.EditorialAssignment) + post_save.connect(signals.notify_new_referee_invitation, + sender=models.RefereeInvitation) diff --git a/submissions/models.py b/submissions/models.py index c7b1dee29d3527018e241d5fb7c9830fe068fa3d..08983d70a1277b3e8890a8c1ae2d691d35bd7235 100644 --- a/submissions/models.py +++ b/submissions/models.py @@ -275,6 +275,9 @@ class EditorialAssignment(SubmissionRelatedObjectMixin, models.Model): self.submission.title[:30] + ' by ' + self.submission.author_list[:30] + ', requested on ' + self.date_created.strftime('%Y-%m-%d')) + def get_absolute_url(self): + return reverse('submissions:assignment_request', args=(self.id,)) + class RefereeInvitation(SubmissionRelatedObjectMixin, models.Model): submission = models.ForeignKey('submissions.Submission', on_delete=models.CASCADE, @@ -503,8 +506,10 @@ class EICRecommendation(SubmissionRelatedObjectMixin, models.Model): eligible_to_vote = models.ManyToManyField('scipost.Contributor', blank=True, related_name='eligible_to_vote') voted_for = models.ManyToManyField('scipost.Contributor', blank=True, related_name='voted_for') - voted_against = models.ManyToManyField('scipost.Contributor', blank=True, related_name='voted_against') - voted_abstain = models.ManyToManyField('scipost.Contributor', blank=True, related_name='voted_abstain') + voted_against = models.ManyToManyField('scipost.Contributor', blank=True, + related_name='voted_against') + voted_abstain = models.ManyToManyField('scipost.Contributor', blank=True, + related_name='voted_abstain') voting_deadline = models.DateTimeField('date submitted', default=timezone.now) objects = EICRecommendationManager() @@ -513,6 +518,10 @@ class EICRecommendation(SubmissionRelatedObjectMixin, models.Model): return (self.submission.title[:20] + ' by ' + self.submission.author_list[:30] + ', ' + self.get_recommendation_display()) + def get_absolute_url(self): + # TODO: Fix this weird redirect, but it's neccesary for the notifications to have one. + return self.submission.get_absolute_url() + @property def nr_for(self): return self.voted_for.count() diff --git a/submissions/signals.py b/submissions/signals.py new file mode 100644 index 0000000000000000000000000000000000000000..53461d84cea416478376bd2404f1700834d0aaaf --- /dev/null +++ b/submissions/signals.py @@ -0,0 +1,46 @@ +from django.contrib.auth.models import User, Group + +from notifications.signals import notify + + +def notify_new_manuscript_submitted(sender, instance, created, **kwargs): + """ + Notify the Editorial Administration about a new Submission submitted. + """ + if created: + administrators = User.objects.filter(groups__name='Editorial Administrators') + for user in administrators: + notify.send(sender=sender, recipient=user, actor=instance.submitted_by, + verb=' submitted a new manuscript.', target=instance) + + +def notify_new_editorial_recommendation(sender, instance, created, **kwargs): + """ + Notify the Editorial Recommendation about a new Submission submitted. + """ + if created: + administrators = User.objects.filter(groups__name='Editorial Administrators') + editor_in_charge = instance.submission.editor_in_charge + for user in administrators: + notify.send(sender=sender, recipient=user, actor=editor_in_charge, + verb=' formulated a new Editorial Recommendation.', target=instance) + + +def notify_new_editorial_assignment(sender, instance, created, **kwargs): + """ + Notify a College Fellow about a new EIC invitation. + """ + if created: + administration = Group.objects.get(name='Editorial Administrators') + notify.send(sender=sender, recipient=instance.to.user, actor=administration, + verb=' invited you to become Editor-in-charge.', target=instance) + + +def notify_new_referee_invitation(sender, instance, created, **kwargs): + """ + Notify a Referee about a new refereeing invitation. + """ + if created: + notify.send(sender=sender, recipient=instance.referee.user, + actor=instance.submission.editor_in_charge, + verb=' would like to invite you to referee a Submission.', target=instance) diff --git a/submissions/templates/submissions/pool/assignment_request.html b/submissions/templates/submissions/pool/assignment_request.html index a01954b9f109d98ef7b6ce2c5497d07229598fa5..2f0b46cde76c735220de426c609285ce8f891ef8 100644 --- a/submissions/templates/submissions/pool/assignment_request.html +++ b/submissions/templates/submissions/pool/assignment_request.html @@ -13,7 +13,7 @@ {% block pagetitle %}: Assignment Request{% endblock pagetitle %} {% block content %} - <h1>Assignment request</h1> + <h1 class="highlight">Assignment request</h1> <h3>Can you act as Editor-in-charge? (see below to accept/decline)</h3> {% include 'submissions/_submission_assignment_request.html' with assignment=assignment consider_assignment_form=form %}