book mini box: cache instead of ssi
authorJan Szejko <jan.szejko@gmail.com>
Tue, 12 Apr 2016 09:56:01 +0000 (11:56 +0200)
committerJan Szejko <jan.szejko@gmail.com>
Tue, 12 Apr 2016 09:56:01 +0000 (11:56 +0200)
src/catalogue/models/book.py
src/catalogue/templates/catalogue/book_detail.html
src/catalogue/templates/catalogue/book_mini_box.html
src/catalogue/templates/catalogue/book_text.html
src/catalogue/templates/catalogue/collection_box.html
src/catalogue/templates/catalogue/related_books.html
src/catalogue/views.py
src/wolnelektury/templates/main_page.html

index 3811bba..d3e2a77 100644 (file)
@@ -153,6 +153,9 @@ class Book(models.Model):
     def language_name(self):
         return dict(settings.LANGUAGES).get(self.language_code(), "")
 
+    def is_foreign(self):
+        return self.language_code() != settings.LANGUAGE_CODE
+
     def has_media(self, type_):
         if type_ in Book.formats:
             return bool(getattr(self, "%s_file" % type_))
index b87e9eb..3083181 100644 (file)
@@ -3,6 +3,7 @@
 {% load common_tags catalogue_tags %}
 {% load ssify %}
 {% load build_absolute_uri from fnp_common %}
+{% load cache %}
 
 {% block titleextra %}{{ book.pretty_title }}{% endblock %}
 {% block ogimage %}{% if book.cover %}{{ book.cover.url|build_absolute_uri:request }}{% endif %}{% endblock %}
 <section class="see-also" style="display: inline-block;">
 <h1>{% trans "Other versions" %}:</h1>
 {% for rel in book.other_versions %}
