make custom pdf optional
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 26 Apr 2012 09:30:54 +0000 (11:30 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 26 Apr 2012 09:30:54 +0000 (11:30 +0200)
apps/catalogue/templates/catalogue/book_text.html
apps/catalogue/templates/catalogue/book_wide.html
apps/catalogue/templates/catalogue/snippets/custom_pdf_link_li.html [new file with mode: 0644]
apps/catalogue/templatetags/catalogue_tags.py
apps/catalogue/views.py
apps/sponsors/static/sponsors/js/sponsors.js
wolnelektury/settings/custom.py

index e844c96..d2d5d33 100644 (file)
@@ -49,7 +49,7 @@
             {% if book.txt_file %}
             <li><a href="{{ book.txt_file.url}}">TXT</a> {% trans "for advanced usage" %}</li>
             {% endif %}
-            <li><a href="{% url "custom_pdf_form" book.slug %}">{% trans "Download a custom PDF" %}</a></li>
+            {% custom_pdf_link_li book %}
             {% if related.media.mp3 or related.media.ogg or related.media.daisy %}
                 <li>{% trans "Download all audiobooks for this book" %}:
                     {% download_audio book %}</li> 
index 9213560..8d83413 100644 (file)
@@ -1,6 +1,6 @@
 {% extends "catalogue/book_short.html" %}
 {% load i18n %}
-{% load download_audio tag_list from catalogue_tags %}
+{% load download_audio tag_list custom_pdf_link_li from catalogue_tags %}
 {% load cite_promo from social_tags %}
 
 
@@ -60,9 +60,7 @@
            {% download_audio book %}. 
        {% endif %}
       </li>
-      <li>
-       <a href="{% url custom_pdf_form book.slug %}" id="custom-pdf" class="ajaxable">{% trans "Download a custom PDF" %}</a>
-      </li>
+      {% custom_pdf_link_li book %}
     </ul>
   </div>
 </div>
diff --git a/apps/catalogue/templates/catalogue/snippets/custom_pdf_link_li.html b/apps/catalogue/templates/catalogue/snippets/custom_pdf_link_li.html
new file mode 100644 (file)
index 0000000..380844a
--- /dev/null
@@ -0,0 +1,8 @@
+{% load i18n %}
+{% load url from future %}
+{% if not NO_CUSTOM_PDF %}
+<li>
+    <a href="{% url 'custom_pdf_form' book.slug %}" id="custom-pdf"
+        class="ajaxable">{% trans "Download a custom PDF" %}</a>
+</li>
+{% endif %}
index fdd0a73..4f84dad 100644 (file)
@@ -5,6 +5,7 @@
 import datetime
 import feedparser
 
+from django.conf import settings
 from django import template
 from django.template import Node, Variable, Template, Context
 from django.core.cache import cache
@@ -12,7 +13,6 @@ from django.core.urlresolvers import reverse
 from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
 from django.utils.translation import ugettext as _
 
-from catalogue import forms
 from catalogue.utils import split_tags
 from catalogue.models import Book, BookMedia, Fragment, Tag
 
@@ -406,3 +406,11 @@ def download_audio(book, daisy=True):
             links.append("<a href='%s'>%s</a>" %
                 (dsy.file.url, BookMedia.formats['daisy'].name))
     return ", ".join(links)
+
+
+@register.inclusion_tag("catalogue/snippets/custom_pdf_link_li.html")
+def custom_pdf_link_li(book):
+    return {
+        'book': book,
+        'NO_CUSTOM_PDF': settings.NO_CUSTOM_PDF,
+    }
index 599fde1..fc27e02 100644 (file)
@@ -536,6 +536,11 @@ class CustomPDFFormView(AjaxableFormView):
     submit = ugettext_lazy('Download')
     honeypot = True
 
+    def __call__(self, *args, **kwargs):
+        if settings.NO_CUSTOM_PDF:
+            raise Http404('Custom PDF is disabled')
+        return super(CustomPDFFormView, self).__call__(*args, **kwargs)
+
     def form_args(self, request, obj):
         """Override to parse view args and give additional args to the form."""
         return (obj,), {}
index 7674379..fbfbaeb 100755 (executable)
@@ -4,5 +4,5 @@
         $('.sponsor-logos').cycle({timeout: 3000});
 
     });
-})(jQuery)
+})(jQuery);
 
index 552188a..e059b8f 100644 (file)
@@ -9,6 +9,7 @@ NO_BUILD_EPUB = False
 NO_BUILD_TXT = False
 # You'll need XeLaTeX to generate PDF files.
 NO_BUILD_PDF = True
+NO_CUSTOM_PDF = True
 # You'll need Calibre installed to generate MOBI files.
 NO_BUILD_MOBI = True