X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d91551345b68c2bc7d96f2098691fab28276d6b8..dd549d9f4b46da1b7a42145f571c746f3831953e:/apps/catalogue/views.py diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 44a01479d..9168099ca 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -129,27 +129,6 @@ def daisy_list(request): template_name='catalogue/daisy_list.html') -def counters(request): - form = forms.SearchForm() - - books = models.Book.objects.count() - books_nonempty = models.Book.objects.exclude(html_file='').count() - books_empty = models.Book.objects.filter(html_file='').count() - books_root = models.Book.objects.filter(parent=None).count() - - media = models.BookMedia.objects.count() - media_types = models.BookMedia.objects.values('type').\ - annotate(count=Count('type')).\ - order_by('type') - for mt in media_types: - mt['size'] = sum(b.file.size for b in models.BookMedia.objects.filter(type=mt['type'])) - mt['deprecated'] = models.BookMedia.objects.filter( - type=mt['type'], source_sha1=None).count() if mt['type'] in ('mp3', 'ogg') else '-' - - return render_to_response('catalogue/counters.html', - locals(), context_instance=RequestContext(request)) - - def differentiate_tags(request, tags, ambiguous_slugs): beginning = '/'.join(tag.url_chunk for tag in tags) unparsed = '/'.join(ambiguous_slugs[1:]) @@ -293,6 +272,7 @@ def book_detail(request, slug): tag.count = theme_counter[tag.pk] extra_info = book.get_extra_info_value() + hide_about = extra_info.get('about', '').startswith('http://wiki.wolnepodreczniki.pl') projects = set() for m in book.media.filter(type='mp3'): @@ -626,7 +606,7 @@ def download_shelf(request, slug): if form.is_valid(): formats = form.cleaned_data['formats'] if len(formats) == 0: - formats = ['pdf', 'epub', 'odt', 'txt'] + formats = ['pdf', 'epub', 'mobi', 'odt', 'txt'] # Create a ZIP archive temp = tempfile.TemporaryFile() @@ -637,6 +617,9 @@ def download_shelf(request, slug): if 'pdf' in formats and book.pdf_file: filename = book.pdf_file.path archive.write(filename, str('%s.pdf' % book.slug)) + if 'mobi' in formats and book.mobi_file: + filename = book.mobi_file.path + archive.write(filename, str('%s.mobi' % book.slug)) if book.root_ancestor not in already and 'epub' in formats and book.root_ancestor.epub_file: filename = book.root_ancestor.epub_file.path archive.write(filename, str('%s.epub' % book.root_ancestor.slug)) @@ -666,13 +649,15 @@ def shelf_book_formats(request, shelf): """ shelf = get_object_or_404(models.Tag, slug=shelf, category='set') - formats = {'pdf': False, 'epub': False, 'odt': False, 'txt': False} + formats = {'pdf': False, 'epub': False, 'mobi': False, 'odt': False, 'txt': False} for book in collect_books(models.Book.tagged.with_all(shelf)): if book.pdf_file: formats['pdf'] = True if book.root_ancestor.epub_file: formats['epub'] = True + if book.mobi_file: + formats['mobi'] = True if book.txt_file: formats['txt'] = True for format in ('odt',): @@ -788,6 +773,23 @@ def book_info(request, id, lang='pl'): return render_to_response('catalogue/book_info.html', locals(), context_instance=RequestContext(request)) + def tag_info(request, id): tag = get_object_or_404(models.Tag, id=id) return HttpResponse(tag.description) + + +def download_zip(request, format, slug): + url = None + if format == 'pdf': + url = models.Book.zip_pdf() + elif format == 'epub': + url = models.Book.zip_epub() + elif format == 'mobi': + url = models.Book.zip_mobi() + elif format == 'audiobook' and slug is not None: + book = models.Book.objects.get(slug=slug) + url = book.zip_audiobooks() + else: + raise Http404('No format specified for zip package') + return HttpResponseRedirect(urlquote_plus(settings.MEDIA_URL + url, safe='/?='))