Skip to content

publications: Add XML feed for last publications #119

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from mpicms.base.api import api_router
from mpicms.personal.views import ContactListView, RawContactListView
from mpicms.events.views import ics_view
from mpicms.publications.views import PublicationsFeedView


urlpatterns = [
Expand Down Expand Up @@ -46,7 +47,8 @@
path('contacts/', ContactListView.as_view(), name='contacts'),
path('contactsraw/', RawContactListView.as_view(), name='contactsraw'),

path('events/ics', ics_view, name='ics')
path('events/ics', ics_view, name='ics'),
path('feed/last_publications', PublicationsFeedView.as_view()),
] + static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
)
Expand Down
29 changes: 29 additions & 0 deletions mpicms/publications/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.http import HttpResponse
from django.views.generic.base import View

from .models import Publication

class PublicationsFeedView(View):

# 2DO: check for legal XML characters everywhere https://www.w3.org/TR/xml/#NT-Char
# 2DO: Put HTML content in <![CDATA[...]]> ?
# If we don't make DOI into element:
# 2DO: escape invalid characterds in attribute ( &quot; &amp; &lt; )
# If we don't convert the rich text fields to plain text)
# 2DO: Remove editor artefacts from ricch text fields ("<p>blabla</p>") ?
# 2DO: Remove <i> from source fields ("<p><i>Mol Cell.</i></p>") ?
# maybe use xml.dom for that?

def get(self, request, *args, **kwargs):
response = HttpResponse(content_type="application/rss+xml; charset=utf-8")
response.write('<?xml version="1.0" encoding="utf-8" ?>\n')
response.write('<publication-list>\n')
for item in Publication.objects.order_by('sort_order')[:3]:
response.write(f' <publication doi="{item.doi}">\n')
response.write(f' <authors>{item.authors}</authors>\n');
response.write(f' <title>{item.title}</title>\n');
response.write(f' <source>{item.source}</source>\n');
response.write(f' <groups>{item.groups}</groups>\n');
response.write(' </publication>\n')
response.write('</publication-list>\n')
return response;