diff --git a/HISTORY.rst b/HISTORY.rst index 59fa3bda6a..e5cbad2385 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -60,6 +60,8 @@ * Use FilteredSelectionForm for the class CabinetListForm. * Add keyword arguments to URL definitions. * Use FilteredSelectionForm to add a new ACLCreateForm. +* Rename IndexListForm to IndexTemplateFilteredForm. +* Use FilteredSelectionForm for IndexTemplateFilteredForm. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 78561684ea..a9b8d61e79 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -84,7 +84,8 @@ Other changes * Use FilteredSelectionForm for the class CabinetListForm. * Add keyword arguments to URL definitions. * Use FilteredSelectionForm to add a new ACLCreateForm. - +* Rename IndexListForm to IndexTemplateFilteredForm. +* Use FilteredSelectionForm for IndexTemplateFilteredForm. Removals -------- diff --git a/mayan/apps/document_indexing/forms.py b/mayan/apps/document_indexing/forms.py index 26ddd8f434..790a5e6e2e 100644 --- a/mayan/apps/document_indexing/forms.py +++ b/mayan/apps/document_indexing/forms.py @@ -4,29 +4,23 @@ from django import forms from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from mayan.apps.acls.models import AccessControlList from mayan.apps.common.classes import ModelProperty +from mayan.apps.common.forms import FilteredSelectionForm from mayan.apps.documents.models import Document from .models import Index, IndexTemplateNode from .permissions import permission_document_indexing_rebuild -class IndexListForm(forms.Form): - indexes = forms.ModelMultipleChoiceField( - help_text=_('Indexes to be queued for rebuilding.'), - label=_('Indexes'), queryset=Index.objects.none(), - required=False, widget=forms.widgets.CheckboxSelectMultiple() - ) - - def __init__(self, *args, **kwargs): - user = kwargs.pop('user') - super(IndexListForm, self).__init__(*args, **kwargs) - queryset = AccessControlList.objects.filter_by_access( - permission=permission_document_indexing_rebuild, user=user, - queryset=Index.objects.filter(enabled=True) - ) - self.fields['indexes'].queryset = queryset +class IndexTemplateFilteredForm(FilteredSelectionForm): + class Meta: + allow_multiple = True + field_name = 'index_templates' + help_text = _('Index templates to be queued for rebuilding.') + label = _('Index templates') + queryset = Index.objects.filter(enabled=True) + permission = permission_document_indexing_rebuild + widget_attributes = {'class': 'select2'} class IndexTemplateNodeForm(forms.ModelForm): diff --git a/mayan/apps/document_indexing/tests/test_views.py b/mayan/apps/document_indexing/tests/test_views.py index 4efdeb86e8..8cf15c1e9c 100644 --- a/mayan/apps/document_indexing/tests/test_views.py +++ b/mayan/apps/document_indexing/tests/test_views.py @@ -156,7 +156,7 @@ class IndexViewTestCase(GenericDocumentViewTestCase): def _request_index_rebuild_post_view(self): return self.post( viewname='indexing:rebuild_index_instances', data={ - 'indexes': self.index.pk + 'index_templates': self.index.pk } ) diff --git a/mayan/apps/document_indexing/urls.py b/mayan/apps/document_indexing/urls.py index abc206f052..5e9eb43e34 100644 --- a/mayan/apps/document_indexing/urls.py +++ b/mayan/apps/document_indexing/urls.py @@ -9,7 +9,7 @@ from .api_views import ( ) from .views import ( DocumentIndexNodeListView, IndexInstanceNodeView, IndexListView, - RebuildIndexesView, SetupIndexDocumentTypesView, SetupIndexCreateView, + IndexesRebuildView, SetupIndexDocumentTypesView, SetupIndexCreateView, SetupIndexDeleteView, SetupIndexEditView, SetupIndexListView, SetupIndexTreeTemplateListView, TemplateNodeCreateView, TemplateNodeDeleteView, TemplateNodeEditView @@ -63,7 +63,7 @@ urlpatterns = [ ), url( - regex=r'^rebuild/all/$', view=RebuildIndexesView.as_view(), + regex=r'^indexes/rebuild/$', view=IndexesRebuildView.as_view(), name='rebuild_index_instances' ), url( diff --git a/mayan/apps/document_indexing/views.py b/mayan/apps/document_indexing/views.py index 6a015ce7bf..920735e5c4 100644 --- a/mayan/apps/document_indexing/views.py +++ b/mayan/apps/document_indexing/views.py @@ -16,7 +16,7 @@ from mayan.apps.documents.models import Document, DocumentType from mayan.apps.documents.permissions import permission_document_view from mayan.apps.documents.views import DocumentListView -from .forms import IndexListForm, IndexTemplateNodeForm +from .forms import IndexTemplateFilteredForm, IndexTemplateNodeForm from .icons import icon_index from .links import link_index_setup_create from .models import ( @@ -365,15 +365,15 @@ class DocumentIndexNodeListView(SingleObjectListView): ) -class RebuildIndexesView(FormView): +class IndexesRebuildView(FormView): extra_context = { 'title': _('Rebuild indexes'), } - form_class = IndexListForm + form_class = IndexTemplateFilteredForm def form_valid(self, form): count = 0 - for index in form.cleaned_data['indexes']: + for index in form.cleaned_data['index_templates']: task_rebuild_index.apply_async( kwargs=dict(index_id=index.pk) ) @@ -389,7 +389,7 @@ class RebuildIndexesView(FormView): } ) - return super(RebuildIndexesView, self).form_valid(form=form) + return super(IndexesRebuildView, self).form_valid(form=form) def get_form_extra_kwargs(self): return {