from catalogue.feeds import AudiobookFeed
from catalogue.models import Book
from picture.models import Picture
+from catalogue.views import CustomPDFFormView
+
+ SLUG = r'[a-z0-9-]*'
+
urlpatterns = patterns('picture.views',
# pictures - currently pictures are coupled with catalogue, hence the url is here
url(r'^obraz/?$', 'picture_list'),
url(r'^audiobooki/(?P<type>mp3|ogg|daisy|all).xml$', AudiobookFeed(), name='audiobook_feed'),
- url(r'^custompdf/(?P<book_fileid>%s).pdf' % Book.FILEID_RE, 'download_custom_pdf'),
- url(r'^custompdf$', CustomPDFFormView(), name='custom_pdf_form')
++ url(r'^custompdf$', CustomPDFFormView(), name='custom_pdf_form'),
+ url(r'^custompdf/(?P<slug>%s).pdf' % SLUG, 'download_custom_pdf'),
+
)
context_instance=RequestContext(request))
- def book_detail(request, book):
- kwargs = models.Book.split_urlid(book)
- if kwargs is None:
- raise Http404
+ def book_detail(request, slug):
try:
- book = models.Book.objects.get(**kwargs)
+ book = models.Book.objects.get(slug=slug)
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)
return HttpResponseRedirect(urlquote_plus(settings.MEDIA_URL + url, safe='/?='))
- 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)
-def download_custom_pdf(request, slug):
++def download_custom_pdf(request, slug, method='GET'):
+ book = get_object_or_404(models.Book, slug=slug)
- 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)