-    {% ssi_include 'catalogue_book_mini' pk=rel.pk %}
+    {% cache 86400 book_mini_box rel.pk %}
+      {% include 'catalogue/book_mini_box.html' with book=rel %}
+    {% endcache %}
+    {#% ssi_include 'catalogue_book_mini' pk=rel.pk %#}
 {% endfor %}
 </section>
 {% endif %}
index d77f910..b74d651 100755 (executable)
@@ -1,22 +1,24 @@
 {% spaceless %}
-<div class="book-mini-box">
-    <div class="book-mini-box-inner">
-    {% if with_link %}
-    <a href="{{ book.get_absolute_url }}">
-    {% endif %}
-        {% if book.cover_thumb %}
-            <img src="{{ book.cover_thumb.url }}" alt="{{ author }} – {{ book.title }}" class="cover" />
+  {% with book.author_unicode as author %}
+    <div class="book-mini-box">
+      <div class="book-mini-box-inner">
+        {% if not no_link %}
+          <a href="{{ book.get_absolute_url }}">
         {% endif %}
-        {% if show_lang %}
+          {% if book.cover_thumb %}
+            <img src="{{ book.cover_thumb.url }}" alt="{{ author }} – {{ book.title }}" class="cover" />
+          {% endif %}
+          {% if book.is_foreign %}
             <span class="language" title="{{ book.language_name }}">{{ book.language_code }}</span>
-        {% endif %}
-        <div class="desc">
+          {% endif %}
+          <div class="desc">
             <span class="mono author">{{ author }}</span>
             <span class="title">{{ book.title }}</span>
-        </div>
-    {% if with_link %}
-    </a>
-    {% endif %}
+          </div>
+        {% if not no_link %}
+          </a>
+        {% endif %}
+      </div>
     </div>
-</div>
+  {% endwith %}
 {% endspaceless %}
\ No newline at end of file
index 339cfc7..f51e565 100644 (file)
@@ -2,6 +2,7 @@
 {% load i18n %}
 {% load catalogue_tags ssify %}
 {% load thumbnail %}
+{% load cache %}
 
 
 {% block title %}{{ book.pretty_title }}{% endblock %}
     <ul>
     {% spaceless %}
     {% for other_version in book.other_versions %}
-        <li><a class="display-other" 
-            data-other="{{ other_version.html_file.url }}"
-            href="{% url 'book_text' other_version.slug %}">
-                {% ssi_include 'catalogue_book_mini_nolink' pk=other_version.pk %}
-                </a>
+        <li>
+          <a class="display-other"
+              data-other="{{ other_version.html_file.url }}"
+              href="{% url 'book_text' other_version.slug %}">
+            {% cache 86400 book_mini_box other_version.pk %}
+              {% include 'catalogue/book_mini_box.html' with book=other_version no_link=True %}
+            {% endcache %}
+            {#% ssi_include 'catalogue_book_mini_nolink' pk=other_version.pk %#}
+          </a>
         </li>
     {% endfor %}
     {% endspaceless %}
index 81e0b38..1d9206b 100644 (file)
@@ -1,13 +1,17 @@
 {% spaceless %}
 {% load i18n %}
 {% load ssi_include from ssify %}
+{% load cache %}
 <div class="collection-box white-box">
     <h2><a href="{{ obj.get_absolute_url }}">{% trans "Collection" %}: {{ obj }}</a></h2>
     {% if obj.description %}
     {{ obj.description|safe|truncatewords_html:40 }}
     {% endif %}
-    {% for b in obj.get_books|slice:":5" %}
-        {% ssi_include 'catalogue_book_mini' pk=b.pk %}
+    {% for book in obj.get_books|slice:":5" %}
+        {% cache 86400 book_mini_box book.pk %}
+          {% include 'catalogue/book_mini_box.html' %}
+        {% endcache %}
+        {#% ssi_include 'catalogue_book_mini' pk=book.pk %#}
     {% endfor %}
     {% with obj.get_books.count|add:-5 as more %}
         {% if more > 0 %}
index 6407d5a..03d7793 100755 (executable)
@@ -2,13 +2,17 @@
 {% load catalogue_random_book from catalogue_tags %}
 {% load picture_random_picture from picture_tags %}
 {% load ssi_include from ssify %}
+{% load cache %}
 
 {% for pic in pics %}
     {% ssi_include 'picture_mini' pk=pic.pk %}
 {% endfor %}
 
 {% for book in books %}
-    {% ssi_include 'catalogue_book_mini' pk=book.pk %}
+    {% cache 86400 book_mini_box book.pk %}
+      {% include 'catalogue/book_mini_box.html' %}
+    {% endcache %}
+    {#% ssi_include 'catalogue_book_mini' pk=book.pk %#}
 {% endfor %}
 
 {% if random %}
index c263608..6222185 100644 (file)
@@ -616,9 +616,7 @@ def book_mini(request, pk, with_link=True):
         raise Http404
     return render(request, 'catalogue/book_mini_box.html', {
         'book': book,
-        'author': book.author_unicode(),
-        'with_link': with_link,
-        'show_lang': book.language_code() != settings.LANGUAGE_CODE,
+        'no_link': not with_link,
     })
 
 
index ad34958..840514f 100755 (executable)
@@ -2,6 +2,7 @@
 {% load static from staticfiles %}
 {% load i18n catalogue_tags infopages_tags social_tags %}
 {% load ssi_include from ssify %}
+{% load cache %}
 
 
 {% block title %}{% trans "Wolne Lektury internet library" %}{% endblock %}
 
 {% block body %}{% spaceless %}
 
-    {% choose_cite as cite_pk %}
-    {{ cite_pk.if }}
-        {% ssi_include 'social_cite_main' pk=cite_pk %}
-    {{ cite_pk.endif }}
-
-    <section id="main-library">
-        <h1>W naszej cyfrowej bibliotece znajdziesz</h1>
-        <div class="main-library-row">
-            <div class="covers">
-            {% for b in best %}
-                {% ssi_include 'catalogue_book_mini' pk=b.pk %}
-            {% endfor %}
-            </div>
-            <div class="note white-box normal-text" style="font-size: 18px">
-            i wiele innych książek, wierszy, obrazów, audiobooków…
-            </div>
-        </div>
-    </section>
-
-    <section id="main-theme">
-        <h1>Motywy i tematy</h1>
-        <div class="white-box normal-text">
-        <h2>{% trans "Theme" %}: {{ theme }}</h2>
-        <p>Utwory, w których występuje ten motyw:</p>
-        {% for book in theme_books %}
-            {% ssi_include 'catalogue_book_mini' pk=book.pk %}
+  {% choose_cite as cite_pk %}
+  {{ cite_pk.if }}
+    {% ssi_include 'social_cite_main' pk=cite_pk %}
+  {{ cite_pk.endif }}
+
+  <section id="main-library">
+    <h1>W naszej cyfrowej bibliotece znajdziesz</h1>
+    <div class="main-library-row">
+      <div class="covers">
+        {% for book in best %}
+          {% cache 86400 book_mini_box book.pk %}
+            {% include 'catalogue/book_mini_box.html' %}
+          {% endcache %}
+          {#% ssi_include 'catalogue_book_mini' pk=b.pk %#}
         {% endfor %}
-        {% if theme_fragment %}
-            {% ssi_include 'catalogue_fragment_promo' pk=theme_fragment.pk %}
-        {% endif %}
-        </div>
-        <a class="more" href="{% url 'theme_catalogue' %}">Zobacz katalog motywów</a>
-    </section>
-
-    {% comment %}
-    <section class="tag-box-section">
-        <h1>Autorzy</h1>
-      <a class="tag-box" href="{{ author.get_absolute_url }}">
+      </div>
+      <div class="note white-box normal-text" style="font-size: 18px">
+        i wiele innych książek, wierszy, obrazów, audiobooków…
+      </div>
+    </div>
+  </section>
+
+  <section id="main-theme">
+    <h1>Motywy i tematy</h1>
+    <div class="white-box normal-text">
+      <h2>{% trans "Theme" %}: {{ theme }}</h2>
+      <p>Utwory, w których występuje ten motyw:</p>
+      {% for book in theme_books %}
+        {% cache 86400 book_mini_box book.pk %}
+          {% include 'catalogue/book_mini_box.html' %}
+        {% endcache %}
+        {#% ssi_include 'catalogue_book_mini' pk=book.pk %#}
+      {% endfor %}
+      {% if theme_fragment %}
+        {% ssi_include 'catalogue_fragment_promo' pk=theme_fragment.pk %}
+      {% endif %}
+    </div>
+    <a class="more" href="{% url 'theme_catalogue' %}">Zobacz katalog motywów</a>
+  </section>
+
+  {% comment %}
+  <section class="tag-box-section">
+    <h1>Autorzy</h1>
+    <a class="tag-box" href="{{ author.get_absolute_url }}">
       {% ssi_include "catalogue_tag_box" pk=author.pk %}
-      </a>
-        <a class="more" href="{% url 'author_catalogue' %}">Zobacz katalog autorów</a>
-    </section>
+    </a>
+    <a class="more" href="{% url 'author_catalogue' %}">Zobacz katalog autorów</a>
+  </section>
 
-    <section class="tag-box-section">
-        <h1>Gatunki</h1>
-      <a class="tag-box" href="{{ genre.get_absolute_url }}">
+  <section class="tag-box-section">
+    <h1>Gatunki</h1>
+    <a class="tag-box" href="{{ genre.get_absolute_url }}">
       {% ssi_include "catalogue_tag_box" pk=genre.pk %}
-      </a>
-        <a class="more" href="{% url 'genre_catalogue' %}">Zobacz katalog gatunków</a>
-    </section>
+    </a>
+    <a class="more" href="{% url 'genre_catalogue' %}">Zobacz katalog gatunków</a>
+  </section>
 
-    <section class="tag-box-section">
-        <h1>Rodzaje</h1>
-      <a class="tag-box" href="{{ kind.get_absolute_url }}">
+  <section class="tag-box-section">
+    <h1>Rodzaje</h1>
+    <a class="tag-box" href="{{ kind.get_absolute_url }}">
       {% ssi_include "catalogue_tag_box" pk=kind.pk %}
-      </a>
-        <a class="more" href="{% url 'kind_catalogue' %}">Zobacz katalog rodzajów</a>
-    </section>
+    </a>
+    <a class="more" href="{% url 'kind_catalogue' %}">Zobacz katalog rodzajów</a>
+  </section>
 
-    <section class="tag-box-section">
-        <h1>Epoki</h1>
-      <a class="tag-box" href="{{ epoch.get_absolute_url }}">
+  <section class="tag-box-section">
+    <h1>Epoki</h1>
+    <a class="tag-box" href="{{ epoch.get_absolute_url }}">
       {% ssi_include "catalogue_tag_box" pk=epoch.pk %}
-      </a>
-        <a class="more" href="{% url 'epoch_catalogue' %}">Zobacz katalog epok</a>
-    </section>
-    {% endcomment %}
-
-    {% if collection %}
-        <section>
-            <h1>Kolekcje</h1>
-            {% ssi_include 'catalogue_collection_box' pk=collection.pk %}
-            <a class="more" href="{% url 'catalogue_collections' %}">Zobacz katalog kolekcji</a>
-        </section>
-    {% endif %}
+    </a>
+    <a class="more" href="{% url 'epoch_catalogue' %}">Zobacz katalog epok</a>
+  </section>
+  {% endcomment %}
 
+  {% if collection %}
     <section>
-        <h1>{% trans "Recent publications" %}</h1>
-            {% for book in last_published %}
-                {% ssi_include 'catalogue_book_mini' pk=book.pk %}
-            {% endfor %}
-        <a class="more" href="{% url 'recent_list' %}">{% trans "More recent publications" %}</a>
+      <h1>Kolekcje</h1>
+      {% ssi_include 'catalogue_collection_box' pk=collection.pk %}
+      <a class="more" href="{% url 'catalogue_collections' %}">Zobacz katalog kolekcji</a>
     </section>
-
-    <div class="clearboth"></div>
-
-    <section class="infopages-box">
-        <h1>{% trans "News" %}</h1>
-        {% ssi_include 'latest_blog_posts' %}
-    </section>
-
-
-    <section class="infopages-box">
-        <h1>{% trans "Utilities" %}</h1>
-
-        <ul>
-            <li><a href="{% url 'suggest' %}" id="suggest" class="ajaxable">{% trans "Report a bug or suggestion" %}</a></li>
-            <!--li><a href="http://turniej.wolnelektury.pl">Turniej Elektrybałtów</a></li-->
-            <li><a href="{% url 'reporting_catalogue_pdf' %}">{% trans "Download the catalogue in PDF format." %}</a></li>
-           <li><a href="{% url 'dictionary_notes' %}">{% trans "Footnotes" %}</a></li>
-            <li><a href="{% url 'suggest_publishing' %}" id="suggest-publishing" class="ajaxable">{% trans "Missing a book?" %}</a></li>
-            <li><a href="{% url 'publish_plan' %}">{% trans "Publishing plan" %}</a></li>
-            <li><a href="{% url 'api' %}">API</a></li>
-            {#<li><a href="{% url 'oaipmh' %}">OAI-PMH</a></li>#}
-            <li><a href="{% url 'lesmianator' %}" lang="pl">Leśmianator</a></li>
-            <li><a href="http://polski.wolnelektury.pl" lang="pl">Materiały do nauki j. polskiego</a></li>
-
-        </ul>
-    </section>
-
-
-    <section class="infopages-box">
-        <h1>{% trans "Information" %}</h1>
-        <ul>
-            <li><a href="https://nowoczesnapolska.org.pl/prywatnosc/">{% trans "Privacy policy" %}</a></li>
-            {% infopages_on_main %}
-        </ul>
-
-        <div class="social-links">
-            <a href="https://pl-pl.facebook.com/pages/Wolne-Lektury/203084073268" title='Wolne Lektury @ Facebook'>
-                <img src="{% static "img/social/f.png" %}" alt="Wolne Lektury @ Facebook" />
-            </a>
-            <a href="https://nk.pl/profile/30441509" title='Wolne Lektury @ NK'>
-                <img src="{% static "img/social/nk.png" %}" alt="Wolne Lektury @ NK.pl" />
-            </a>
-        </div>
-    </section>
-
+  {% endif %}
+
+  <section>
+    <h1>{% trans "Recent publications" %}</h1>
+      {% for book in last_published %}
+        {% cache 86400 book_mini_box book.pk %}
+          {% include 'catalogue/book_mini_box.html' %}
+        {% endcache %}
+        {#% ssi_include 'catalogue_book_mini' pk=book.pk %#}
+      {% endfor %}
+    <a class="more" href="{% url 'recent_list' %}">{% trans "More recent publications" %}</a>
+  </section>
+
+  <div class="clearboth"></div>
+
+  <section class="infopages-box">
+    <h1>{% trans "News" %}</h1>
+    {% ssi_include 'latest_blog_posts' %}
+  </section>
+
+
+  <section class="infopages-box">
+    <h1>{% trans "Utilities" %}</h1>
+
+    <ul>
+      <li><a href="{% url 'suggest' %}" id="suggest" class="ajaxable">{% trans "Report a bug or suggestion" %}</a></li>
+      <!--li><a href="http://turniej.wolnelektury.pl">Turniej Elektrybałtów</a></li-->
+      <li><a href="{% url 'reporting_catalogue_pdf' %}">{% trans "Download the catalogue in PDF format." %}</a></li>
+<li><a href="{% url 'dictionary_notes' %}">{% trans "Footnotes" %}</a></li>
+      <li><a href="{% url 'suggest_publishing' %}" id="suggest-publishing" class="ajaxable">{% trans "Missing a book?" %}</a></li>
+      <li><a href="{% url 'publish_plan' %}">{% trans "Publishing plan" %}</a></li>
+      <li><a href="{% url 'api' %}">API</a></li>
+      {#<li><a href="{% url 'oaipmh' %}">OAI-PMH</a></li>#}
+      <li><a href="{% url 'lesmianator' %}" lang="pl">Leśmianator</a></li>
+      <li><a href="http://polski.wolnelektury.pl" lang="pl">Materiały do nauki j. polskiego</a></li>
+    </ul>
+  </section>
+
+
+  <section class="infopages-box">
+    <h1>{% trans "Information" %}</h1>
+    <ul>
+      <li><a href="https://nowoczesnapolska.org.pl/prywatnosc/">{% trans "Privacy policy" %}</a></li>
+      {% infopages_on_main %}
+    </ul>
+
+    <div class="social-links">
+      <a href="https://pl-pl.facebook.com/pages/Wolne-Lektury/203084073268" title='Wolne Lektury @ Facebook'>
+        <img src="{% static "img/social/f.png" %}" alt="Wolne Lektury @ Facebook" />
+      </a>
+      <a href="https://nk.pl/profile/30441509" title='Wolne Lektury @ NK'>
+        <img src="{% static "img/social/nk.png" %}" alt="Wolne Lektury @ NK.pl" />
+      </a>
+    </div>
+  </section>
 
 {% endspaceless %}{% endblock %}
 
 
 {% block add_footer %}{% spaceless %}
-{{ cite_pk.if }}
+  {{ cite_pk.if }}
     <p>{% trans "Image used:" %}
-    {% ssi_include 'social_cite_info' pk=cite_pk %}
+      {% ssi_include 'social_cite_info' pk=cite_pk %}
     </p>
-{{ cite_pk.endif }}
+  {{ cite_pk.endif }}
 {% endspaceless %}{% endblock %}