summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-18 15:36:26 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-18 15:36:26 +0200
commit4f23c4050eb57b2f2ee2af79f66f0191aab96efd (patch)
tree68971bdc42ab6208ba8a47e48f6bd6aa296d0241
parent580818aedffebce068728de1d36ffdb8447fee14 (diff)
downloadIshtar-4f23c4050eb57b2f2ee2af79f66f0191aab96efd.tar.bz2
Ishtar-4f23c4050eb57b2f2ee2af79f66f0191aab96efd.zip
Manage alternative profiles for labels, external ids, etc.
-rw-r--r--archaeological_context_records/models.py10
-rw-r--r--archaeological_finds/models_finds.py12
-rw-r--r--ishtar_common/alternative_configs.py27
-rw-r--r--ishtar_common/migrations/0068_ishtarsiteprofile_config.py20
-rw-r--r--ishtar_common/models.py14
5 files changed, 83 insertions, 0 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 04639bb56..6061ad09c 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -549,6 +549,16 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,
u"/{}/{}".format(self.SLUG, slugify(self.label or u"00"))
@property
+ def archaeological_site_reference(self):
+ if self.archaeological_site:
+ return self.archaeological_site.reference
+ if self.operation.archaeological_sites.count():
+ return u"-".join(
+ [a.reference for a in self.operation.archaeological_sites.all()]
+ )
+ return u""
+
+ @property
def reference(self):
if not self.operation:
return "00"
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 41752be0b..882bcd811 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -33,6 +33,8 @@ from django.utils.translation import ugettext_lazy as _, pgettext_lazy, \
from ishtar_common.data_importer import post_importer_action, ImporterError
from ishtar_common.utils import cached_label_changed, post_save_point
+from ishtar_common.alternative_configs import ALTERNATE_CONFIGS
+
from ishtar_common.models import Document, GeneralType, \
HierarchicalType, BaseHistorizedItem, ShortMenuItem, LightHistorizedItem, \
HistoricalRecords, OwnPerms, Person, Basket, post_save_cache, \
@@ -365,6 +367,9 @@ class BaseFind(BulkUpdatedItem, BaseHistorizedItem, OwnPerms):
return settings.JOINT.join(c_id)
def complete_id(self):
+ profile = get_current_profile()
+ if profile.has_overload('basefind_complete_id'):
+ return ALTERNATE_CONFIGS[profile.config].basefind_complete_id(self)
# OPE|MAT.CODE|UE|FIND_index
c_id = [self._ope_code()]
@@ -385,6 +390,9 @@ class BaseFind(BulkUpdatedItem, BaseHistorizedItem, OwnPerms):
return self.complete_id()
def short_id(self):
+ profile = get_current_profile()
+ if profile.has_overload('basefind_short_id'):
+ return ALTERNATE_CONFIGS[profile.config].basefind_short_id(self)
# OPE|FIND_index
c_id = [self._ope_code()]
c_id.append((u'{:0' + str(settings.ISHTAR_FINDS_INDEX_ZERO_LEN) + 'd}'
@@ -1079,6 +1087,10 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
@property
def administrative_index(self):
+ profile = get_current_profile()
+ if profile.has_overload('find_administrative_index'):
+ return ALTERNATE_CONFIGS[profile.config].find_administrative_index(
+ self)
bf = self.get_first_base_find()
if not bf or not bf.context_record or not bf.context_record.operation:
return ""
diff --git a/ishtar_common/alternative_configs.py b/ishtar_common/alternative_configs.py
new file mode 100644
index 000000000..269b44948
--- /dev/null
+++ b/ishtar_common/alternative_configs.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+class ConfigDrassm(object):
+ LABEL = u"DRASSM"
+
+ @classmethod
+ def find_administrative_index(cls, find):
+ return find.external_id
+
+ @classmethod
+ def basefind_complete_id(cls, basefind):
+ return basefind.external_id
+
+ @classmethod
+ def basefind_short_id(cls, basefind):
+ return basefind.external_id
+
+
+ALTERNATE_CONFIGS = {
+ 'DRASSM': ConfigDrassm
+}
+
+ALTERNATE_CONFIGS_CHOICES = [
+ (k, choice.LABEL) for k, choice in ALTERNATE_CONFIGS.items()
+]
diff --git a/ishtar_common/migrations/0068_ishtarsiteprofile_config.py b/ishtar_common/migrations/0068_ishtarsiteprofile_config.py
new file mode 100644
index 000000000..05acb47be
--- /dev/null
+++ b/ishtar_common/migrations/0068_ishtarsiteprofile_config.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-08-18 14:54
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0067_auto_20180816_1832'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='ishtarsiteprofile',
+ name='config',
+ field=models.CharField(blank=True, choices=[(b'DRASSM', 'DRASSM')], help_text='Choose an alternate configuration for label, index management', max_length=200, null=True, verbose_name='Alternate configuration'),
+ ),
+ ]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index ac639168c..dfcf503af 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -58,6 +58,9 @@ from secretary import Renderer as SecretaryRenderer
from simple_history.models import HistoricalRecords as BaseHistoricalRecords
from unidecode import unidecode
+from ishtar_common.alternative_configs import ALTERNATE_CONFIGS, \
+ ALTERNATE_CONFIGS_CHOICES
+
from ishtar_common.model_merging import merge_model_objects
from ishtar_common.models_imports import ImporterModel, ImporterType, \
ImporterDefault, ImporterDefaultValues, ImporterColumn, \
@@ -1703,6 +1706,13 @@ class IshtarSiteProfile(models.Model, Cached):
experimental_feature = models.BooleanField(
_(u"Activate experimental feature"), default=False)
description = models.TextField(_(u"Description"), null=True, blank=True)
+ config = models.CharField(
+ _(u"Alternate configuration"), max_length=200,
+ choices=ALTERNATE_CONFIGS_CHOICES,
+ help_text=_(u"Choose an alternate configuration for label, "
+ u"index management"),
+ null=True, blank=True
+ )
files = models.BooleanField(_(u"Files module"), default=False)
archaeological_site = models.BooleanField(
_(u"Archaeological site module"), default=False)
@@ -1814,6 +1824,10 @@ class IshtarSiteProfile(models.Model, Cached):
def __unicode__(self):
return unicode(self.label)
+ def has_overload(self, key):
+ return self.config and self.config in ALTERNATE_CONFIGS and \
+ hasattr(ALTERNATE_CONFIGS[self.config], key)
+
@classmethod
def get_current_profile(cls, force=False):
cache_key, value = get_cache(cls, ['is-current-profile'])