Source code for journals.managers

__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"


from django.db import models
from django.utils import timezone

from .constants import (
    STATUS_DRAFT,
    STATUS_PUBLICLY_OPEN,
    STATUS_PUBLISHED,
    PUBLICATION_PUBLISHED,
    ISSUES_AND_VOLUMES,
    ISSUES_ONLY,
    INDIVIDUAL_PUBLICATIONS,
)


[docs]class JournalQuerySet(models.QuerySet):
[docs] def active(self): return self.filter(active=True)
[docs] def submission_allowed(self): return self.filter(submission_allowed=True)
[docs] def has_issues(self): return self.filter(structure__in=(ISSUES_AND_VOLUMES, ISSUES_ONLY))
[docs] def has_individual_publications(self): return self.filter(structure=INDIVIDUAL_PUBLICATIONS)
[docs]class IssueQuerySet(models.QuerySet):
[docs] def open_or_published(self): return self.filter( models.Q(status=STATUS_PUBLICLY_OPEN) | models.Q(status=STATUS_PUBLISHED) )
[docs] def published(self): return self.filter(status=STATUS_PUBLISHED)
[docs] def in_draft(self): return self.filter(status=STATUS_DRAFT)
[docs] def for_journal(self, journal_name): return self.filter( models.Q(in_volume__in_journal__name=journal_name) | models.Q(in_journal__name=journal_name) )
[docs] def get_current_issue(self): return self.published( start_date__lte=timezone.now(), until_date__gte=timezone.now() ).first()
[docs]class PublicationQuerySet(models.QuerySet):
[docs] def published(self): return self.filter(status=PUBLICATION_PUBLISHED).filter( models.Q(in_issue__status=STATUS_PUBLISHED) | models.Q(in_journal__active=True) )
[docs] def unpublished(self): return self.exclude(status=PUBLICATION_PUBLISHED)
[docs] def in_draft(self): return self.filter(in_issue__status=STATUS_DRAFT)
[docs] def drafts(self): return self.filter(status=STATUS_DRAFT)
[docs] def for_specialty(self, specialty): return self.filter(specialties__slug=specialty)
[docs] def for_journal(self, journal_name): return self.filter( models.Q(in_issue__in_volume__in_journal__name=journal_name) | models.Q(in_issue__in_journal__name=journal_name) | models.Q(in_journal__name=journal_name) )
[docs] def most_cited(self, n_returns=5): return self.order_by("-number_of_citations")[:n_returns]