From dab276bc0a4bdb890d7a356db21abf40fe7311bb Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Tue, 23 May 2017 11:48:51 +0200 Subject: [PATCH] get xml by dc_slug --- apps/catalogue/urls.py | 1 + apps/catalogue/views.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/catalogue/urls.py b/apps/catalogue/urls.py index 7989d2ad..164ec1b5 100644 --- a/apps/catalogue/urls.py +++ b/apps/catalogue/urls.py @@ -37,6 +37,7 @@ urlpatterns = patterns('catalogue.views', permission_required('catalogue.change_book')(GalleryView.as_view()), name="catalogue_book_gallery"), url(r'^book/(?P[^/]+)/xml$', 'book_xml', name="catalogue_book_xml"), + url(r'^book/dc/(?P[^/]+)/xml$', 'book_xml_dc', name="catalogue_book_xml_dc"), url(r'^book/(?P[^/]+)/txt$', 'book_txt', name="catalogue_book_txt"), url(r'^book/(?P[^/]+)/html$', 'book_html', name="catalogue_book_html"), url(r'^book/(?P[^/]+)/epub$', 'book_epub', name="catalogue_book_epub"), diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index b30297cd..e71b3495 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -204,18 +204,27 @@ def upload(request): }) -@never_cache -def book_xml(request, slug): - book = get_object_or_404(Book, slug=slug) +def serve_xml(request, book, slug): if not book.accessible(request): return HttpResponseForbidden("Not authorized.") xml = book.materialize() - response = http.HttpResponse(xml, content_type='application/xml') response['Content-Disposition'] = 'attachment; filename=%s.xml' % slug return response +@never_cache +def book_xml(request, slug): + book = get_object_or_404(Book, slug=slug) + return serve_xml(request, book, slug) + + +@never_cache +def book_xml_dc(request, slug): + book = get_object_or_404(Book, dc_slug=slug) + return serve_xml(request, book, slug) + + @never_cache def book_txt(request, slug): book = get_object_or_404(Book, slug=slug) -- 2.20.1