fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
custom pdf in dirs
[wolnelektury.git]
/
apps
/
catalogue
/
views.py
diff --git
a/apps/catalogue/views.py
b/apps/catalogue/views.py
index
20fecb7
..
0c05d17
100644
(file)
--- a/
apps/catalogue/views.py
+++ b/
apps/catalogue/views.py
@@
-4,38
+4,33
@@
#
import re
import itertools
#
import re
import itertools
-from datetime import datetime
from django.conf import settings
from django.template import RequestContext
from django.conf import settings
from django.template import RequestContext
-from django.shortcuts import render_to_response, get_object_or_404
+from django.shortcuts import render_to_response, get_object_or_404
, redirect
from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect
from django.core.urlresolvers import reverse
-from django.db.models import
Count, Sum,
Q
+from django.db.models import Q
from django.contrib.auth.decorators import login_required, user_passes_test
from django.utils.datastructures import SortedDict
from django.contrib.auth.decorators import login_required, user_passes_test
from django.utils.datastructures import SortedDict
-from django.views.decorators.http import require_POST
-from django.contrib import auth
-from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.utils.http import urlquote_plus
from django.utils.http import urlquote_plus
-from django.views.decorators import cache
from django.utils import translation
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 _
, ugettext_lazy
+from django.views.
decorators.cache import never_cache
-from ajaxable.utils import
LazyEncoder,
JSONResponse, AjaxableFormView
+from ajaxable.utils import JSONResponse, AjaxableFormView
from catalogue import models
from catalogue import forms
from catalogue import models
from catalogue import forms
-from catalogue.utils import (split_tags,
AttachmentHttpResponse,
+from catalogue.utils import (split_tags,
async_build_pdf, MultiQuerySet)
async_build_pdf, MultiQuerySet)
-from catalogue.tasks import touch_tag
from pdcounter import models as pdcounter_models
from pdcounter import views as pdcounter_views
from suggest.forms import PublishingSuggestForm
from picture.models import Picture
from os import path
from pdcounter import models as pdcounter_models
from pdcounter import views as pdcounter_views
from suggest.forms import PublishingSuggestForm
from picture.models import Picture
from os import path
+from waiter.models import WaitedFile
staff_required = user_passes_test(lambda user: user.is_staff)
staff_required = user_passes_test(lambda user: user.is_staff)
@@
-102,8
+97,8
@@
def differentiate_tags(request, tags, ambiguous_slugs):
context_instance=RequestContext(request))
context_instance=RequestContext(request))
+@never_cache
def tagged_object_list(request, tags=''):
def tagged_object_list(request, tags=''):
- # import pdb; pdb.set_trace()
try:
tags = models.Tag.get_tag_list(tags)
except models.Tag.DoesNotExist:
try:
tags = models.Tag.get_tag_list(tags)
except models.Tag.DoesNotExist:
@@
-194,6
+189,7
@@
def tagged_object_list(request, tags=''):
'only_my_shelf': only_my_shelf,
'formats_form': forms.DownloadFormatsForm(),
'tags': tags,
'only_my_shelf': only_my_shelf,
'formats_form': forms.DownloadFormatsForm(),
'tags': tags,
+ 'theme_is_set': theme_is_set,
},
context_instance=RequestContext(request))
},
context_instance=RequestContext(request))
@@
-209,6
+205,7
@@
def book_fragments(request, slug, theme_slug):
context_instance=RequestContext(request))
context_instance=RequestContext(request))
+@never_cache
def book_detail(request, slug):
try:
book = models.Book.objects.get(slug=slug)
def book_detail(request, slug):
try:
book = models.Book.objects.get(slug=slug)
@@
-250,10
+247,11
@@
def player(request, slug):
else:
have_oggs = False
audiobooks.append(media)
else:
have_oggs = False
audiobooks.append(media)
- print audiobooks
projects = sorted(projects)
projects = sorted(projects)
+ extra_info = book.get_extra_info_value()
+
return render_to_response('catalogue/player.html', locals(),
context_instance=RequestContext(request))
return render_to_response('catalogue/player.html', locals(),
context_instance=RequestContext(request))
@@
-543,10
+541,11
@@
def download_custom_pdf(request, slug, method='GET'):
cust = form.customizations
pdf_file = models.get_customized_pdf_path(book, cust)
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()
- return AttachmentHttpResponse(file_name=("%s.pdf" % book.slug), file_path=pdf_file, mimetype="application/pdf")
+ url = WaitedFile.order(pdf_file,
+ lambda p: async_build_pdf.delay(book.id, cust, p),
+ book.pretty_title()
+ )
+ return redirect(url)
else:
raise Http404(_('Incorrect customization options for PDF'))
else:
else:
raise Http404(_('Incorrect customization options for PDF'))
else:
@@
-555,17
+554,22
@@
def download_custom_pdf(request, slug, method='GET'):
class CustomPDFFormView(AjaxableFormView):
form_class = forms.CustomPDFForm
class CustomPDFFormView(AjaxableFormView):
form_class = forms.CustomPDFForm
- title =
_
('Download custom PDF')
- submit =
_
('Download')
+ title =
ugettext_lazy
('Download custom PDF')
+ submit =
ugettext_lazy
('Download')
def __call__(self, request):
from copy import copy
if request.method == 'POST':
request.GET = copy(request.GET)
def __call__(self, request):
from copy import copy
if request.method == 'POST':
request.GET = copy(request.GET)
- request.GET['next'] = "%s?%s" % (reverse('catalogue.views.download_custom_pdf', args=[request.GET
['slug']
]),
+ request.GET['next'] = "%s?%s" % (reverse('catalogue.views.download_custom_pdf', args=[request.GET
.get('slug')
]),
request.POST.urlencode())
return super(CustomPDFFormView, self).__call__(request)
request.POST.urlencode())
return super(CustomPDFFormView, self).__call__(request)
+ def get_object(self, request):
+ return get_object_or_404(models.Book, slug=request.GET.get('slug'))
+
+ def context_description(self, request, obj):
+ return obj.pretty_title()
def success(self, *args):
pass
def success(self, *args):
pass