Skip to content

Commit ada7e48

Browse files
committed
Framework in place, most of the details worked out
- Legacy-Id: 10275
1 parent effd727 commit ada7e48

2 files changed

Lines changed: 79 additions & 3 deletions

File tree

ietf/doc/feeds.py

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Copyright The IETF Trust 2007, All Rights Reserved
22

33
from django.contrib.syndication.views import Feed, FeedDoesNotExist
4-
from django.utils.feedgenerator import Atom1Feed
4+
from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed
55
from django.core.urlresolvers import reverse as urlreverse
66
from django.template.defaultfilters import truncatewords, truncatewords_html, date as datefilter, linebreaks
77
from django.utils.html import strip_tags
88

9-
from ietf.doc.models import Document, State, LastCallDocEvent
9+
from ietf.doc.models import Document, State, LastCallDocEvent, DocEvent
1010
from ietf.doc.utils import augment_events_with_revision
1111
from ietf.doc.templatetags.ietf_filters import format_textarea
1212

@@ -75,3 +75,78 @@ def item_description(self, item):
7575
def item_pubdate(self, item):
7676
return item.lc_event.time
7777

78+
class Rss201WithNamespacesFeed(Rss201rev2Feed):
79+
def root_attributes(self):
80+
attrs = super(Rss201WithNamespacesFeed, self).root_attributes()
81+
attrs['xmlns:dcterms'] = 'http://purl.org/dc/terms/'
82+
attrs['xmlns:media'] = 'http://search.yahoo.com/mrss/'
83+
attrs['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance'
84+
return attrs
85+
86+
def add_item_elements(self, handler, item):
87+
super(Rss201WithNamespacesFeed, self).add_item_elements(handler, item)
88+
89+
for element_name in ['abstract','accessRights', 'format', ]:
90+
dc_item_name = 'dcterms_%s' % element_name
91+
dc_element_name = 'dcterms:%s' % element_name
92+
if dc_item_name in item and item[dc_item_name] is not None:
93+
handler.addQuickElement(dc_element_name,item[dc_item_name])
94+
95+
if 'doi' in item and item['doi'] is not None:
96+
handler.addQuickElement('dcterms:identifier',item['doi'],{'xsi:type':'dcterms:doi'})
97+
98+
if 'media_content' in item and item['media_content'] is not None:
99+
handler.startElement('media:content',{'url':item['media_content']['url'],'type':'text/plain'})
100+
handler.addQuickElement('dcterms:isFormatOf',item['media_content']['link_url'])
101+
handler.endElement('media:content')
102+
103+
class RfcFeed(Feed):
104+
feed_type = Rss201WithNamespacesFeed
105+
title = "RFCs"
106+
author_name = "RFC Editor"
107+
link = "https://www.rfc-editor.org/rfc-index2.html"
108+
109+
def items(self):
110+
rfc_events = DocEvent.objects.filter(type='published_rfc').order_by('-time')
111+
results = [(e.doc, e.time) for e in rfc_events[:5]]
112+
for doc,time in results:
113+
doc.publication_time = time
114+
return [doc for doc,time in results]
115+
116+
def item_title(self, item):
117+
return item.canonical_name()
118+
119+
def item_description(self, item):
120+
return item.title
121+
122+
def item_link(self, item):
123+
return "https://rfc-editor.org/info/%s"%item.canonical_name()
124+
125+
def item_pubdate(self, item):
126+
return item.publication_time
127+
128+
def item_extra_kwargs(self, item):
129+
extra = super(RfcFeed, self).item_extra_kwargs(item)
130+
extra.update({'dcterms_abstract': item.abstract})
131+
extra.update({'dcterms_accessRights': 'gratis'})
132+
extra.update({'dcterms_format': 'text/html'})
133+
extra.update({'media_content': {'url': 'https://rfc-editor.org/rfc/%s.txt' % item.canonical_name(),
134+
'link_url': self.item_link(item)
135+
}
136+
})
137+
extra.update({'doi':'http://dx.doi.org/10.17487/%s' % item.canonical_name().upper()})
138+
139+
#TODO
140+
# R104 Publisher (Mandatory - but we need a string from them first)
141+
142+
#TODO MAYBE (Optional stuff)
143+
# R108 License
144+
# R115 Creator/Contributor (which would we use?)
145+
# F305 Checksum (do they use it?) (or should we put the our digital signature in here somewhere?)
146+
# F308 Holder of rights (copyright)
147+
148+
# Stuff we can't do yet given what's in the datatracker
149+
# R118 Keyword
150+
151+
return extra
152+

ietf/feed_urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.conf.urls import patterns
22
from django.views.generic import RedirectView
33

4-
from ietf.doc.feeds import DocumentChangesFeed, InLastCallFeed
4+
from ietf.doc.feeds import DocumentChangesFeed, InLastCallFeed, RfcFeed
55
from ietf.group.feeds import GroupChangesFeed
66
from ietf.iesg.feeds import IESGAgendaFeed
77
from ietf.ipr.feeds import LatestIprDisclosuresFeed
@@ -18,4 +18,5 @@
1818
(r'^ipr/$', LatestIprDisclosuresFeed()),
1919
(r'^liaison/(?P<kind>recent|from|to|subject)/(?:(?P<search>[^/]+)/)?$', LiaisonStatementsFeed()),
2020
(r'^wg-proceedings/$', LatestMeetingMaterialFeed()),
21+
(r'^rfc/$', RfcFeed())
2122
)

0 commit comments

Comments
 (0)