"""
allowed_methods = ['GET']
fields = ['title', 'parent', 'children'] + Book.formats + [
- 'media', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'simple_cover', 'fragment_data', 'audio_length'] + [
- 'media', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'simple_cover', 'fragment_data', 'preview'] + [
++ 'media', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'simple_cover', 'fragment_data', 'audio_length',
++ 'preview'] + [
category_plural[c] for c in book_tag_categories]
@piwik_track
class FilterBooksHandler(AnonymousBooksHandler):
fields = book_tag_categories + [
- 'href', 'title', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'slug', 'key']
+ 'href', 'title', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'has_audio', 'slug', 'key']
+ def parse_bool(self, s):
+ if s in ('true', 'false'):
+ return s == 'true'
+ else:
+ return None
+
def read(self, request):
key_sep = '$'
search_string = request.GET.get('search')
for book_format in Book.formats:
setattr(BookDetails, book_format, _file_getter(book_format))
++
add_file_getters()
"""
try:
-- tags, ancestors = read_tags(tags, allowed=self.categories)
++ tags, ancestors = read_tags(tags, request, allowed=self.categories)
except ValueError:
return rc.NOT_FOUND
fragments = Fragment.tagged.with_all(tags).select_related('book')
return rc.CREATED
else:
return rc.NOT_FOUND
- ids = BookUserData.objects.filter(user=request.user, complete=state == 'complete').values_list('book_id', flat=True)
+
+
+ class UserDataHandler(BaseHandler):
+ model = BookUserData
+ fields = ('state',)
+ allowed_methods = ('GET', 'POST')
+
+ def read(self, request, slug):
+ try:
+ book = Book.objects.get(slug=slug)
+ except Book.DoesNotExist:
+ return rc.NOT_FOUND
+ if not request.user.is_authenticated():
+ return rc.FORBIDDEN
+ try:
+ data = BookUserData.objects.get(book=book, user=request.user)
+ except BookUserData.DoesNotExist:
+ return {'state': 'not_started'}
+ return data
+
+ def create(self, request, slug, state):
+ try:
+ book = Book.objects.get(slug=slug)
+ except Book.DoesNotExist:
+ return rc.NOT_FOUND
+ if not request.user.is_authenticated():
+ return rc.FORBIDDEN
+ if state not in ('reading', 'complete'):
+ return rc.NOT_FOUND
+ data, created = BookUserData.objects.get_or_create(book=book, user=request.user)
+ data.state = state
+ data.save()
+ return data
+
+
+ class UserShelfHandler(BookDetailHandler):
+ fields = book_tag_categories + [
+ 'href', 'title', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'slug', 'key']
+
+ def parse_bool(self, s):
+ if s in ('true', 'false'):
+ return s == 'true'
+ else:
+ return None
+
+ def read(self, request, state):
+ if not request.user.is_authenticated():
+ return rc.FORBIDDEN
+ if state not in ('reading', 'complete'):
+ return rc.NOT_FOUND
+ after = request.GET.get('after')
+ count = int(request.GET.get('count', 50))
++ ids = BookUserData.objects.filter(user=request.user, complete=state == 'complete')\
++ .values_list('book_id', flat=True)
+ books = Book.objects.filter(id__in=list(ids)).distinct().order_by('slug')
+ if after:
+ books = books.filter(slug__gt=after)
+ if count:
+ books = books[:count]
+ return books
</div>
{% book_shelf_tags book.pk %}
- <ul class="book-box-tools">
- <li class="book-box-read">
- {% if book.html_file %}
- <a href="{% url 'book_text' book.slug %}" class="downarrow">{% trans "Read online" %}</a>
- {% endif %}
- {% if book.print_on_demand %}
- <a href="{{ book.ridero_link }}" class="downarrow print tlite-tooltip" title="{% trans "Cena książki w druku cyfrowym jest zależna od liczby stron.<br>Przed zakupem upewnij się, że cena druku na żądanie jest dla Ciebie odpowiednia.<br>Wszystkie nasze zasoby w wersji elektronicznej są zawsze dostępne bezpłatnie." %}">{% trans "Print on demand –" %}
- <img src="{% static 'img/ridero.png' %}" style="height: 0.8em;"/></a>
- {% endif %}
- </li>
- <li class="book-box-download">
- <a class="downarrow">{% trans "Download" %}:</a>
- <div class="book-box-formats">
- {% if book.pdf_file %}
- <span><a href="{{ book.pdf_file.url}}">PDF</a></span>
- {% endif %}
- {% if book.epub_file %}
- <span><a href="{{ book.epub_file.url}}">EPUB</a></span>
+ {% if book|status:user != 'closed' %}
+ <ul class="book-box-tools">
+ <li class="book-box-read">
+ {% if book.html_file %}
+ <a href="{% url 'book_text' book.slug %}" class="downarrow">{% trans "Read online" %}</a>
{% endif %}
- {% if book.mobi_file %}
- <span><a href="{{ book.mobi_file.url}}">MOBI</a></span>
+ {% if book.print_on_demand %}
+ <a href="{{ book.ridero_link }}" class="downarrow print tlite-tooltip" title="{% trans "Cena książki w druku cyfrowym jest zależna od liczby stron.<br>Przed zakupem upewnij się, że cena druku na żądanie jest dla Ciebie odpowiednia.<br>Wszystkie nasze zasoby w wersji elektronicznej są zawsze dostępne bezpłatnie." %}">{% trans "Print on demand –" %}
+ <img src="{% static 'img/ridero.png' %}" style="height: 0.8em;"/></a>
{% endif %}
- {% if book.has_audio %}
- <span><a href="{% url 'download_zip_mp3' book.slug %}">MP3</a></span>
- {% endif %}
- <a class="read-more-show hide" href="#">{% trans "more" %}</a>
- <span class="read-more-content">
- {% if book.fb2_file %}
- <span><a href="{{ book.fb2_file.url}}">FB2</a></span>
+ </li>
+ <li class="book-box-download">
+ <a class="downarrow">{% trans "Download" %}:</a>
+ <div class="book-box-formats">
+ {% if book.pdf_file %}
+ <span><a href="{{ book.pdf_url}}">PDF</a></span>
{% endif %}
- {% if book.txt_file %}
- <span><a href="{{ book.txt_file.url}}">TXT</a></span>
+ {% if book.epub_file %}
+ <span><a href="{{ book.epub_url}}">EPUB</a></span>
{% endif %}
- {% download_audio book mp3=False %}
- <br>
- {% custom_pdf_link_li book %}
- <a class="read-more-hide hide" href="#">{% trans "less" %}</a>
- </span>
- </div>
- </li>
- </ul>
+ {% if book.mobi_file %}
+ <span><a href="{{ book.mobi_url}}">MOBI</a></span>
+ {% endif %}
+ {% if book.has_audio %}
+ <span><a href="{% url 'download_zip_mp3' book.slug %}">MP3</a></span>
+ {% endif %}
+ <a class="read-more-show hide" href="#">{% trans "more" %}</a>
+ <span class="read-more-content">
+ {% if book.fb2_file %}
+ <span><a href="{{ book.fb2_url}}">FB2</a></span>
+ {% endif %}
+ {% if book.txt_file %}
+ <span><a href="{{ book.txt_url}}">TXT</a></span>
+ {% endif %}
+ {% download_audio book mp3=False %}
+ <br>
+ {% custom_pdf_link_li book %}
+ <a class="read-more-hide hide" href="#">{% trans "less" %}</a>
+ </span>
+ </div>
+ </li>
+ </ul>
+ {% else %}
+ <p class="book-box-tools">{% trans "For now this work is only available for our subscribers." %}</p>
+ {% endif %}
- <div class="clearboth"></div>
- {% if book.abstract %}
- <div class="abstract more">
- {{ book.abstract|safe }}
- </div>
- {% endif %}
{% block book-box-extra-info %}{% endblock %}
- {% block box-append %}
- {% endblock %}
+ {% block box-append %}{% endblock %}
</div>
+ {% if book.abstract %}
+ <div class="abstract more">
+ {{ book.abstract|safe }}
+ </div>
+ {% endif %}
{% endwith %}
{% block right-column %}