summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md7
-rw-r--r--ishtar_common/utils.py29
-rw-r--r--ishtar_common/views.py5
-rw-r--r--version.py2
4 files changed, 33 insertions, 10 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 7e9bae963..131d78c0b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,6 +1,13 @@
Ishtar changelog
================
+0.97.6 (2016-09-05)
+-------------------
+
+### Bug fixes ###
+
+- Fix random images rights and manage broken images
+
0.97.5 (2016-09-05)
-------------------
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index cb45d32e1..ca9193204 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -68,6 +68,9 @@ def mode(array):
def _get_image_link(item):
+ # manage missing images
+ if not item.thumbnail or not item.thumbnail.url:
+ return ""
return mark_safe(u"""
<div class="welcome-image">
<img src="{}"/><br/>
@@ -86,13 +89,25 @@ def _get_image_link(item):
unicode(_(u"Load another random image?"))))
-def get_random_item_image_link():
+def get_random_item_image_link(request):
from archaeological_operations.models import Operation
from archaeological_context_records.models import ContextRecord
from archaeological_finds.models import Find
- ope_image_nb = Operation.objects.filter(image__isnull=False).count()
- cr_image_nb = ContextRecord.objects.filter(image__isnull=False).count()
- find_image_nb = Find.objects.filter(image__isnull=False).count()
+
+ ope_image_nb, cr_image_nb, find_image_nb = 0, 0, 0
+ if request.user.has_perm('archaeological_operations.view_operation',
+ Operation):
+ ope_image_nb = Operation.objects.filter(
+ thumbnail__isnull=False).count()
+ if request.user.has_perm(
+ 'archaeological_context_records.view_contextrecord',
+ ContextRecord):
+ cr_image_nb = ContextRecord.objects.filter(
+ thumbnail__isnull=False).count()
+ if request.user.has_perm('archaeological_finds.view_find',
+ Find):
+ find_image_nb = Find.objects.filter(
+ thumbnail__isnull=False).count()
image_total = ope_image_nb + cr_image_nb + find_image_nb
if not image_total:
@@ -101,14 +116,14 @@ def get_random_item_image_link():
image_nb = random.randint(0, image_total - 1)
if image_nb >= 0 and image_nb < ope_image_nb:
return _get_image_link(
- Operation.objects.filter(image__isnull=False).all()[image_nb])
+ Operation.objects.filter(thumbnail__isnull=False).all()[image_nb])
if image_nb >= ope_image_nb and image_nb < (cr_image_nb + ope_image_nb):
return _get_image_link(
- ContextRecord.objects.filter(image__isnull=False).all()[
+ ContextRecord.objects.filter(thumbnail__isnull=False).all()[
image_nb - ope_image_nb])
if image_nb >= (cr_image_nb + ope_image_nb):
return _get_image_link(
- Find.objects.filter(image__isnull=False).all()[
+ Find.objects.filter(thumbnail__isnull=False).all()[
image_nb - ope_image_nb - cr_image_nb])
# should never happen except in case of deletion during the excution
return ''
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index ea2eda462..46a8ceb6a 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -80,13 +80,14 @@ def index(request):
"""
dct = {}
profile = get_current_profile()
+ image = get_random_item_image_link(request)
if hasattr(profile, 'homepage') and profile.homepage:
dct['homepage'] = markdown(profile.homepage)
if '{random_image}' in dct['homepage']:
dct['homepage'] = dct['homepage'].replace(
- '{random_image}', get_random_item_image_link())
+ '{random_image}', image)
else:
- dct['random_image'] = get_random_item_image_link()
+ dct['random_image'] = image
try:
return render_to_response('index.html', dct,
context_instance=RequestContext(request))
diff --git a/version.py b/version.py
index 0dd739e84..0b79515ea 100644
--- a/version.py
+++ b/version.py
@@ -1,4 +1,4 @@
-VERSION = (0, 97, 5)
+VERSION = (0, 97, 6)
def get_version():