diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/migrations/0080_auto_20190111_1755.py | 36 | ||||
| -rw-r--r-- | ishtar_common/models.py | 12 | ||||
| -rw-r--r-- | ishtar_common/templatetags/window_field.py | 6 | ||||
| -rw-r--r-- | ishtar_common/utils.py | 10 | 
4 files changed, 49 insertions, 15 deletions
| diff --git a/ishtar_common/migrations/0080_auto_20190111_1755.py b/ishtar_common/migrations/0080_auto_20190111_1755.py new file mode 100644 index 000000000..3043c50d7 --- /dev/null +++ b/ishtar_common/migrations/0080_auto_20190111_1755.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2019-01-11 17:55 +from __future__ import unicode_literals + +import django.contrib.postgres.fields.jsonb +from django.db import migrations + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0079_migrate-importers'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='historicalorganization', +            name='history_m2m', +            field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default={}), +        ), +        migrations.AddField( +            model_name='historicalperson', +            name='history_m2m', +            field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default={}), +        ), +        migrations.AddField( +            model_name='organization', +            name='history_m2m', +            field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default={}), +        ), +        migrations.AddField( +            model_name='person', +            name='history_m2m', +            field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default={}), +        ), +    ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e5e173654..ef7dc8a4e 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -69,7 +69,7 @@ from ishtar_common.models_imports import ImporterModel, ImporterType, \      Import, TargetKeyGroup  from ishtar_common.utils import get_cache, disable_for_loaddata, create_slug, \      get_all_field_names, merge_tsvectors, cached_label_changed, \ -    generate_relation_graph, HISTORY_M2M_SPLIT +    generate_relation_graph  __all__ = [      'ImporterModel', 'ImporterType', 'ImporterDefault', 'ImporterDefaultValues', @@ -153,11 +153,10 @@ class HistoryModel(models.Model):          abstract = True      def m2m_listing(self, key): -        hist_value = getattr(self, "historical_" + key, None) -        if not hist_value: +        if not self.history_m2m or key not in self.history_m2m:              return          related_model = getattr(self, key).model -        return related_model.history_decompress(hist_value) +        return related_model.history_decompress(self.history_m2m[key])  class HistoricalRecords(BaseHistoricalRecords): @@ -539,7 +538,7 @@ class GeneralType(Cached, models.Model):          if not value:              return []          res = [] -        for txt_idx in value.split(HISTORY_M2M_SPLIT): +        for txt_idx in value:              try:                  res.append(cls.objects.get(txt_idx=txt_idx))              except cls.DoesNotExist: @@ -1481,6 +1480,7 @@ class BaseHistorizedItem(DocumentItem, FullSearch, Imported, JsonData,          User, related_name='+', on_delete=models.SET_NULL,          verbose_name=_(u"Creator"), blank=True, null=True)      last_modified = models.DateTimeField(auto_now=True) +    history_m2m = JSONField(default={}, blank=True)      class Meta:          abstract = True @@ -2827,6 +2827,7 @@ class OrganizationManager(models.Manager):  class Organization(Address, Merge, OwnPerms, ValueGetter):      TABLE_COLS = ('name', 'organization_type', 'town') +    SLUG = "organization"      SHOW_URL = 'show-organization'      # search parameters @@ -2954,6 +2955,7 @@ class PersonManager(models.Manager):  class Person(Address, Merge, OwnPerms, ValueGetter): +    SLUG = "person"      _prefix = 'person_'      TYPE = (          ('Mr', _(u'Mr')), diff --git a/ishtar_common/templatetags/window_field.py b/ishtar_common/templatetags/window_field.py index df72690c4..d843d3030 100644 --- a/ishtar_common/templatetags/window_field.py +++ b/ishtar_common/templatetags/window_field.py @@ -101,14 +101,14 @@ from django.template import Library, loader, Context  @register.simple_tag  def field_multiple_obj(caption, item, attr, li=False, size=None):      data = getattr(item, attr) -    if not hasattr(item, '_step') or not hasattr(item, 'historical_' + attr): +    if not hasattr(item, '_step') or attr not in item.history_m2m \ +            or not item.history_m2m[attr]:          t = loader.get_template('ishtar/blocks/window_field_flex_multiple.html')          return t.render(              {'caption': caption, 'data': data, 'li': li, "size": size}          )      rel_model = data.model -    data = getattr(item, 'historical_' + attr) -    data = rel_model.history_decompress(data) +    data = rel_model.history_decompress(item.history_m2m[attr])      t = loader.get_template(          'ishtar/blocks/window_field_flex_historized_multiple.html')      return t.render( diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 56c6f669f..e293562ff 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -931,26 +931,22 @@ def get_urls_for_model(model, views, own=False, autocomplete=False,      return urls -HISTORY_M2M_SPLIT = u"*||*" - -  def m2m_historization_changed(sender, **kwargs):      obj = kwargs.get('instance', None)      if not obj:          return -    hist_values = {} +    hist_values = obj.history_m2m or {}      for attr in obj.HISTORICAL_M2M:          values = []          for value in getattr(obj, attr).all():              if not hasattr(value, "history_compress"):                  continue              values.append(value.history_compress()) -        hist_values['historical_' + attr] = HISTORY_M2M_SPLIT.join(values) -    for key in hist_values: -        setattr(obj, key, hist_values[key]) +        hist_values[attr] = values      # force resave of last history record      if hasattr(obj, 'skip_history_when_saving'):          delattr(obj, 'skip_history_when_saving') +    obj.history_m2m = hist_values      obj._force_history = True      q = obj.history.order_by("-history_date")      if q.count(): | 
