diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-09-12 00:18:46 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-09-12 00:18:46 +0200 |
commit | a96790a5a0899bf1860c7fd1989fe623dee2a4a4 (patch) | |
tree | ea0c07d37f724099bf2d613fe8f29138e0a43257 | |
parent | 07cc588198eb6503a6cc973dac8e97788912778d (diff) | |
download | Ishtar-a96790a5a0899bf1860c7fd1989fe623dee2a4a4.tar.bz2 Ishtar-a96790a5a0899bf1860c7fd1989fe623dee2a4a4.zip |
Serializations: ActType filter in types - Full export of ActType in conf
-rw-r--r-- | archaeological_operations/models.py | 1 | ||||
-rw-r--r-- | ishtar_common/serializers.py | 9 | ||||
-rw-r--r-- | ishtar_common/serializers_utils.py | 8 |
3 files changed, 14 insertions, 4 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 6a25490d7..a120e7db5 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1735,6 +1735,7 @@ class ActType(GeneralType): ('TF', _(u'Treatment request')), ('T', _(u'Treatment')), ) + SERIALIZATION_EXCLUDE = ["associated_template"] intented_to = models.CharField(_("Intended to"), max_length=2, choices=TYPE) code = models.CharField(_("Code"), max_length=10, blank=True, null=True) diff --git a/ishtar_common/serializers.py b/ishtar_common/serializers.py index 50a48d79b..d2e3c2b98 100644 --- a/ishtar_common/serializers.py +++ b/ishtar_common/serializers.py @@ -13,6 +13,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.auth.models import Group, Permission from . import models +from archaeological_operations.models import ActType from ishtar_common.serializers_utils import generic_get_results, \ archive_serialization, generic_archive_files, SERIALIZATION_VERSION, \ @@ -56,16 +57,20 @@ CONF_MODEL_LIST = [ models.IshtarSiteProfile, models.GlobalVar, models.CustomForm, models.ExcludedField, models.JsonDataSection, models.JsonDataField, models.CustomFormJsonField, models.ImporterModel, - models.DocumentTemplate + models.DocumentTemplate, ActType ] +CONF_SERIALIZATION_INCLUDE = {ActType.__name__: ["associated_template"]} + def conf_serialization(archive=False, return_empty_types=False, archive_name=None): media_archive = None if archive: media_archive = generic_archive_files(CONF_MODEL_LIST) - result = generic_get_results(CONF_MODEL_LIST, "common_configuration") + result = generic_get_results( + CONF_MODEL_LIST, "common_configuration", + serialization_include=CONF_SERIALIZATION_INCLUDE) full_archive = archive_serialization( result, archive_dir="common_configuration", archive=archive, return_empty_types=return_empty_types, archive_name=archive_name) diff --git a/ishtar_common/serializers_utils.py b/ishtar_common/serializers_utils.py index efa390e59..e3b132ae0 100644 --- a/ishtar_common/serializers_utils.py +++ b/ishtar_common/serializers_utils.py @@ -108,7 +108,7 @@ def archive_serialization(result, archive_dir=None, archive=False, def generic_get_results(model_list, dirname, no_geo=True, - result_queryset=None): + result_queryset=None, serialization_include=None): result = OrderedDict() for model in model_list: base_model_name = model.__name__ @@ -173,11 +173,15 @@ def generic_get_results(model_list, dirname, no_geo=True, excluded_fields = ["history_modifier", "history_creator", "imports", "locked", "lock_user"] if hasattr(model, "SERIALIZATION_EXCLUDE"): - excluded_fields = list(model.SERIALIZATION_EXCLUDE) + excluded_fields += list(model.SERIALIZATION_EXCLUDE) if no_geo: excluded_fields += ["center", "limit"] + [ field.name for field in models.GeoItem._meta.get_fields() ] + if serialization_include and model.__name__ in serialization_include: + for k in serialization_include[model.__name__]: + if k in excluded_fields: + excluded_fields.pop(excluded_fields.index(k)) if excluded_fields: new_result = json.loads(result[key]) for idx in range(len(new_result)): |