diff --git a/config/urls.py b/config/urls.py index 35f278f..620dfdd 100644 --- a/config/urls.py +++ b/config/urls.py @@ -15,6 +15,7 @@ from mpicms.personal.views import ContactListView, RawContactListView from mpicms.events.views import ics_view from mpicms.publications.views import PublicationsFeedView +from mpicms.publications.views import PublicationsRssFeedView urlpatterns = [ @@ -48,7 +49,8 @@ path('contactsraw/', RawContactListView.as_view(), name='contactsraw'), path('events/ics', ics_view, name='ics'), - path('feed/last_publications', PublicationsFeedView.as_view()), + path('feed/last_publications_xml', PublicationsFeedView.as_view()), + path('feed/last_publications', PublicationsRssFeedView.as_view()), ] + static( settings.MEDIA_URL, document_root=settings.MEDIA_ROOT ) diff --git a/mpicms/publications/models.py b/mpicms/publications/models.py index 5e157e9..de164ec 100644 --- a/mpicms/publications/models.py +++ b/mpicms/publications/models.py @@ -10,14 +10,17 @@ from modelcluster.models import ClusterableModel + class LatestFirstOrderable(Orderable): def save(self, *args, **kwargs): if self.pk is None: self.sort_order = self.__class__.objects.aggregate(models.Min('sort_order'))['sort_order__min'] - 1 super(Orderable, self).save(*args, **kwargs) + class Meta: abstract = True + @register_snippet class Publication(index.Indexed, ClusterableModel, LatestFirstOrderable): title = RichTextField(_('title'), features=['bold', 'italic', 'link']) diff --git a/mpicms/publications/views.py b/mpicms/publications/views.py index 9c9bac4..fc3dd5e 100644 --- a/mpicms/publications/views.py +++ b/mpicms/publications/views.py @@ -3,16 +3,22 @@ from .models import Publication + class PublicationsFeedView(View): + # IMPORTANT: Quick hack to get experiments going, This assumes, that the + # editor of the publications is trusted to put only expected values into the + # fields. + # # 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: escape invalid characterds in attribute ( " & < > ) + # If we don't convert the rich text fields to plain text maybe: + # 2DO: Remove

editor artefacts from rich text fields ("

blabla

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

Mol Cell.

") ? # maybe use xml.dom for that? + # 2DO: ... ? def get(self, request, *args, **kwargs): response = HttpResponse(content_type="application/rss+xml; charset=utf-8") @@ -20,10 +26,49 @@ def get(self, request, *args, **kwargs): 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(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; + return response + + +class PublicationsRssFeedView(View): + + # IMPORTANT: Quick hack to get experiments going, This assumes, that the + # editor of the publications is trusted to put only expected values into the + # fields. + # + # 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 maybe: + # 2DO: Remove

editor artefacts from rich text fields ("

blabla

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

Mol Cell.

") ? + # maybe use xml.dom for that? + # 2DO: ... ? + + def get(self, request, *args, **kwargs): + response = HttpResponse(content_type="application/rss+xml; charset=utf-8") + response.write('\n') + response.write('\n') + response.write(' \n') + # the next three elements are required https://www.rssboard.org/rss-specification + response.write(' Last Three Publications\n') + response.write(' https://intranet.molgen.mpg.de/\n') + response.write(' The last three publications published on the Intranet site\n') + for item in Publication.objects.order_by('sort_order')[:3]: + # all elements optional, but either title or description allowed + response.write(f' \n') + response.write(f' {item.title}\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') + response.write('\n') + return response