summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-27 12:33:14 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-27 12:33:14 +0100
commitea5150055203a014b4dc8fa6098634eb211a81b6 (patch)
tree4d0daee448a5d8868685f90a23d1671579fd3609
parent8b77d3f69f560aac666aa2daba4edd61d062c9d0 (diff)
downloadIshtar-ea5150055203a014b4dc8fa6098634eb211a81b6.tar.bz2
Ishtar-ea5150055203a014b4dc8fa6098634eb211a81b6.zip
Operations: fix bulk update of context records for old postgresql version (refs #3472)
-rw-r--r--archaeological_context_records/models.py37
-rw-r--r--archaeological_operations/tests.py1
2 files changed, 21 insertions, 17 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index c45cb1fd4..1ec32ea83 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -290,30 +290,33 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms,
sql = """
UPDATE "archaeological_context_records_contextrecord" AS cr
SET cached_label =
- CASE context_records_cached_label_bulk_update.main_code
- WHEN NULL THEN
- CASE context_records_cached_label_bulk_update.year
- IS NOT NULL
- AND context_records_cached_label_bulk_update.ope_code
- IS NOT NULL
- WHEN TRUE THEN
- '{ope_prefix}' ||
- context_records_cached_label_bulk_update.year ||
- '-' ||
- context_records_cached_label_bulk_update.ope_code
- ELSE ''
- END
- ELSE
- '{main_ope_prefix}' ||
- context_records_cached_label_bulk_update.main_code
+ CASE
+ WHEN context_records_cached_label_bulk_update.main_code
+ IS NULL
+ THEN
+ CASE
+ WHEN context_records_cached_label_bulk_update.year
+ IS NOT NULL
+ AND context_records_cached_label_bulk_update.ope_code
+ IS NOT NULL
+ THEN
+ '{ope_prefix}' ||
+ context_records_cached_label_bulk_update.year ||
+ '-' ||
+ context_records_cached_label_bulk_update.ope_code
+ ELSE ''
END
+ ELSE
+ '{main_ope_prefix}' ||
+ context_records_cached_label_bulk_update.main_code
+ END
|| '{join}' ||
context_records_cached_label_bulk_update.section || '{join}' ||
context_records_cached_label_bulk_update.number || '{join}' ||
context_records_cached_label_bulk_update.label
FROM context_records_cached_label_bulk_update
WHERE cr.id = context_records_cached_label_bulk_update.id
- AND cr.id IN (
+ AND cr.id IN (
SELECT id FROM archaeological_context_records_contextrecord
WHERE {where}
);
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index ab485572a..25f278880 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -806,6 +806,7 @@ class OperationTest(TestCase, OperationInitTest):
self.assertEqual(ope_id, '{}2011-1'.format(
settings.ISHTAR_DEF_OPE_PREFIX))
+ operation = models.Operation.objects.get(pk=operation.pk)
operation.code_patriarche = '666'
operation.save()
cr = ContextRecord.objects.get(pk=cr.pk)