get xml by dc_slug
authorJan Szejko <janek37@gmail.com>
Tue, 23 May 2017 09:48:51 +0000 (11:48 +0200)
committerJan Szejko <janek37@gmail.com>
Tue, 23 May 2017 09:48:51 +0000 (11:48 +0200)
apps/catalogue/urls.py
apps/catalogue/views.py

index 7989d2a..164ec1b 100644 (file)
@@ -37,6 +37,7 @@ urlpatterns = patterns('catalogue.views',
             permission_required('catalogue.change_book')(GalleryView.as_view()),
             name="catalogue_book_gallery"),
     url(r'^book/(?P<slug>[^/]+)/xml$', 'book_xml', name="catalogue_book_xml"),
             permission_required('catalogue.change_book')(GalleryView.as_view()),
             name="catalogue_book_gallery"),
     url(r'^book/(?P<slug>[^/]+)/xml$', 'book_xml', name="catalogue_book_xml"),
+    url(r'^book/dc/(?P<slug>[^/]+)/xml$', 'book_xml_dc', name="catalogue_book_xml_dc"),
     url(r'^book/(?P<slug>[^/]+)/txt$', 'book_txt', name="catalogue_book_txt"),
     url(r'^book/(?P<slug>[^/]+)/html$', 'book_html', name="catalogue_book_html"),
     url(r'^book/(?P<slug>[^/]+)/epub$', 'book_epub', name="catalogue_book_epub"),
     url(r'^book/(?P<slug>[^/]+)/txt$', 'book_txt', name="catalogue_book_txt"),
     url(r'^book/(?P<slug>[^/]+)/html$', 'book_html', name="catalogue_book_html"),
     url(r'^book/(?P<slug>[^/]+)/epub$', 'book_epub', name="catalogue_book_epub"),
index b30297c..e71b349 100644 (file)
@@ -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()
     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
 
 
     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)
 @never_cache
 def book_txt(request, slug):
     book = get_object_or_404(Book, slug=slug)