summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-30 18:24:06 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-30 18:24:06 +0100
commit2dae1b8fe9d6614d2746e9d2e85b79aac6956328 (patch)
tree3e293a5f9d0a2213c20930465c93224abcef6a56
parent73bcbbc05152f36cf211bc2897d6aadde766c166 (diff)
downloadIshtar-2dae1b8fe9d6614d2746e9d2e85b79aac6956328.tar.bz2
Ishtar-2dae1b8fe9d6614d2746e9d2e85b79aac6956328.zip
update-current-item: prevent errors when session is not well initialized
-rw-r--r--ishtar_common/tests.py24
-rw-r--r--ishtar_common/views.py4
2 files changed, 25 insertions, 3 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 9ced28ea6..9e5fc3466 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -355,7 +355,7 @@ class ShortMenuTest(TestCase):
if not user:
user = self.other_user
from archaeological_operations.models import Operation, OperationType
- ope_type = OperationType.objects.create()
+ ope_type, created = OperationType.objects.get_or_create(label="test")
return Operation.objects.create(
operation_type=ope_type,
history_modifier=user,
@@ -662,6 +662,28 @@ class ShortMenuTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertFalse(str(treat.cached_label) in response.content)
+ def test_update_current_item(self):
+ c = Client()
+ c.login(username=self.username, password=self.password)
+ base_find, find = self._create_find()
+
+ response = c.get(reverse('pin', args=['find', find.pk]))
+ self.assertEqual(response.status_code, 200)
+ # the selected find is pined
+ self.assertEqual(c.session['find'], str(find.pk))
+ # dependant items are also pined
+ self.assertEqual(c.session['contextrecord'],
+ str(base_find.context_record.pk))
+ self.assertEqual(c.session['operation'],
+ str(base_find.context_record.operation.pk))
+
+ # pin another operation - dependant items are nullify
+ ope = self._create_ope()
+ response = c.get(reverse('pin', args=['operation', ope.pk]))
+ self.assertEqual(response.status_code, 200)
+ self.assertFalse(c.session['find'])
+ self.assertFalse(c.session['contextrecord'])
+
class ImportTest(TestCase):
def testDeleteRelated(self):
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index e8ae1a458..33f4fac7f 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -368,14 +368,14 @@ def update_current_item(request, item_type=None, pk=None):
request.session["operation"] = ''
currents['operation'] = None
if item_type in ('operation', 'file') and currents['contextrecord'] and \
- (not request.session["operation"] or
+ (not request.session.get("operation", None) or
currents['contextrecord'].operation != currents['operation']):
request.session["contextrecord"] = ''
currents['contextrecord'] = None
from archaeological_finds.models import Find
if item_type in ('contextrecord', 'operation', 'file') and \
currents['find'] and \
- (not request.session["contextrecord"] or
+ (not request.session.get("contextrecord", None) or
not Find.objects.filter(
downstream_treatment__isnull=True,
base_finds__context_record__pk=request.session["contextrecord"],