book detail page - now with media / custom pdf
authorMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Fri, 30 Dec 2011 12:00:25 +0000 (13:00 +0100)
committerMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Fri, 30 Dec 2011 12:00:25 +0000 (13:00 +0100)
apps/catalogue/templatetags/catalogue_tags.py
apps/catalogue/urls.py
apps/catalogue/views.py
wolnelektury/static/css/book_box.css
wolnelektury/static/css/dialogs.css
wolnelektury/templates/catalogue/book_wide.html

index c5b904d..df938a6 100644 (file)
@@ -291,4 +291,8 @@ def book_wide(book):
 
     extra_info = book.get_extra_info_value()
 
 
     extra_info = book.get_extra_info_value()
 
+    has_media = {}
+    for media_format in ['mp3', 'ogg']:
+        has_media[media_format] = book.has_media(media_format)
+
     return locals()
     return locals()
index 4020592..dce1b8f 100644 (file)
@@ -6,6 +6,7 @@ from django.conf.urls.defaults import *
 from catalogue.feeds import AudiobookFeed
 from catalogue.models import Book
 from picture.models import Picture
 from catalogue.feeds import AudiobookFeed
 from catalogue.models import Book
 from picture.models import Picture
+from catalogue.views import CustomPDFFormView
 
 urlpatterns = patterns('picture.views',
                        # pictures - currently pictures are coupled with catalogue, hence the url is here
 
 urlpatterns = patterns('picture.views',
                        # pictures - currently pictures are coupled with catalogue, hence the url is here
@@ -47,5 +48,5 @@ urlpatterns = patterns('picture.views',
     url(r'^audiobooki/(?P<type>mp3|ogg|daisy|all).xml$', AudiobookFeed(), name='audiobook_feed'),
 
     url(r'^custompdf/(?P<book_fileid>%s).pdf' % Book.FILEID_RE, 'download_custom_pdf'),
     url(r'^audiobooki/(?P<type>mp3|ogg|daisy|all).xml$', AudiobookFeed(), name='audiobook_feed'),
 
     url(r'^custompdf/(?P<book_fileid>%s).pdf' % Book.FILEID_RE, 'download_custom_pdf'),
-
+    url(r'^custompdf$', CustomPDFFormView(), name='custom_pdf_form')
 ) 
 ) 
index 90fe22f..d80e570 100644 (file)
@@ -23,7 +23,8 @@ from django.utils import translation
 from django.utils.translation import ugettext as _
 from django.views.generic.list_detail import object_list
 
 from django.utils.translation import ugettext as _
 from django.views.generic.list_detail import object_list
 
-from ajaxable.utils import LazyEncoder, JSONResponse
+from ajaxable.utils import LazyEncoder, JSONResponse, AjaxableFormView
+
 from catalogue import models
 from catalogue import forms
 from catalogue.utils import (split_tags, AttachmentHttpResponse,
 from catalogue import models
 from catalogue import forms
 from catalogue.utils import (split_tags, AttachmentHttpResponse,
@@ -207,12 +208,12 @@ def book_detail(request, book):
         book = models.Book.objects.get(**kwargs)
     except models.Book.DoesNotExist:
         return pdcounter_views.book_stub_detail(request, kwargs['slug'])
         book = models.Book.objects.get(**kwargs)
     except models.Book.DoesNotExist:
         return pdcounter_views.book_stub_detail(request, kwargs['slug'])
-    
+
     book_tag = book.book_tag()
     tags = list(book.tags.filter(~Q(category='set')))
     categories = split_tags(tags)
     book_children = book.children.all().order_by('parent_number', 'sort_key')
     book_tag = book.book_tag()
     tags = list(book.tags.filter(~Q(category='set')))
     categories = split_tags(tags)
     book_children = book.children.all().order_by('parent_number', 'sort_key')
-    
+
     _book = book
     parents = []
     while _book.parent:
     _book = book
     parents = []
     while _book.parent:
@@ -466,7 +467,7 @@ def search(request):
             context_instance=RequestContext(request))
     else:
         form = PublishingSuggestForm(initial={"books": prefix + ", "})
             context_instance=RequestContext(request))
     else:
         form = PublishingSuggestForm(initial={"books": prefix + ", "})
-        return render_to_response('catalogue/search_no_hits.html', 
+        return render_to_response('catalogue/search_no_hits.html',
             {'tags':tag_list, 'prefix':prefix, "pubsuggest_form": form},
             context_instance=RequestContext(request))
 
             {'tags':tag_list, 'prefix':prefix, "pubsuggest_form": form},
             context_instance=RequestContext(request))
 
@@ -477,7 +478,7 @@ def tags_starting_with(request):
     if len(prefix) < 2:
         return HttpResponse('')
     tags_list = []
     if len(prefix) < 2:
         return HttpResponse('')
     tags_list = []
-    result = ""   
+    result = ""
     for tag in _tags_starting_with(prefix, request.user):
         if not tag.name in tags_list:
             result += "\n" + tag.name
     for tag in _tags_starting_with(prefix, request.user):
         if not tag.name in tags_list:
             result += "\n" + tag.name
@@ -725,18 +726,18 @@ def download_zip(request, format, book=None):
     return HttpResponseRedirect(urlquote_plus(settings.MEDIA_URL + url, safe='/?='))
 
 
     return HttpResponseRedirect(urlquote_plus(settings.MEDIA_URL + url, safe='/?='))
 
 
-def download_custom_pdf(request, book_fileid):
+def download_custom_pdf(request, book_fileid, method='GET'):
     kwargs = models.Book.split_fileid(book_fileid)
     if kwargs is None:
         raise Http404
     book = get_object_or_404(models.Book, **kwargs)
 
     kwargs = models.Book.split_fileid(book_fileid)
     if kwargs is None:
         raise Http404
     book = get_object_or_404(models.Book, **kwargs)
 
-    if request.method == 'GET':
-        form = forms.CustomPDFForm(request.GET)
+    if request.method == method:
+        form = forms.CustomPDFForm(method == 'GET' and request.GET or request.POST)
         if form.is_valid():
             cust = form.customizations
             pdf_file = models.get_customized_pdf_path(book, cust)
         if form.is_valid():
             cust = form.customizations
             pdf_file = models.get_customized_pdf_path(book, cust)
-                
+
             if not path.exists(pdf_file):
                 result = async_build_pdf.delay(book.id, cust, pdf_file)
                 result.wait()
             if not path.exists(pdf_file):
                 result = async_build_pdf.delay(book.id, cust, pdf_file)
                 result.wait()
@@ -745,3 +746,15 @@ def download_custom_pdf(request, book_fileid):
             raise Http404(_('Incorrect customization options for PDF'))
     else:
         raise Http404(_('Bad method'))
             raise Http404(_('Incorrect customization options for PDF'))
     else:
         raise Http404(_('Bad method'))
+
+
+class CustomPDFFormView(AjaxableFormView):
+    form_class = forms.CustomPDFForm
+    title = _('Download custom PDF')
+    submit = _('Download')
+
+    def __call__(self, request):
+        if request.method == 'POST':
+            return download_custom_pdf(request, request.GET['book_id'], method='POST')
+        else:
+            return super(CustomPDFFormView, self).__call__(request)
index 9b589dc..1733008 100755 (executable)
@@ -15,6 +15,7 @@
 
 .book-wide-box {
     width: 98.5em;
 
 .book-wide-box {
     width: 98.5em;
+    margin-left: -0.1em;
 }
 
 .book-mini-box a, .book-box-inner {
 }
 
 .book-mini-box a, .book-box-inner {
     margin: .5em;
 }
 
     margin: .5em;
 }
 
+.book-wide-box .book-box-inner {
+    height: 24.4em;
+}
+
 .book-mini-box img, .book-box img, .book-wide-box img {
     width: 13.9em;
     height: 19.3em;
 .book-mini-box img, .book-box img, .book-wide-box img {
     width: 13.9em;
     height: 19.3em;
     height: 17em;
     overflow: hidden;
 }
     height: 17em;
     overflow: hidden;
 }
+
+.book-wide-box .book-box-body {
+    height: 21.8em;
+}
+
 .book-box-head {
     min-height: 7em;
     margin-top: 1.4em;
 .book-box-head {
     min-height: 7em;
     margin-top: 1.4em;
     font-size: 1.1em;
 }
 
     font-size: 1.1em;
 }
 
+.book-wide-box .book-box-tools {
+    margin-left: 14em;
+}
+
 .book-box-tools a.downarrow:before {
     content: "\2609";
     font-family: WL-Nav;
 .book-box-tools a.downarrow:before {
     content: "\2609";
     font-family: WL-Nav;
@@ -186,16 +200,25 @@ ul.book-box-tools {
     padding: 0.888em;
 }
 
     padding: 0.888em;
 }
 
+ul.inline-items, ul.inline-items li {
+    margin: 0;
+    padding: 0;
+}
+
+ul.inline-items li {
+    display: inline-block;
+}
+
 .book-wide-box #other-tools {
     float: left;
     width: 14.5em;
 .book-wide-box #other-tools {
     float: left;
     width: 14.5em;
-    margin-left: 1.5em;
+    margin: 6em 0 0 1.5em;
     
 }
 
     
 }
 
