From ada7e48ed47c0a85ef86b3c4da6c918fdfed768d Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Fri, 23 Oct 2015 19:15:55 +0000 Subject: [PATCH] Framework in place, most of the details worked out - Legacy-Id: 10275 --- ietf/doc/feeds.py | 79 +++++++++++++++++++++++++++++++++++++++++++++-- ietf/feed_urls.py | 3 +- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/ietf/doc/feeds.py b/ietf/doc/feeds.py index 80fcbc861..bb969a03c 100644 --- a/ietf/doc/feeds.py +++ b/ietf/doc/feeds.py @@ -1,12 +1,12 @@ # Copyright The IETF Trust 2007, All Rights Reserved from django.contrib.syndication.views import Feed, FeedDoesNotExist -from django.utils.feedgenerator import Atom1Feed +from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed from django.core.urlresolvers import reverse as urlreverse from django.template.defaultfilters import truncatewords, truncatewords_html, date as datefilter, linebreaks from django.utils.html import strip_tags -from ietf.doc.models import Document, State, LastCallDocEvent +from ietf.doc.models import Document, State, LastCallDocEvent, DocEvent from ietf.doc.utils import augment_events_with_revision from ietf.doc.templatetags.ietf_filters import format_textarea @@ -75,3 +75,78 @@ class InLastCallFeed(Feed): def item_pubdate(self, item): return item.lc_event.time +class Rss201WithNamespacesFeed(Rss201rev2Feed): + def root_attributes(self): + attrs = super(Rss201WithNamespacesFeed, self).root_attributes() + attrs['xmlns:dcterms'] = 'http://purl.org/dc/terms/' + attrs['xmlns:media'] = 'http://search.yahoo.com/mrss/' + attrs['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance' + return attrs + + def add_item_elements(self, handler, item): + super(Rss201WithNamespacesFeed, self).add_item_elements(handler, item) + + for element_name in ['abstract','accessRights', 'format', ]: + dc_item_name = 'dcterms_%s' % element_name + dc_element_name = 'dcterms:%s' % element_name + if dc_item_name in item and item[dc_item_name] is not None: + handler.addQuickElement(dc_element_name,item[dc_item_name]) + + if 'doi' in item and item['doi'] is not None: + handler.addQuickElement('dcterms:identifier',item['doi'],{'xsi:type':'dcterms:doi'}) + + if 'media_content' in item and item['media_content'] is not None: + handler.startElement('media:content',{'url':item['media_content']['url'],'type':'text/plain'}) + handler.addQuickElement('dcterms:isFormatOf',item['media_content']['link_url']) + handler.endElement('media:content') + +class RfcFeed(Feed): + feed_type = Rss201WithNamespacesFeed + title = "RFCs" + author_name = "RFC Editor" + link = "https://www.rfc-editor.org/rfc-index2.html" + + def items(self): + rfc_events = DocEvent.objects.filter(type='published_rfc').order_by('-time') + results = [(e.doc, e.time) for e in rfc_events[:5]] + for doc,time in results: + doc.publication_time = time + return [doc for doc,time in results] + + def item_title(self, item): + return item.canonical_name() + + def item_description(self, item): + return item.title + + def item_link(self, item): + return "https://rfc-editor.org/info/%s"%item.canonical_name() + + def item_pubdate(self, item): + return item.publication_time + + def item_extra_kwargs(self, item): + extra = super(RfcFeed, self).item_extra_kwargs(item) + extra.update({'dcterms_abstract': item.abstract}) + extra.update({'dcterms_accessRights': 'gratis'}) + extra.update({'dcterms_format': 'text/html'}) + extra.update({'media_content': {'url': 'https://rfc-editor.org/rfc/%s.txt' % item.canonical_name(), + 'link_url': self.item_link(item) + } + }) + extra.update({'doi':'http://dx.doi.org/10.17487/%s' % item.canonical_name().upper()}) + + #TODO + # R104 Publisher (Mandatory - but we need a string from them first) + + #TODO MAYBE (Optional stuff) + # R108 License + # R115 Creator/Contributor (which would we use?) + # F305 Checksum (do they use it?) (or should we put the our digital signature in here somewhere?) + # F308 Holder of rights (copyright) + + # Stuff we can't do yet given what's in the datatracker + # R118 Keyword + + return extra + diff --git a/ietf/feed_urls.py b/ietf/feed_urls.py index eea94dc7b..b46ddbe2d 100644 --- a/ietf/feed_urls.py +++ b/ietf/feed_urls.py @@ -1,7 +1,7 @@ from django.conf.urls import patterns from django.views.generic import RedirectView -from ietf.doc.feeds import DocumentChangesFeed, InLastCallFeed +from ietf.doc.feeds import DocumentChangesFeed, InLastCallFeed, RfcFeed from ietf.group.feeds import GroupChangesFeed from ietf.iesg.feeds import IESGAgendaFeed from ietf.ipr.feeds import LatestIprDisclosuresFeed @@ -18,4 +18,5 @@ urlpatterns = patterns( (r'^ipr/$', LatestIprDisclosuresFeed()), (r'^liaison/(?Precent|from|to|subject)/(?:(?P[^/]+)/)?$', LiaisonStatementsFeed()), (r'^wg-proceedings/$', LatestMeetingMaterialFeed()), + (r'^rfc/$', RfcFeed()) )