X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/db2b21ea1d016ed42a657b88930ce95dc921ee78..5207c4d8ee23d6d5df532faa8103a34b1572e45f:/apps/catalogue/views.py diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 13a7da4ff..5de0e9dc2 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -141,7 +141,7 @@ def differentiate_tags(request, tags, ambiguous_slugs): context_instance=RequestContext(request)) -def tagged_object_list(request, tags=''): +def tagged_object_list(request, tags='', api=False): try: tags = models.Tag.get_tag_list(tags) except models.Tag.DoesNotExist: @@ -222,20 +222,23 @@ def tagged_object_list(request, tags=''): only_author = len(tags) == 1 and tags[0].category == 'author' objects = models.Book.objects.none() - return object_list( - request, - objects, - template_name='catalogue/tagged_object_list.html', - extra_context={ - 'categories': categories, - 'only_shelf': only_shelf, - 'only_author': only_author, - 'only_my_shelf': only_my_shelf, - 'formats_form': forms.DownloadFormatsForm(), - - 'tags': tags, - } - ) + if api: + print objects + return objects + else: + return object_list( + request, + objects, + template_name='catalogue/tagged_object_list.html', + extra_context={ + 'categories': categories, + 'only_shelf': only_shelf, + 'only_author': only_author, + 'only_my_shelf': only_my_shelf, + 'formats_form': forms.DownloadFormatsForm(), + 'tags': tags, + } + ) def book_fragments(request, book_slug, theme_slug): @@ -491,13 +494,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 = @@ -591,7 +595,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() @@ -613,18 +617,6 @@ def download_shelf(request, slug): 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' % slughifi(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' % slughifi(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' % slughifi(file.name))) archive.close() response = HttpResponse(content_type='application/zip', mimetype='application/x-zip-compressed') @@ -643,7 +635,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: @@ -652,8 +644,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)) @@ -691,6 +683,27 @@ def delete_shelf(request, slug): # ================== # = Authentication = # ================== + +@cache.never_cache +def simple_login(request): + if request.method == "GET": + #next = request.REQUEST.get('next', '') + #if next == '': + form = AuthenticationForm(prefix='login') + return render_to_response('auth/login.html', locals(), + context_instance=RequestContext(request)) + #else: + # return HttpResponseRedirect("/"+next) + + elif request.method == "POST": + form = AuthenticationForm(data=request.POST, prefix='login') + if form.is_valid(): + auth.login(request, form.get_user()) + url = request.META['HTTP_REFERER'].split("next=")[1] + url = url.replace("%3F","?").replace("%3D","=") + return HttpResponseRedirect(url) + + @require_POST @cache.never_cache def login(request):