diff --git a/djangocms_attributes_field/widgets.py b/djangocms_attributes_field/widgets.py index e9f890d..2dad209 100644 --- a/djangocms_attributes_field/widgets.py +++ b/djangocms_attributes_field/widgets.py @@ -1,7 +1,7 @@ from django.forms import Widget from django.forms.utils import flatatt from django.utils.html import escape, mark_safe, strip_spaces_between_tags -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ class AttributesWidget(Widget): @@ -13,10 +13,11 @@ class AttributesWidget(Widget): # https://www.huyng.com/posts/django-custom-form-widget-for-dictionary-and-tuple-key-value-pairs def __init__(self, *args, **kwargs): """ - Supports additional kwargs: `key_attr` and `val_attr`. + Supports additional kwargs: `key_attr`, `val_attr`, `sorted`. """ self.key_attrs = kwargs.pop('key_attrs', {}) self.val_attrs = kwargs.pop('val_attrs', {}) + self.sorted = sorted if kwargs.pop('sorted', True) else lambda x: x super().__init__(*args, **kwargs) def _render_row(self, key, value, field_name, key_attrs, val_attrs): @@ -69,7 +70,7 @@ def render(self, name, value, attrs=None, renderer=None): output = '