diff options
| -rw-r--r-- | archaeological_context_records/forms.py | 45 | ||||
| -rw-r--r-- | archaeological_context_records/models.py | 10 | ||||
| -rw-r--r-- | archaeological_finds/forms.py | 6 | ||||
| -rw-r--r-- | archaeological_finds/models_finds.py | 7 | ||||
| -rw-r--r-- | archaeological_operations/forms.py | 73 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 41 | ||||
| -rw-r--r-- | archaeological_operations/templates/ishtar/sheet_site.html | 3 | ||||
| -rw-r--r-- | ishtar_common/forms.py | 58 | ||||
| -rw-r--r-- | ishtar_common/models.py | 34 | ||||
| -rw-r--r-- | ishtar_common/models_common.py | 20 | ||||
| -rw-r--r-- | ishtar_common/widgets.py | 14 |
11 files changed, 222 insertions, 89 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 93ff65c25..0e5b752eb 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -20,7 +20,6 @@ """ Context records forms definitions """ -from collections import OrderedDict from copy import copy from itertools import groupby @@ -54,6 +53,7 @@ from ishtar_common.forms import ( MultiSearchForm, LockForm, GeoItemSelect, + DatingSelect, QAForm, ) from ishtar_common.forms_common import get_town_field @@ -90,46 +90,7 @@ class OperationFormSelection(CustomForm, forms.Form): ) -class PeriodSelect(forms.Form): - datings__period = forms.ChoiceField(label=_("Dating - period"), choices=[]) - datings__precise_dating = forms.CharField(label=_("Dating - precise")) - datings__start_date = forms.IntegerField(label=_("Dating - start date")) - datings__end_date = forms.IntegerField(label=_("Dating - end date")) - datings__dating_type = forms.ChoiceField( - label=_("Dating - dating type"), choices=[] - ) - datings__quality = forms.ChoiceField(label=_("Dating - dating quality"), choices=[]) - TYPES = [ - FieldType("datings__period", Period), - FieldType("datings__dating_type", models.DatingType), - FieldType("datings__quality", models.DatingQuality), - ] - PERIOD_FIELDS = [ - "datings__period", - "datings__precise_dating", - "datings__start_date", - "datings__end_date", - "datings__dating_type", - "datings__quality", - ] - - def _reorder_period_fields(self, insert_period_after): - fields = OrderedDict() - for key in self.fields: - if key in self.PERIOD_FIELDS: - continue - fields[key] = self.fields[key] - if key == insert_period_after: - for period_key in self.PERIOD_FIELDS: - if period_key not in self.fields: - continue - fields[period_key] = self.fields[period_key] - if period_key in self.fields: - fields[period_key] = self.fields[period_key] - self.fields = fields - - -class RecordSelect(GeoItemSelect, PeriodSelect): +class RecordSelect(GeoItemSelect, DatingSelect): _model = models.ContextRecord form_admin_name = _("Context record - 001 - Search") form_slug = "contextrecord-001-search" @@ -192,7 +153,7 @@ class RecordSelect(GeoItemSelect, PeriodSelect): colors = forms.ChoiceField(label=_("Colors"), choices=[]) details_on_color = forms.CharField(label=_("Details on color")) - TYPES = PeriodSelect.TYPES + [ + TYPES = DatingSelect.TYPES + [ FieldType('area', Area), FieldType("periods", Period), FieldType('cultural_attributions', models.CulturalAttributionType), diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index d1b1fb147..6b6f0f039 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -440,8 +440,9 @@ class ContextRecord( "documents__associated_file__isnull", "documents__associated_url__isnull", ] - NUMBER_FIELDS = ["operation__year", "operation__operation_code", "datings__start_date", - "datings__end_date"] + GeographicSubTownItem.NUMBER_FIELDS + NUMBER_FIELDS = [ + "operation__year", "operation__operation_code" + ] + GeographicSubTownItem.NUMBER_FIELDS + BaseDating.NUMBER_FIELDS RELATION_TYPES_PREFIX = { "ope_relation_types": "operation__", @@ -486,9 +487,9 @@ class ContextRecord( pgettext_lazy("key for text search", "operation-relation-type"), "ope_relation_types", ), - "datings__period": SearchAltName( + "period": SearchAltName( pgettext_lazy("key for text search", "period"), - "datings__period__label__iexact", + "periods__label__iexact", ), "unit": SearchAltName( pgettext_lazy("key for text search", "unit-type"), "unit__label__iexact" @@ -573,6 +574,7 @@ class ContextRecord( ALT_NAMES.update(Dating.ASSOCIATED_ALT_NAMES) ALT_NAMES.update(GeoItem.ALT_NAMES) ALT_NAMES.update(Imported.ALT_NAMES) + ALT_NAMES.update(BaseDating.ALT_NAMES) DEFAULT_SEARCH_FORM = ("archaeological_context_records.forms", "RecordSelect") diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index d4f954d59..727657fc2 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -92,7 +92,7 @@ from ishtar_common.forms import ( GeoItemSelect, ) from ishtar_common.forms_common import get_town_field -from archaeological_context_records.forms import PeriodSelect +from archaeological_context_records.forms import DatingSelect from ishtar_common.models import ( Area, @@ -1616,7 +1616,7 @@ class DateForm(ManageOldType, forms.Form): ] -class FindSelect(MuseumForm, GeoItemSelect, PeriodSelect): +class FindSelect(MuseumForm, GeoItemSelect, DatingSelect): _model = models.Find form_admin_name = _("Find - 001 - Search") form_slug = "find-001-search" @@ -2017,7 +2017,7 @@ class FindSelect(MuseumForm, GeoItemSelect, PeriodSelect): museum_allocation_date = DateField(label=_("Museum - Date of allocation")) museum_purchase_price = forms.CharField(label=_("Museum - Purchase price")) - TYPES = PeriodSelect.TYPES + [ + TYPES = DatingSelect.TYPES + [ FieldType("periods", Period), FieldType("conservatory_states", models.ConservatoryState), FieldType("base_finds__batch", models.BatchType), diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 9b4156a9d..5f26fc443 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -207,6 +207,7 @@ class TreatmentType(HierarchicalType): initial=None, force=False, full_hierarchy=False, + limit=None ): types = super(TreatmentType, cls).get_types( dct=dct, @@ -217,6 +218,7 @@ class TreatmentType(HierarchicalType): initial=initial, force=force, full_hierarchy=full_hierarchy, + limit=limit ) if dct and not exclude: rank = 0 @@ -1405,15 +1407,13 @@ class Find( "weight", "find_number", "min_number_of_individuals", - "datings__start_date", - "datings__end_date", "clutter_long_side", "clutter_short_side", "clutter_height", "museum_inventory_entry_year", "museum_inventory_quantity", "museum_observed_quantity", - ] + GeographicSubTownItem.NUMBER_FIELDS + ] + GeographicSubTownItem.NUMBER_FIELDS + BaseDating.NUMBER_FIELDS BASE_REQUEST = {"downstream_treatment__isnull": True} EXTRA_REQUEST_KEYS = { "all_base_finds__context_record": "base_finds__context_record__context_record_tree_parent__cr_parent_id", @@ -1922,6 +1922,7 @@ class Find( ALT_NAMES.update(Dating.ASSOCIATED_ALT_NAMES) ALT_NAMES.update(GeoItem.ALT_NAMES_FOR_FIND()) ALT_NAMES.update(Imported.ALT_NAMES) + ALT_NAMES.update(BaseDating.ALT_NAMES) DEFAULT_SEARCH_FORM = ("archaeological_finds.forms", "FindSelect") diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 82f41c089..79e265e93 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -41,7 +41,7 @@ from ishtar_common import widgets from ishtar_common.forms import FinalForm, FormSet, \ reverse_lazy, get_data_from_formset, QAForm, CustomFormSearch,\ ManageOldType, IshtarForm, CustomForm, FieldType, FormHeader, \ - GeoItemSelect, LockForm, MultiSearchForm, DocumentItemSelect + GeoItemSelect, LockForm, MultiSearchForm, DocumentItemSelect, DatingSelect from ishtar_common.forms_common import TownFormSet, get_town_field, TownForm from ishtar_common.models import valid_id, valid_ids, Person, Town, \ DocumentTemplate, Organization, get_current_profile, \ @@ -1173,7 +1173,7 @@ class OperationDeletionForm(FinalForm): ######### -class SiteSelect(GeoItemSelect): +class SiteSelect(GeoItemSelect, DatingSelect): _model = models.ArchaeologicalSite form_admin_name = _("Archaeological site - 001 - Search") form_slug = "archaeological_site-001-search" @@ -1186,23 +1186,48 @@ class SiteSelect(GeoItemSelect): name = forms.CharField(label=_("Name"), max_length=200, required=False) other_reference = forms.CharField(label=_("Other reference"), max_length=200, required=False) - types = widgets.Select2MultipleField(label=_("Types"), required=False) + types = widgets.Select2SimpleField(label=_("Types"), required=False, + modal="modal-advanced-search") + heritage_interest = forms.ChoiceField(label=_("Heritage interests"), choices=[], + required=False) + actors = forms.IntegerField( + label=_("Actors"), required=False, + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-qualifiedbiographicalnote'))) + collaborators = forms.IntegerField( + label=_("Collaborators"), required=False, + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-person'))) + protection_id = forms.CharField(label=_("Protection ID"), required=False) + protection_date = DateField(label=_("Protection date"), required=False) + heritage_environmental_protections = forms.ChoiceField( + label=_("Heritage and environmental protections"), choices=[], + required=False) + details_on_protection = forms.CharField(label=_("Details on protection"), + required=False) discoverer = forms.IntegerField( - widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person'), associated_model=Person), + widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person'), + associated_model=Person), label=_("Discoverer")) - periods = forms.ChoiceField(label=_("Periods"), choices=[], required=False) - remains = forms.ChoiceField(label=_("Remains"), choices=[], required=False) - cultural_attributions = forms.ChoiceField( - label=_("Cultural attribution"), choices=[], required=False) - discovery_status = forms.ChoiceField(label=_("Discovery status"), choices=[], required=False) - current_status = forms.ChoiceField(label=_("Current status"), choices=[], required=False) - nature_of_site = forms.ChoiceField(label=_("Nature of site"), choices=[], required=False) - interpretation_level = forms.ChoiceField(label=_("Interpretation level"), choices=[], required=False) + periods = widgets.Select2SimpleField(label=_("Periods"), required=False, + modal="modal-advanced-search") + remains = widgets.Select2SimpleField(label=_("Remains"), required=False, + modal="modal-advanced-search") + cultural_attributions = widgets.Select2SimpleField( + label=_("Cultural attributions"), required=False, modal="modal-advanced-search") + discovery_status = forms.ChoiceField(label=_("Discovery status"), choices=[], + required=False) + current_states = forms.ChoiceField(label=_("Current states"), required=False) + nature_of_site = forms.ChoiceField(label=_("Nature of site"), choices=[], + required=False) + interpretation_level = forms.ChoiceField(label=_("Interpretation level"), + choices=[], required=False) + towns = get_town_field() towns__areas = forms.ChoiceField(label=_("Areas"), choices=[]) - description = forms.CharField(label=_("Description"), max_length=200, required=False) - public_description = forms.CharField(label=_("Public description"), max_length=200, required=False) - comment = forms.CharField(label=_("Comment"), max_length=200, required=False) + description = forms.CharField(label=_("Description"), required=False) + public_description = forms.CharField(label=_("Public description"), required=False) + comment = forms.CharField(label=_("Comment"), required=False) top_operation = forms.IntegerField( label=_("Top operation"), required=False, widget=widgets.JQueryAutoComplete( @@ -1241,17 +1266,26 @@ class SiteSelect(GeoItemSelect): discovery_area = forms.CharField( label=_("Discovery area"), max_length=200, required=False) + + editors = forms.IntegerField( + label=_("Editors"), required=False, + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-author'))) + TYPES = [ FieldType('periods', models.Period), FieldType('remains', models.RemainType), - FieldType("types", models.SiteType, is_multiple=True), - FieldType('current_status', models.SiteCurrentStatusType), + FieldType("types", models.SiteType), + FieldType('current_states', models.SiteCurrentStatusType), FieldType('discovery_status', models.SiteDiscoveryStatusType), FieldType('cultural_attributions', models.CulturalAttributionType), FieldType('nature_of_site', models.NatureOfSiteType), FieldType('interpretation_level', models.InterpretationLevelType), FieldType('towns__areas', Area), - ] + GeoItemSelect.TYPES + FieldType('heritage_interest', models.HeritageInterestType), + FieldType('heritage_environmental_protections', + models.HeritageAndEnvironmentalProtectionType), + ] + GeoItemSelect.TYPES + DatingSelect.TYPES def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -1265,6 +1299,7 @@ class SiteSelect(GeoItemSelect): 'affmar_number', 'drassm_number', )) + self._reorder_period_fields("comment") class SiteFormSelection(LockForm, CustomFormSearch): @@ -1343,7 +1378,7 @@ class SiteForm(CustomForm, ManageOldType): required=False) actor = widgets.Select2MultipleField( model=QualifiedBiographicalNote, label=_("Actors"), required=False, - remote=True, new=True) + remote=True, new=True, remote_filter='qualification_type__S-A') collaborator = widgets.Select2MultipleField( model=Person, label=_("Collaborators"), required=False, remote=True, new=True) diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 7bf654639..c34478b6c 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -475,8 +475,8 @@ class ArchaeologicalSite( "heritage_environmental_protections" ] - DATED_FIELDS = BaseHistorizedItem.DATED_FIELDS + ["sinking_date"] - NUMBER_FIELDS = GeographicTownItem.NUMBER_FIELDS[:] + DATED_FIELDS = BaseHistorizedItem.DATED_FIELDS + ["sinking_date", "protection_date"] + NUMBER_FIELDS = GeographicTownItem.NUMBER_FIELDS[:] + BaseDating.NUMBER_FIELDS EXTRA_REQUEST_KEYS = { "towns_label": "towns", @@ -516,9 +516,41 @@ class ArchaeologicalSite( pgettext_lazy("key for text search", "discovery-status"), "discovery_status__label__iexact" ), - "current_status": SearchAltName( + "current_states": SearchAltName( pgettext_lazy("key for text search", "current-status"), - "current_status__label__iexact" + "current_states__label__iexact" + ), + "actors": SearchAltName( + pgettext_lazy("key for text search", "actors"), + "actors__cached_label__iexact" + ), + "collaborators": SearchAltName( + pgettext_lazy("key for text search", "collaborators"), + "collaborators__cached_label__iexact" + ), + "editors": SearchAltName( + pgettext_lazy("key for text search", "editor"), + "editors__cached_label__iexact" + ), + "protection_id": SearchAltName( + pgettext_lazy("key for text search", "protection-id"), + "protection_id__iexact" + ), + "protection_date": SearchAltName( + pgettext_lazy("key for text search", "protection-date"), + "protection_date" + ), + "details_on_protection": SearchAltName( + pgettext_lazy("key for text search", "protection-details"), + "details_on_protection__iexact" + ), + "heritage_interest": SearchAltName( + pgettext_lazy("key for text search", "heritage-interest"), + "heritage_interests__label__iexact" + ), + "heritage_environmental_protections": SearchAltName( + pgettext_lazy("key for text search", "heritage-environmental-protection"), + "heritage_environmental_protections__label__iexact" ), "nature_of_site": SearchAltName( pgettext_lazy("key for text search", "nature"), @@ -606,6 +638,7 @@ class ArchaeologicalSite( ALT_NAMES.update(DocumentItem.ALT_NAMES) ALT_NAMES.update(GeoItem.ALT_NAMES) ALT_NAMES.update(Imported.ALT_NAMES) + ALT_NAMES.update(BaseDating.ALT_NAMES) DEFAULT_SEARCH_FORM = ("archaeological_operations.forms", "SiteSelect") diff --git a/archaeological_operations/templates/ishtar/sheet_site.html b/archaeological_operations/templates/ishtar/sheet_site.html index 1de4c367f..b648a709f 100644 --- a/archaeological_operations/templates/ishtar/sheet_site.html +++ b/archaeological_operations/templates/ishtar/sheet_site.html @@ -156,9 +156,10 @@ {% endif %} {% if not is_external %} -{% if item.history_creator or item.last_edition_date or item.created %} +{% if item.history_creator or item.last_edition_date or item.created or item.editors.count %} <h3>{% trans "Sheet"%}</h3> <div class="row"> + {% field_flex_multiple _("Editors") item.editors %} {% include "ishtar/blocks/sheet_creation_section.html" %} </div> {% endif %} diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 4db6a138b..87d498596 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -707,8 +707,8 @@ class FieldType: self.empty_first = empty_first self.help_text = help_text - def get_choices(self, initial=None): - args = {"empty_first": self.empty_first, "initial": initial} + def get_choices(self, initial=None, limit=None): + args = {"empty_first": self.empty_first, "initial": initial, "limit": limit} if self.extra_args: args.update(self.extra_args) return self.model.get_types(**args) @@ -848,10 +848,14 @@ class IshtarForm(BSForm, forms.Form): for field in type_lst: self._init_type(field) - def _init_type(self, field): + def _init_type(self, field, extra=None): if field.key not in self.fields: return - self.fields[field.key].choices = field.get_choices() + if not extra: + extra = {} + if hasattr(self, "limits") and field.key in self.limits: + extra["limit"] = self.limits[field.key] + self.fields[field.key].choices = field.get_choices(**extra) if not getattr(field, "help_text", True): return self.fields[field.key].help_text = field.get_help() @@ -1349,10 +1353,7 @@ class ManageOldType(IshtarForm): if field.key not in self.fields: return initial = self.init_data.getlist(field.key) - self.fields[field.key].choices = field.get_choices( - initial=initial - ) - self.fields[field.key].help_text = field.get_help() + super()._init_type(field, extra={"initial": initial}) class QAForm(CustomForm, ManageOldType): @@ -1570,6 +1571,47 @@ class GeoItemSelect(DocumentItemSelect): # all geo item can have documents ] + DocumentItemSelect.TYPES +class DatingSelect(forms.Form): + datings__period = forms.ChoiceField(label=_("Dating - period"), choices=[]) + datings__precise_dating = forms.CharField(label=_("Dating - precise")) + datings__start_date = forms.IntegerField(label=_("Dating - start date")) + datings__end_date = forms.IntegerField(label=_("Dating - end date")) + datings__dating_type = forms.ChoiceField( + label=_("Dating - dating type"), choices=[] + ) + datings__quality = forms.ChoiceField(label=_("Dating - dating quality"), choices=[]) + TYPES = [ + FieldType("datings__period", ("archaeological_operations", "Period")), + FieldType("datings__dating_type", + ("archaeological_context_records", "DatingType")), + FieldType("datings__quality", + ("archaeological_context_records", "DatingQuality")), + ] + PERIOD_FIELDS = [ + "datings__period", + "datings__precise_dating", + "datings__start_date", + "datings__end_date", + "datings__dating_type", + "datings__quality", + ] + + def _reorder_period_fields(self, insert_period_after): + fields = OrderedDict() + for key in self.fields: + if key in self.PERIOD_FIELDS: + continue + fields[key] = self.fields[key] + if key == insert_period_after: + for period_key in self.PERIOD_FIELDS: + if period_key not in self.fields: + continue + fields[period_key] = self.fields[period_key] + if period_key in self.fields: + fields[period_key] = self.fields[period_key] + self.fields = fields + + class QADating(ManageOldType, forms.Form): form_label = _("Dating") associated_models = { diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e52d210a6..5b06baba2 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -4702,6 +4702,10 @@ class QualifiedBiographicalNoteType(OrderedHierarchicalType): ordering = ["order", "label"] ADMIN_SECTION = _("Directory") + @classmethod + def _set_limit(cls, dct, limit): + dct["model__in"] = limit + post_save.connect(post_save_cache, sender=QualifiedBiographicalNoteType) post_delete.connect(post_save_cache, sender=QualifiedBiographicalNoteType) @@ -6200,6 +6204,7 @@ class OperationType(GeneralType): empty_first=True, default=None, initial=None, + limit=None ): dct = dct or {} exclude = exclude or [] @@ -6279,6 +6284,35 @@ class BaseDating(models.Model, SerializeItem): SERIALIZE_EXCLUDE = ["find", "context_record", "archaeological_site"] CURRENT_MODEL = None CURRENT_MODEL_ATTR = None + + ALT_NAMES = { + "datings__period": SearchAltName( + pgettext_lazy("key for text search", "dating-period"), + "datings__period__label__iexact", + ), + "datings__precise_dating": SearchAltName( + pgettext_lazy("key for text search", "dating-precision"), + "datings__precise_dating__iexact", + ), + "datings__start_date": SearchAltName( + pgettext_lazy("key for text search", "dating-start"), + "datings__start_date", + ), + "datings__end_date": SearchAltName( + pgettext_lazy("key for text search", "dating-end"), + "datings__end_date", + ), + "datings__dating_type": SearchAltName( + pgettext_lazy("key for text search", "dating-type"), + "datings__dating_type__label__iexact", + ), + "datings__quality": SearchAltName( + pgettext_lazy("key for text search", "dating-quality"), + "datings__quality__label__iexact", + ), + } + NUMBER_FIELDS = ["datings__start_date", "datings__end_date"] + uuid = models.UUIDField(default=uuid.uuid4) reference = models.TextField(_("Reference"), blank=True, default="") external_id = models.TextField(_("External ID"), blank=True, default="") diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index ba27b3bbc..117981e79 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -403,6 +403,7 @@ class GeneralType(Cached, models.Model): initial=None, force=False, full_hierarchy=False, + limit=None ): if not dct: dct = {} @@ -412,7 +413,8 @@ class GeneralType(Cached, models.Model): if not instances and empty_first and not default: types = [("", "--")] types += cls._pre_get_types( - dct, instances, exclude, default, force, get_full_hierarchy=full_hierarchy + dct, instances, exclude, default, force, get_full_hierarchy=full_hierarchy, + limit=limit ) if not initial: return types @@ -421,6 +423,13 @@ class GeneralType(Cached, models.Model): return types @classmethod + def _set_limit(cls, dct, limit): + """ + Translate limit set in forms to a query filter + """ + raise NotImplementedError(f"_set_limit method must be set for {cls}") + + @classmethod def _pre_get_types( cls, dct=None, @@ -429,6 +438,7 @@ class GeneralType(Cached, models.Model): default=None, force=False, get_full_hierarchy=False, + limit=None ): if not dct: dct = {} @@ -439,11 +449,15 @@ class GeneralType(Cached, models.Model): if not instances: keys = ["__get_types"] keys += ["{}".format(ex) for ex in exclude] + ["{}".format(default)] + if limit: + keys.append("lim" + ";".join(limit)) keys += ["{}-{}".format(str(k), dct[k]) for k in dct] cache_key, value = get_cache(cls, keys) if value and not force: return value base_dct = dct.copy() + if limit: + cls._set_limit(base_dct, limit) if hasattr(cls, "parent"): if not cache_key: return cls._get_parent_types( @@ -467,7 +481,9 @@ class GeneralType(Cached, models.Model): return vals if not cache_key: - return cls._get_types(base_dct, instances, exclude=exclude, default=default) + return cls._get_types( + base_dct, instances, exclude=exclude, default=default + ) vals = [ v for v in cls._get_types( diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index b11ae0c5d..304e6a669 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -232,12 +232,16 @@ class Select2DynamicMultipleField(forms.MultipleChoiceField): class Select2Base(Select2Media): def __init__( - self, attrs=None, choices=(), remote=None, model=None, new=None, available=None + self, attrs=None, choices=(), remote=None, model=None, new=None, available=None, + remote_filter=None ): self.remote = remote self.available = available self.model = model self.new = new + self.remote_filter = None + if attrs and "remote_filter" in attrs: + self.remote_filter = attrs.pop("remote_filter") super(Select2Base, self).__init__(attrs, choices) def get_q(self): @@ -275,8 +279,8 @@ class Select2Base(Select2Media): attrs["style"] = "width: 370px" if value and getattr(self, "multiple", False) and \ - not isinstance(value, (list, tuple)): - value = value.split(",") + not isinstance(value, (list, tuple)): + value = value.split(",") options = "" if self.remote: @@ -331,6 +335,8 @@ class Select2Base(Select2Media): html = "<div class='input-group'>" url_new = "new-" + self.model.SLUG url_new = reverse(url_new, args=["id_" + name]) + if self.remote_filter: + url_new += self.remote_filter # WARNING: the modal for the form must be in the main template # "extra_form_modals" list is used for that in form or view new = ( @@ -412,6 +418,8 @@ class Select2BaseField(object): attrs["modal"] = kwargs.pop("modal") if kwargs.get("style", None): attrs["style"] = kwargs.pop("style") + if kwargs.get("remote_filter", None): + attrs["remote_filter"] = kwargs.pop("remote_filter") kwargs["widget"] = widget( model=self.model, available=self.available, |
