Source code for scipost.feeds
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
import datetime
from django.contrib.syndication.views import Feed
from django.http import Http404
from django.utils.feedgenerator import Atom1Feed
from django.urls import reverse
from django.db.models import Q
from careers.models import JobOpening
from comments.models import Comment
from commentaries.models import Commentary
from journals.models import Publication
from news.models import NewsItem
from submissions.models import Submission
from theses.models import ThesisLink
[docs]class LatestCommentsFeedRSS(Feed):
title = "SciPost: Latest Comments"
description = "SciPost: Latest Comments"
link = "/comments/"
[docs] def item_link(self, item):
if isinstance(item.content_object, Commentary):
return reverse(
"commentaries:commentary",
kwargs={"arxiv_or_DOI_string": item.content_object.arxiv_or_DOI_string},
)
elif isinstance(item.content_object, Submission):
return reverse(
"submissions:submission",
kwargs={
"identifier_w_vn_nr": item.content_object.preprint.identifier_w_vn_nr
},
)
elif isinstance(item.content_object, ThesisLink):
return reverse(
"theses:thesis", kwargs={"thesislink_id": item.thesislink.id}
)
else:
return reverse("scipost:index")
[docs]class LatestCommentsFeedAtom(LatestCommentsFeedRSS):
feed_type = Atom1Feed
subtitle = LatestCommentsFeedRSS.description
[docs]class LatestNewsFeedRSS(Feed):
title = "SciPost: Latest News"
link = "/news/"
description = "SciPost: recent news and announcements"
[docs]class LatestNewsFeedAtom(LatestNewsFeedRSS):
feed_type = Atom1Feed
subtitle = LatestNewsFeedRSS.description
[docs] def item_updateddate(self, item):
return datetime.datetime(item.date.year, item.date.month, item.date.day)
[docs]class LatestSubmissionsFeedRSS(Feed):
title_template = "feeds/latest_submissions_title.html"
description_template = "feeds/latest_submissions_description.html"
link = "/submissions/"
[docs] def get_object(self, request, specialty=None):
if specialty:
queryset = (
Submission.objects.filter(specialties=specialty)
.filter(visible_public=True)
.order_by("-submission_date")[:10]
)
queryset.specialty = specialty
else:
queryset = Submission.objects.filter(visible_public=True).order_by(
"-submission_date"
)[:10]
queryset.specialty = None
return queryset
[docs] def title(self, obj):
title_text = "SciPost: Latest Submissions"
if obj.specialty:
title_text += " in %s" % obj.specialty.name
return title_text
[docs] def description(self, obj):
desc = "SciPost: most recent submissions"
if obj.specialty:
desc += " in %s" % obj.specialty.name
return desc
[docs] def item_link(self, item):
return reverse(
"submissions:submission",
kwargs={"identifier_w_vn_nr": item.preprint.identifier_w_vn_nr},
)
[docs]class LatestSubmissionsFeedAtom(LatestSubmissionsFeedRSS):
feed_type = Atom1Feed
subtitle = LatestSubmissionsFeedRSS.description
[docs] def item_updateddate(self, item):
return datetime.datetime(
item.submission_date.year,
item.submission_date.month,
item.submission_date.day,
)
[docs]class LatestPublicationsFeedRSS(Feed):
title_template = "feeds/latest_publications_title.html"
description_template = "feeds/latest_publications_description.html"
link = "/journals/"
[docs] def get_object(self, request, specialty=None):
qs = Publication.objects.published()
if specialty:
qs = qs.filter(specialties=specialty)
self.specialty = specialty
return qs.order_by("-publication_date")[:10]
[docs] def title(self, obj):
title_text = "SciPost: Latest Publications"
if self.specialty:
title_text += " in %s" % self.specialty.name
return title_text
[docs] def description(self, obj):
desc = "SciPost: most recent publications"
if self.specialty:
desc += " in %s" % self.specialty.name
return desc
[docs]class LatestPublicationsFeedAtom(LatestPublicationsFeedRSS):
feed_type = Atom1Feed
subtitle = LatestPublicationsFeedRSS.description
[docs] def item_updateddate(self, item):
return datetime.datetime(
item.publication_date.year,
item.publication_date.month,
item.publication_date.day,
)