diff options
Diffstat (limited to 'ishtar_common/models_common.py')
| -rw-r--r-- | ishtar_common/models_common.py | 30 | 
1 files changed, 18 insertions, 12 deletions
| diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 4abc81a76..4f82cde8f 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -5,16 +5,6 @@  Generic models and tools for models  """ -""" -from ishtar_common.models import GeneralType, get_external_id, \ -    LightHistorizedItem, OwnPerms, Address, post_save_cache, \ -    DashboardFormItem, document_attached_changed, SearchAltName, \ -    DynamicRequest, GeoItem, QRCodeItem, SearchVectorConfig, DocumentItem, \ -    QuickAction, MainItem, Merge - - -""" -  import copy  from collections import OrderedDict  import datetime @@ -65,6 +55,16 @@ from ishtar_common.utils import get_cache, disable_for_loaddata, \  logger = logging.getLogger(__name__) +""" +from ishtar_common.models import GeneralType, get_external_id, \ +    LightHistorizedItem, OwnPerms, Address, post_save_cache, \ +    DashboardFormItem, document_attached_changed, SearchAltName, \ +    DynamicRequest, GeoItem, QRCodeItem, SearchVectorConfig, DocumentItem, \ +    QuickAction, MainItem, Merge + + +""" +  class CachedGen(object):      @classmethod @@ -2364,6 +2364,8 @@ def document_attached_changed(sender, **kwargs):              return      for item in items: +        for doc in item.documents.all(): +            doc.regenerate_all_ids()          q = item.documents.filter(              image__isnull=False).exclude(image='')          if item.main_image: @@ -2727,8 +2729,8 @@ class CompleteIdentifierItem(models.Model, ImageContainerModel):          if not key or not key.strip():              return          keys = key.strip().split(";") -        if len(key) == 1 and hasattr(self, "get_index_" + key):  # custom index -            # generation +        if len(keys) == 1 and hasattr(self, "get_index_" + keys[0]): +            # custom index generation              return getattr(self, "get_index_" + key)()          model = self.__class__          try: @@ -2758,6 +2760,9 @@ class CompleteIdentifierItem(models.Model, ImageContainerModel):      def save(self, *args, **kwargs):          super(CompleteIdentifierItem, self).save(*args, **kwargs) +        self.regenerate_all_ids() + +    def regenerate_all_ids(self):          if getattr(self, "_prevent_loop", False):              return          modified = False @@ -2771,6 +2776,7 @@ class CompleteIdentifierItem(models.Model, ImageContainerModel):              self.complete_identifier = complete_id          if modified:              self._prevent_loop = True +            self.skip_history_when_saving = True              self.save() | 
