From 9771b4edcbb556927312f624de6263395f82e0ba Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 30 Dec 2011 13:00:25 +0100 Subject: [PATCH] book detail page - now with media / custom pdf --- apps/catalogue/templatetags/catalogue_tags.py | 4 +++ apps/catalogue/urls.py | 3 +- apps/catalogue/views.py | 31 +++++++++++++------ wolnelektury/static/css/book_box.css | 31 ++++++++++++++++--- wolnelektury/static/css/dialogs.css | 8 +++++ .../templates/catalogue/book_wide.html | 19 +++++++++--- 6 files changed, 78 insertions(+), 18 deletions(-) diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index c5b904d40..df938a624 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -291,4 +291,8 @@ def book_wide(book): 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() diff --git a/apps/catalogue/urls.py b/apps/catalogue/urls.py index 4020592d2..dce1b8f10 100644 --- a/apps/catalogue/urls.py +++ b/apps/catalogue/urls.py @@ -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.views import CustomPDFFormView 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/(?Pmp3|ogg|daisy|all).xml$', AudiobookFeed(), name='audiobook_feed'), url(r'^custompdf/(?P%s).pdf' % Book.FILEID_RE, 'download_custom_pdf'), - + url(r'^custompdf$', CustomPDFFormView(), name='custom_pdf_form') ) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 90fe22fd0..d80e570bc 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -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 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, @@ -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_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: @@ -466,7 +467,7 @@ def search(request): 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)) @@ -477,7 +478,7 @@ def tags_starting_with(request): 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 @@ -725,18 +726,18 @@ def download_zip(request, format, book=None): 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) - 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 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')) + + +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) diff --git a/wolnelektury/static/css/book_box.css b/wolnelektury/static/css/book_box.css index 9b589dc52..17330083a 100755 --- a/wolnelektury/static/css/book_box.css +++ b/wolnelektury/static/css/book_box.css @@ -15,6 +15,7 @@ .book-wide-box { width: 98.5em; + margin-left: -0.1em; } .book-mini-box a, .book-box-inner { @@ -40,6 +41,10 @@ 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; @@ -69,6 +74,11 @@ height: 17em; overflow: hidden; } + +.book-wide-box .book-box-body { + height: 21.8em; +} + .book-box-head { min-height: 7em; margin-top: 1.4em; @@ -130,6 +140,10 @@ 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; @@ -186,16 +200,25 @@ ul.book-box-tools { 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; - margin-left: 1.5em; + margin: 6em 0 0 1.5em; } - .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 } + diff --git a/wolnelektury/static/css/dialogs.css b/wolnelektury/static/css/dialogs.css index dc76e6cd8..b3876c39e 100755 --- a/wolnelektury/static/css/dialogs.css +++ b/wolnelektury/static/css/dialogs.css @@ -85,3 +85,11 @@ width: 21em; height: 3em; } + +#custom-pdf-window { + width: 24em; +} + +#custom-pdf-window label { + display: inline; +} \ No newline at end of file diff --git a/wolnelektury/templates/catalogue/book_wide.html b/wolnelektury/templates/catalogue/book_wide.html index 1cfde2e14..59abe0f0f 100644 --- a/wolnelektury/templates/catalogue/book_wide.html +++ b/wolnelektury/templates/catalogue/book_wide.html @@ -12,12 +12,12 @@

{% trans "See" %}

-

{% trans "Download" %}

-

{% trans "Download all audiobooks for this book" %}

+
    +
  • + {% if has_media.mp3 or has_media.ogg %} + {% trans "Download all audiobooks for this book" %}: + {% if has_media.mp3 %}MP3{% endif %}{% if has_media.mp4 and has_media.ogg %},{% endif %} + {% if has_media.ogg %}OGG{% endif %}. + {% endif %} +
  • +
  • + {% trans "Download a custom PDF" %} +
  • +
{% endblock %} -- 2.20.1