X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/af544a7534db40bd650ac88fe5cf23cccf7b5b27..42dee4014c452c1f9f6b29891bca9800e5ad3528:/apps/catalogue/views.py?ds=sidebyside diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index b69aa4a9c..7f1de6d46 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -10,7 +10,6 @@ import pprint import traceback import re import itertools -from operator import itemgetter from datetime import datetime from django.conf import settings @@ -31,7 +30,7 @@ from django.utils.http import urlquote_plus from django.views.decorators import cache from django.utils.translation import ugettext as _ from django.views.generic.list_detail import object_list -from django.template.defaultfilters import slugify + from catalogue import models from catalogue import forms from catalogue.utils import split_tags @@ -492,13 +491,14 @@ def json_tags_starting_with(request, callback=None): if len(prefix) < 2: return HttpResponse('') tags_list = [] - result = "" for tag in _tags_starting_with(prefix, request.user): if not tag.name in tags_list: - result += "\n" + tag.name tags_list.append(tag.name) - dict_result = {"matches": tags_list} - return JSONResponse(dict_result, callback) + if request.GET.get('mozhint', ''): + result = [prefix, tags_list] + else: + result = {"matches": tags_list} + return JSONResponse(result, callback) # ==================== # = Shelf management = @@ -592,7 +592,7 @@ def download_shelf(request, slug): if form.is_valid(): formats = form.cleaned_data['formats'] if len(formats) == 0: - formats = ['pdf', 'epub', 'odt', 'txt', 'mp3', 'ogg', 'daisy'] + formats = ['pdf', 'epub', 'odt', 'txt'] # Create a ZIP archive temp = tempfile.TemporaryFile() @@ -610,22 +610,10 @@ def download_shelf(request, slug): if 'odt' in formats and book.has_media("odt"): for file in book.get_media("odt"): filename = file.file.path - archive.write(filename, str('%s.odt' % slugify(file.name))) + archive.write(filename, str('%s.odt' % slughifi(file.name))) if 'txt' in formats and book.txt_file: filename = book.txt_file.path archive.write(filename, str('%s.txt' % book.slug)) - if 'mp3' in formats and book.has_media("mp3"): - for file in book.get_media("mp3"): - filename = file.file.path - archive.write(filename, str('%s.mp3' % slugify(file.name))) - if 'ogg' in formats and book.has_media("ogg"): - for file in book.get_media("ogg"): - filename = file.file.path - archive.write(filename, str('%s.ogg' % slugify(file.name))) - if 'daisy' in formats and book.has_media("daisy"): - for file in book.get_media("daisy"): - filename = file.file.path - archive.write(filename, str('%s.daisy' % slugify(file.name))) archive.close() response = HttpResponse(content_type='application/zip', mimetype='application/x-zip-compressed') @@ -644,7 +632,7 @@ 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, 'mp3': False, 'ogg': False, 'daisy': False} + formats = {'pdf': False, 'epub': False, 'odt': False, 'txt': False} for book in collect_books(models.Book.tagged.with_all(shelf)): if book.pdf_file: @@ -653,8 +641,8 @@ def shelf_book_formats(request, shelf): formats['epub'] = True if book.txt_file: formats['txt'] = True - for format in ('odt', 'mp3', 'ogg'): - if not formats[format] and book.has_media(format): + for format in ('odt',): + if book.has_media(format): formats[format] = True return HttpResponse(LazyEncoder().encode(formats)) @@ -761,6 +749,7 @@ def clock(request): def xmls(request): """" Create a zip archive with all XML files. + This should be removed when we have real API. """ temp = tempfile.TemporaryFile() archive = zipfile.ZipFile(temp, 'w') @@ -776,25 +765,3 @@ def xmls(request): temp.seek(0) response.write(temp.read()) return response - - -@cache.never_cache -def epubs(request): - """" - Create a tar archive with all EPUB files, segregated to directories. - """ - - temp = tempfile.TemporaryFile() - archive = tarfile.TarFile(fileobj=temp, mode='w') - - for book in models.Book.objects.exclude(epub_file=''): - archive.add(book.epub_file.path, (u'%s/%s.epub' % (book.get_extra_info_value()['author'], book.slug)).encode('utf-8')) - archive.close() - - response = HttpResponse(content_type='application/tar', mimetype='application/x-tar') - response['Content-Disposition'] = 'attachment; filename=epubs.tar' - response['Content-Length'] = temp.tell() - - temp.seek(0) - response.write(temp.read()) - return response