Fix error handling.
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 21 Aug 2023 11:43:15 +0000 (13:43 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 21 Aug 2023 11:43:15 +0000 (13:43 +0200)
src/documents/templates/documents/book_detail.html
src/documents/views.py

index a2dea02..08d8c36 100644 (file)
   </div>
 
 
-  {% if doc %}
+  {% if stats %}
     <div class="card mt-4">
       <div class="card-header">
         <h2>{% trans "Statistics" %}</h2>
             </tr>
           </thead>
           <tbody>
-            {% with stats=doc.get_statistics %}
-              {% include 'documents/book_stats.html' with book=doc stats=stats depth=0 %}
-          {% endwith %}
+            {% include 'documents/book_stats.html' with book=doc stats=stats depth=0 %}
         </tbody>
       </table>
     </div>
index f4c8561..0fbb3b9 100644 (file)
@@ -362,14 +362,21 @@ def book(request, slug):
     publish_error = book.publishable_error()
     publishable = publish_error is None
 
+    stats = None
     try:
         doc = book.wldocument(librarian2=True)
     except:
         doc = None
+    else:
+        try:
+            stats = doc.get_statistic()
+        except:
+            pass
 
     return render(request, "documents/book_detail.html", {
         "book": book,
         "doc": doc,
+        "stats": stats,
         "publishable": publishable,
         "publishable_error": publish_error,
         "form": form,