|
1 | 1 | # Copyright The IETF Trust 2007, All Rights Reserved |
2 | 2 |
|
3 | 3 | from django.contrib.syndication.views import Feed, FeedDoesNotExist |
4 | | -from django.utils.feedgenerator import Atom1Feed |
| 4 | +from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed |
5 | 5 | from django.core.urlresolvers import reverse as urlreverse |
6 | 6 | from django.template.defaultfilters import truncatewords, truncatewords_html, date as datefilter, linebreaks |
7 | 7 | from django.utils.html import strip_tags |
8 | 8 |
|
9 | | -from ietf.doc.models import Document, State, LastCallDocEvent |
| 9 | +from ietf.doc.models import Document, State, LastCallDocEvent, DocEvent |
10 | 10 | from ietf.doc.utils import augment_events_with_revision |
11 | 11 | from ietf.doc.templatetags.ietf_filters import format_textarea |
12 | 12 |
|
@@ -75,3 +75,78 @@ def item_description(self, item): |
75 | 75 | def item_pubdate(self, item): |
76 | 76 | return item.lc_event.time |
77 | 77 |
|
| 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 | + |
0 commit comments