* Correct division by zero when there is no tem in a collection
* Remove unnecessary item and image prefetch on collection.
* increment version
--- a/src/iconolab/__init__.py Thu Jun 28 17:36:27 2018 +0200
+++ b/src/iconolab/__init__.py Sat Jun 30 00:50:54 2018 +0200
@@ -1,4 +1,4 @@
-VERSION = (0, 1, 3, "final", 0)
+VERSION = (0, 1, 4, "final", 0)
VERSION_STR = ".".join(map(lambda i: "%02d" % (i,), VERSION[:2]))
--- a/src/iconolab/models.py Thu Jun 28 17:36:27 2018 +0200
+++ b/src/iconolab/models.py Sat Jun 30 00:50:54 2018 +0200
@@ -62,7 +62,7 @@
.values('image__item').distinct().count()
total_items = self.items_count
- return int(round((items_with_annotation * 100) / total_items))
+ return int(round((items_with_annotation * 100) / total_items)) if total_items > 0 else 0
def __str__(self):
return self.name
--- a/src/iconolab/views/objects.py Thu Jun 28 17:36:27 2018 +0200
+++ b/src/iconolab/views/objects.py Sat Jun 30 00:50:54 2018 +0200
@@ -102,8 +102,6 @@
if 'collection_name' in kwargs.keys():
try:
objects_tuple += (Collection.objects.prefetch_related(
- 'items',
- 'items__images',
Prefetch(
'folders',
Folder.objects.annotate(items_nb=Count('item')).order_by('name')
@@ -266,7 +264,7 @@
adjacent_pages_count = 2
# Paginated objects list
- items_list = collection.items.order_by("metadatas__natural_key").prefetch_related('images', 'images__stats')
+ items_list = Item.objects.filter(collection=collection).prefetch_related('images', 'images__stats').select_related('collection').order_by('metadatas__natural_key')
folder = request.GET.get('folder', None)
@@ -289,7 +287,7 @@
items_pagination_args += "&folder=" + folder
context["items_pagination_data"] = self.get_pagination_data(
- items_list.all(),
+ items_list,
items_page,
items_per_page,
adjacent_pages_count,
@@ -449,7 +447,7 @@
})
image.stats.views_count += 1
image.stats.save()
- return render(request, 'iconolab/detail_item.html', context);
+ return render(request, 'iconolab/detail_item.html', context)
class ShowImageView(View, ContextMixin, IconolabObjectView):
"""