summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 5ba631dba..030f817d9 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -29,7 +29,7 @@ from django.utils.translation import ugettext_lazy as _, pgettext, \
activate, pgettext_lazy, deactivate
from django.utils.text import slugify
-from ishtar_common.utils import cached_label_changed
+from ishtar_common.utils import cached_label_changed, HISTORY_M2M_SPLIT
from ishtar_common.models import Document, GeneralType, \
BaseHistorizedItem, HistoricalRecords, OwnPerms, ShortMenuItem, \
@@ -104,25 +104,30 @@ class Dating(models.Model):
return self.SEP.join(values)
@classmethod
- def history_decompress(cls, value):
- if not value:
- value = ""
- res = {}
- for idx, val in enumerate(value.split(cls.SEP)):
- key = cls.HISTORY_ATTR[idx]
- if val == '':
- val = None
- elif key in ("period", "dating_type", "quality"):
- field = cls._meta.get_field(key)
- q = field.related_model.objects.filter(txt_idx=val)
- if q.count():
- val = q.all()[0]
- else: # do not exist anymore in db
+ def history_decompress(cls, full_value, create=False):
+ if not full_value:
+ return []
+ full_res = []
+ for value in full_value.split(HISTORY_M2M_SPLIT):
+ res = {}
+ for idx, val in enumerate(value.split(cls.SEP)):
+ key = cls.HISTORY_ATTR[idx]
+ if val == '':
val = None
- elif key in ("start_date", "end_date"):
- val = int(val)
- res[key] = val
- return res
+ elif key in ("period", "dating_type", "quality"):
+ field = cls._meta.get_field(key)
+ q = field.related_model.objects.filter(txt_idx=val)
+ if q.count():
+ val = q.all()[0]
+ else: # do not exist anymore in db
+ val = None
+ elif key in ("start_date", "end_date"):
+ val = int(val)
+ res[key] = val
+ if create:
+ res = cls.objects.create(**res)
+ full_res.append(res)
+ return full_res
@classmethod
def is_identical(cls, dating_1, dating_2):