diff --git a/passbook/admin/forms/base.py b/passbook/admin/forms/base.py deleted file mode 100644 index 6e05ab421..000000000 --- a/passbook/admin/forms/base.py +++ /dev/null @@ -1,40 +0,0 @@ -"""passbook form helpers""" -from django import forms - -from passbook.admin.fields import YAMLField - - -class TagModelForm(forms.ModelForm): - """Base form for models that have attributes""" - - def __init__(self, *args, **kwargs): - # Check if we have an instance, load tags otherwise use an empty dict - instance = kwargs.get("instance", None) - tags = instance.tags if instance else {} - # Make sure all predefined tags exist in tags, and set default if they don't - predefined_tags = ( - self._meta.model().get_predefined_tags() # pylint: disable=no-member - ) - for key, value in predefined_tags.items(): - if key not in tags: - tags[key] = value - # Format JSON - kwargs["initial"]["tags"] = tags - super().__init__(*args, **kwargs) - - def clean_tags(self): - """Make sure all required tags are set""" - if hasattr(self.instance, "get_required_keys") and hasattr( - self.instance, "tags" - ): - for key in self.instance.get_required_keys(): - if key not in self.cleaned_data.get("tags"): - raise forms.ValidationError("Tag %s missing." % key) - return self.cleaned_data.get("tags") - - -# pylint: disable=too-few-public-methods -class TagModelFormMeta: - """Base Meta class that uses the YAMLField""" - - field_classes = {"tags": YAMLField} diff --git a/passbook/core/api/propertymappings.py b/passbook/core/api/propertymappings.py index 8567a49e6..7e72d65bf 100644 --- a/passbook/core/api/propertymappings.py +++ b/passbook/core/api/propertymappings.py @@ -17,7 +17,7 @@ class PropertyMappingSerializer(ModelSerializer): class Meta: model = PropertyMapping - fields = ["pk", "name", "__type__"] + fields = ["pk", "name", "expression", "__type__"] class PropertyMappingViewSet(ReadOnlyModelViewSet): diff --git a/passbook/lib/fields.py b/passbook/lib/fields.py deleted file mode 100644 index 09dbcb3ec..000000000 --- a/passbook/lib/fields.py +++ /dev/null @@ -1,48 +0,0 @@ -"""passbook lib fields""" -from itertools import chain - -from django import forms -from django.contrib.postgres.utils import prefix_validation_error - -from passbook.lib.widgets import DynamicArrayWidget - - -class DynamicArrayField(forms.Field): - """Show array field as a dynamic amount of textboxes""" - - default_error_messages = { - "item_invalid": "Item %(nth)s in the array did not validate: " - } - - def __init__(self, base_field, **kwargs): - self.base_field = base_field - self.max_length = kwargs.pop("max_length", None) - kwargs.setdefault("widget", DynamicArrayWidget) - super().__init__(**kwargs) - - def clean(self, value): - cleaned_data = [] - errors = [] - value = [x for x in value if x] - for index, item in enumerate(value): - try: - cleaned_data.append(self.base_field.clean(item)) - except forms.ValidationError as error: - errors.append( - prefix_validation_error( - error, - self.error_messages["item_invalid"], - code="item_invalid", - params={"nth": index}, - ) - ) - if errors: - raise forms.ValidationError(list(chain.from_iterable(errors))) - if not cleaned_data and self.required: - raise forms.ValidationError(self.error_messages["required"]) - return cleaned_data - - def has_changed(self, initial, data): - if not data and not initial: - return False - return super().has_changed(initial, data) diff --git a/passbook/static/static/passbook/pf.css b/passbook/static/static/passbook/pf.css index e835a8203..483c05d08 100644 --- a/passbook/static/static/passbook/pf.css +++ b/passbook/static/static/passbook/pf.css @@ -16,31 +16,6 @@ max-height: var(--pf-c-login__main-footer-links-item-link-svg--Height); } -/* Dynamic array widget */ -.dynamic-array-widget .array-item { - display: flex; - align-items: center; - margin-bottom: 15px; -} - -.dynamic-array-widget .remove_sign { - width: 10px; - height: 2px; - background: #a41515; - border-radius: 1px; -} - -.dynamic-array-widget .remove { - height: 15px; - display: flex; - align-items: center; - margin-left: 5px; -} - -.dynamic-array-widget .remove:hover { - cursor: pointer; -} - /* Selector */ .selector { display: flex; diff --git a/passbook/static/static/passbook/pf.js b/passbook/static/static/passbook/pf.js index 44e713308..00edd94fd 100644 --- a/passbook/static/static/passbook/pf.js +++ b/passbook/static/static/passbook/pf.js @@ -52,34 +52,3 @@ document.querySelectorAll("input[name=name]").forEach((input) => { slugField.value = convertToSlug(slugField.value); }); }); - -// Dynamic Array field logic -window.addEventListener('load', function () { - - function addRemoveEventListener(widgetElement) { - widgetElement.querySelectorAll('.array-remove').forEach(function (element) { - element.addEventListener('click', function () { - this.parentNode.parentNode.remove(); - }); - }); - } - - document.querySelectorAll('.dynamic-array-widget').forEach(function (widgetElement) { - - addRemoveEventListener(widgetElement); - - widgetElement.querySelector('.add-array-item').addEventListener('click', function () { - var first = widgetElement.querySelector('.array-item'); - var newElement = first.cloneNode(true); - var id_parts = newElement.querySelector('input').getAttribute('id').split('_'); - var id = id_parts.slice(0, -1).join('_') + '_' + String(parseInt(id_parts.slice(-1)[0]) + 1); - newElement.querySelector('input').setAttribute('id', id); - newElement.querySelector('input').value = ''; - - addRemoveEventListener(newElement); - first.parentElement.insertBefore(newElement, first.parentNode.lastChild); - }); - - }); - -});