From: Radek Czajka Date: Thu, 26 Apr 2012 09:30:54 +0000 (+0200) Subject: make custom pdf optional X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/1cfd896963379af2d46a08dde3a3cbb24763066c?hp=69b59e1dc5d93547a298830fc439a5608ebd6596 make custom pdf optional --- diff --git a/apps/catalogue/templates/catalogue/book_text.html b/apps/catalogue/templates/catalogue/book_text.html index e844c96c1..d2d5d330e 100644 --- a/apps/catalogue/templates/catalogue/book_text.html +++ b/apps/catalogue/templates/catalogue/book_text.html @@ -49,7 +49,7 @@ {% if book.txt_file %}
  • TXT {% trans "for advanced usage" %}
  • {% endif %} -
  • {% trans "Download a custom PDF" %}
  • + {% custom_pdf_link_li book %} {% if related.media.mp3 or related.media.ogg or related.media.daisy %}
  • {% trans "Download all audiobooks for this book" %}: {% download_audio book %}
  • diff --git a/apps/catalogue/templates/catalogue/book_wide.html b/apps/catalogue/templates/catalogue/book_wide.html index 921356003..8d8341385 100644 --- a/apps/catalogue/templates/catalogue/book_wide.html +++ b/apps/catalogue/templates/catalogue/book_wide.html @@ -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 %} -
  • - {% trans "Download a custom PDF" %} -
  • + {% custom_pdf_link_li book %} 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 index 000000000..380844adb --- /dev/null +++ b/apps/catalogue/templates/catalogue/snippets/custom_pdf_link_li.html @@ -0,0 +1,8 @@ +{% load i18n %} +{% load url from future %} +{% if not NO_CUSTOM_PDF %} +
  • + {% trans "Download a custom PDF" %} +
  • +{% endif %} diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index fdd0a73d2..4f84dadca 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -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("%s" % (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, + } diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 599fde1cb..fc27e02f3 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -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,), {} diff --git a/apps/sponsors/static/sponsors/js/sponsors.js b/apps/sponsors/static/sponsors/js/sponsors.js index 7674379fe..fbfbaebb3 100755 --- a/apps/sponsors/static/sponsors/js/sponsors.js +++ b/apps/sponsors/static/sponsors/js/sponsors.js @@ -4,5 +4,5 @@ $('.sponsor-logos').cycle({timeout: 3000}); }); -})(jQuery) +})(jQuery); diff --git a/wolnelektury/settings/custom.py b/wolnelektury/settings/custom.py index 552188a6f..e059b8f9a 100644 --- a/wolnelektury/settings/custom.py +++ b/wolnelektury/settings/custom.py @@ -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