-
 .book-wide-box #other-download {
     float: left;
 .book-wide-box #other-download {
     float: left;
-    width 22.5em;
-    margin: 0em 1.5em 0em 1.5em
+    width: 22.5em;
+    margin: 6em 1.5em 0em 1.5em
 }
 }
+
index dc76e6c..b3876c3 100755 (executable)
        width: 21em;
     height: 3em;
 }
        width: 21em;
     height: 3em;
 }
+
+#custom-pdf-window {
+    width: 24em;   
+}
+
+#custom-pdf-window label {
+    display: inline;
+}
\ No newline at end of file
index 1cfde2e..59abe0f 100644 (file)
 
   <div id="other-tools">
     <h2 class="mono">{% trans "See" %}</h2>
 
   <div id="other-tools">
     <h2 class="mono">{% trans "See" %}</h2>
-    <ul>
+    <ul class="inline-items">
       {% if extra_info.source_url %}
       {% if extra_info.source_url %}
-      <li><a href="{{ extra_info.source_url }}">{% trans "Source of the book" %}</a></li>
+      <li><a href="{{ extra_info.source_url }}">{% trans "Source" %}</a> {% trans "of the book" %}</li>
       {% endif %}
       {% if extra_info.about and not hide_about %}
       {% endif %}
       {% if extra_info.about and not hide_about %}
