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 items(self): return Comment.objects.vetted().order_by("-date_submitted")[:10]
[docs] def item_title(self, item): return item.comment_text[:50]
[docs] def item_description(self, item): return item.comment_text[:50]
[docs]class LatestCommentsFeedAtom(LatestCommentsFeedRSS): feed_type = Atom1Feed subtitle = LatestCommentsFeedRSS.description
[docs] def author_name(self): return "SciPost"
[docs] def item_updateddate(self, item): return item.date_submitted
[docs]class LatestNewsFeedRSS(Feed): title = "SciPost: Latest News" link = "/news/" description = "SciPost: recent news and announcements"
[docs] def items(self): return NewsItem.objects.homepage().order_by("-date")[:5]
[docs] def item_title(self, item): return item.headline
[docs] def item_description(self, item): return item.blurb
[docs]class LatestNewsFeedAtom(LatestNewsFeedRSS): feed_type = Atom1Feed subtitle = LatestNewsFeedRSS.description
[docs] def author_name(self): return "SciPost"
[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 items(self, obj): return obj
[docs]class LatestSubmissionsFeedAtom(LatestSubmissionsFeedRSS): feed_type = Atom1Feed subtitle = LatestSubmissionsFeedRSS.description
[docs] def author_name(self): return "SciPost"
[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] def items(self, obj): return obj
[docs]class LatestPublicationsFeedAtom(LatestPublicationsFeedRSS): feed_type = Atom1Feed subtitle = LatestPublicationsFeedRSS.description
[docs] def author_name(self): return "SciPost"
[docs] def item_updateddate(self, item): return datetime.datetime( item.publication_date.year, item.publication_date.month, item.publication_date.day, )
[docs]class DjangoJobOpeningsFeedRSS(Feed): title = "SciPost: Dev Jobs" link = "/careers/django/" description = "SciPost: Django dev job openings"
[docs] def items(self): return JobOpening.objects.publicly_visible().filter( description__icontains="django" )
[docs] def item_title(self, item): return item.title
[docs] def item_description(self, item): return item.short_description