re_path(tags_re + r'books/' + paginate_re,
piwik_track_view(views.BookList.as_view()),
- name='catalogue_api_book_list'),
+ {"filename": "books"}, name='catalogue_api_book_list'),
re_path(tags_re + r'parent_books/' + paginate_re,
piwik_track_view(views.BookList.as_view()),
- {"top_level": True}, name='catalogue_api_parent_book_list'),
+ {"filename": "parent_books", "top_level": True}, name='catalogue_api_parent_book_list'),
re_path(tags_re + r'audiobooks/' + paginate_re,
piwik_track_view(views.BookList.as_view()),
- {"audiobooks": True}, name='catalogue_api_audiobook_list'),
+ {"filename": "audiobooks", "audiobooks": True}, name='catalogue_api_audiobook_list'),
re_path(tags_re + r'daisy/' + paginate_re,
piwik_track_view(views.BookList.as_view()),
- {"daisy": True}, name='catalogue_api_daisy_list'),
+ {"filename": "daisy", "daisy": True}, name='catalogue_api_daisy_list'),
re_path(r'^recommended/' + paginate_re,
piwik_track_view(views.BookList.as_view()),
{"recommended": True}, name='catalogue_api_recommended_list'),
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
import json
+import os.path
+from django.conf import settings
from django.http import Http404, HttpResponse
from django.utils.decorators import method_decorator
from django.views.decorators.cache import never_cache
queryset = Book.objects.none() # Required for DjangoModelPermissions
serializer_class = serializers.BookListSerializer
+ def get(self, request, filename=None, **kwargs):
+ if filename and 'count' not in request.query_params:
+ try:
+ with open(os.path.join(settings.MEDIA_ROOT, 'api', '%s.%s' % (filename, request.accepted_renderer.format)), 'rb') as f:
+ content = f.read()
+ return HttpResponse(content, content_type=request.accepted_media_type)
+ except:
+ pass
+ return super().get(request, filename=filename, **kwargs)
+
def get_queryset(self):
try:
tags, ancestors = read_tags(
processed += 1
last_word = ''
- text = str(m.group(1), 'utf-8').lower()
+ text = m.group(1).lower()
for letter in text:
mydict = lesmianator.setdefault(last_word, {})
mydict.setdefault(letter, 0)
return
try:
- dump(lesmianator, open(path, 'w'))
+ dump(lesmianator, open(path, 'wb'))
except IOError:
print(self.style.ERROR("Couldn't write to $s" % path))
return
- dump(lesmianator, open(path, 'w'))
if verbose >= 1:
print("%d processed, %d skipped" % (processed, skipped))
print("Results dumped to %s" % path)