-      <li><a href="{{ extra_info.about }}">{% trans "Book on the Editor's Platform" %}</a></li>
+      <li>{% trans "Book on" %} <a href="{{ extra_info.about }}">{% trans "Editor's Platform" %}</a></li>
       {% endif %}
       {% if book.gazeta_link %}
       <li><a href="{{ book.gazeta_link }}">{% trans "Book description on Lektury.Gazeta.pl" %}</a></li>
       {% endif %}
       {% if book.gazeta_link %}
       <li><a href="{{ book.gazeta_link }}">{% trans "Book description on Lektury.Gazeta.pl" %}</a></li>
   </div>
   <div id="other-download">
     <h2 class="mono">{% trans "Download" %}</h2>
   </div>
   <div id="other-download">
     <h2 class="mono">{% trans "Download" %}</h2>
-    <p>{% trans "Download all audiobooks for this book" %}</p>
+    <ul class="inline-items">
+      <li>
+       {% if has_media.mp3 or has_media.ogg %}
+       {% trans "Download all audiobooks for this book" %}: 
+       {% if has_media.mp3 %}<a href="{% url download_zip_mp3 book.slug %}">MP3</a>{% endif %}{% if has_media.mp4 and has_media.ogg %},{% endif %}
+       {% if has_media.ogg %}<a href="{% url download_zip_ogg book.slug %}">OGG</a>{% endif %}.
+       {% endif %}
+      </li>
+      <li>
+       <a href="{% url custom_pdf_form %}?book_id={{book.fileid}}" id="custom-pdf" class="ajaxable">{% trans "Download a custom PDF" %}</a>
+      </li>
+    </ul>
   </div>
 </div>
 {% endblock %}
   </div>
 </div>
 {% endblock %}