Use FilteredSelectionForm for the class CabinetListForm
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -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)
|
||||
===================
|
||||
|
||||
@@ -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
|
||||
--------
|
||||
|
||||
@@ -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'}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user