From 5ef73d992ce5e207e75db05a76391876222e9542 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 14 Apr 2019 20:36:28 -0400 Subject: [PATCH] Use FilteredSelectionForm for the class CabinetListForm Signed-off-by: Roberto Rosario --- HISTORY.rst | 1 + docs/releases/3.2.rst | 1 + mayan/apps/cabinets/forms.py | 31 ++++++++--------------------- mayan/apps/cabinets/views.py | 2 ++ mayan/apps/cabinets/wizard_steps.py | 2 ++ 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index feb8efa0d5..5e60753cee 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -57,6 +57,7 @@ * DetailForm now support help text on extra fields. * Add FilteredSelectionForm class. * Use FilteredSelectionForm for TagMultipleSelectionForm. +* Use FilteredSelectionForm for the class CabinetListForm. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 8c4a8365c6..0375214c00 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -81,6 +81,7 @@ Other changes * DetailForm now support help text on extra fields. * Add FilteredSelectionForm class. * Use FilteredSelectionForm for TagMultipleSelectionForm. +* Use FilteredSelectionForm for the class CabinetListForm. Removals -------- diff --git a/mayan/apps/cabinets/forms.py b/mayan/apps/cabinets/forms.py index 5876fefcc6..f494371fdd 100644 --- a/mayan/apps/cabinets/forms.py +++ b/mayan/apps/cabinets/forms.py @@ -2,32 +2,17 @@ from __future__ import absolute_import, unicode_literals import logging -from django import forms from django.utils.translation import ugettext_lazy as _ -from mayan.apps.acls.models import AccessControlList - -from .models import Cabinet +from mayan.apps.common.forms import FilteredSelectionForm logger = logging.getLogger(__name__) -class CabinetListForm(forms.Form): - def __init__(self, *args, **kwargs): - help_text = kwargs.pop('help_text', None) - permission = kwargs.pop('permission', None) - queryset = kwargs.pop('queryset', Cabinet.objects.all()) - user = kwargs.pop('user', None) - - logger.debug('user: %s', user) - super(CabinetListForm, self).__init__(*args, **kwargs) - - queryset = AccessControlList.objects.filter_by_access( - permission=permission, user=user, queryset=queryset - ) - - self.fields['cabinets'] = forms.ModelMultipleChoiceField( - label=_('Cabinets'), help_text=help_text, - queryset=queryset, required=False, - widget=forms.SelectMultiple(attrs={'class': 'select2'}) - ) +class CabinetListForm(FilteredSelectionForm): + class Meta: + allow_multiple = True + field_name = 'cabinets' + label = _('Cabinets') + required = False + widget_attributes = {'class': 'select2'} diff --git a/mayan/apps/cabinets/views.py b/mayan/apps/cabinets/views.py index 8e142a7aa5..07b844bad2 100644 --- a/mayan/apps/cabinets/views.py +++ b/mayan/apps/cabinets/views.py @@ -266,6 +266,7 @@ class DocumentAddToCabinetView(MultipleObjectFormActionView): 'Cabinets to which the selected documents will be added.' ), 'permission': permission_cabinet_add_document, + 'queryset': Cabinet.objects.all(), 'user': self.request.user } @@ -355,6 +356,7 @@ class DocumentRemoveFromCabinetView(MultipleObjectFormActionView): 'Cabinets from which the selected documents will be removed.' ), 'permission': permission_cabinet_remove_document, + 'queryset': Cabinet.objects.all(), 'user': self.request.user } diff --git a/mayan/apps/cabinets/wizard_steps.py b/mayan/apps/cabinets/wizard_steps.py index 7c37006e70..230ad96564 100644 --- a/mayan/apps/cabinets/wizard_steps.py +++ b/mayan/apps/cabinets/wizard_steps.py @@ -9,6 +9,7 @@ from django.utils.translation import ugettext_lazy as _ from mayan.apps.sources.wizards import WizardStep from .forms import CabinetListForm +from .models import Cabinet from .permissions import permission_cabinet_add_document @@ -30,6 +31,7 @@ class WizardStepCabinets(WizardStep): return { 'help_text': _('Cabinets to which the document will be added.'), 'permission': permission_cabinet_add_document, + 'queryset': Cabinet.objects.all(), 'user': wizard.request.user }