From 27171597ded9a322713249a34cef40fdd6999324 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 31 Dec 2016 02:22:11 -0400 Subject: [PATCH] Use the select2 widget for the user language and locale. Remove the ModelForm class. --- mayan/apps/common/forms.py | 48 ++++++++++-------------------------- mayan/apps/common/widgets.py | 7 ------ 2 files changed, 13 insertions(+), 42 deletions(-) diff --git a/mayan/apps/common/forms.py b/mayan/apps/common/forms.py index 4b93db6a94..6d63b85a72 100644 --- a/mayan/apps/common/forms.py +++ b/mayan/apps/common/forms.py @@ -115,44 +115,22 @@ class LicenseForm(FileDisplayForm): FILENAME = 'LICENSE' -class ModelForm(forms.ModelForm): - """ - ModelForm subclass that supports field choices sorting - - class Meta: - # Dictionary of field names and the key used to sort the field - sorted_fields = None - - # Example: - # sorted_fields = {'language': operator.itemgetter(1))} - """ - - def __init__(self, *args, **kwargs): - super(ModelForm, self).__init__(*args, **kwargs) - - for field, key in getattr(self.Meta, 'sorted_fields', {}).items(): - # Would be the cleaner "opts.sorted_fields" if these were addressed - # https://code.djangoproject.com/ticket/5793 - # of a get_options_class for Forms/ModelForms - # https://code.djangoproject.com/ticket/18540 - choices = self.fields[field].choices - - if not self.fields[field].required: - # Remove empty choice before sorting - empty_choice = choices.pop(0) - - self.fields[field].choices = sorted(choices, key=key) - - if not self.fields[field].required: - # Add empty choice after sorting - self.fields[field].choices.insert(0, empty_choice) - - -class LocaleProfileForm(ModelForm): +class LocaleProfileForm(forms.ModelForm): class Meta: fields = ('language', 'timezone') model = UserLocaleProfile - sorted_fields = {'language': itemgetter(1)} + widgets = { + 'language': forms.Select( + attrs={ + 'class': 'select2' + } + ), + 'timezone': forms.Select( + attrs={ + 'class': 'select2' + } + ) + } class LocaleProfileForm_view(DetailForm): diff --git a/mayan/apps/common/widgets.py b/mayan/apps/common/widgets.py index 2dfd6551ee..cd277402ad 100644 --- a/mayan/apps/common/widgets.py +++ b/mayan/apps/common/widgets.py @@ -129,13 +129,6 @@ class TextAreaDiv(forms.widgets.Widget): return mark_safe(result) -def exists_widget(path): - try: - return two_state_template(os.path.exists(path)) - except Exception as exception: - return exception - - def two_state_template(state, ok_icon='fa fa-check', fail_icon='fa fa-times'): if state: return mark_safe(''.format(ok_icon))