diff --git a/config/urls.py b/config/urls.py index 4bc3907..35f278f 100644 --- a/config/urls.py +++ b/config/urls.py @@ -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 = [ @@ -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 ) diff --git a/mpicms/publications/views.py b/mpicms/publications/views.py new file mode 100644 index 0000000..9c9bac4 --- /dev/null +++ b/mpicms/publications/views.py @@ -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 ? + # If we don't make DOI into element: + # 2DO: escape invalid characterds in attribute ( " & < ) + # If we don't convert the rich text fields to plain text) + # 2DO: Remove editor artefacts from ricch text fields ("

blabla

") ? + # 2DO: Remove from source fields ("

Mol Cell.

") ? + # maybe use xml.dom for that? + + def get(self, request, *args, **kwargs): + response = HttpResponse(content_type="application/rss+xml; charset=utf-8") + response.write('\n') + response.write('\n') + for item in Publication.objects.order_by('sort_order')[:3]: + response.write(f' \n') + response.write(f' {item.authors}\n'); + response.write(f' {item.title}\n'); + response.write(f' {item.source}\n'); + response.write(f' {item.groups}\n'); + response.write(' \n') + response.write('\n') + return response;