Use FilteredSelectionForm for IndexListForm

Rename IndexListForm to IndexTemplateFilteredForm.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-15 01:49:57 -04:00
parent 0d69274bb4
commit cdb55ab5dd
6 changed files with 22 additions and 25 deletions

View File

@@ -60,6 +60,8 @@
* Use FilteredSelectionForm for the class CabinetListForm. * Use FilteredSelectionForm for the class CabinetListForm.
* Add keyword arguments to URL definitions. * Add keyword arguments to URL definitions.
* Use FilteredSelectionForm to add a new ACLCreateForm. * Use FilteredSelectionForm to add a new ACLCreateForm.
* Rename IndexListForm to IndexTemplateFilteredForm.
* Use FilteredSelectionForm for IndexTemplateFilteredForm.
3.1.11 (2019-04-XX) 3.1.11 (2019-04-XX)
=================== ===================

View File

@@ -84,7 +84,8 @@ Other changes
* Use FilteredSelectionForm for the class CabinetListForm. * Use FilteredSelectionForm for the class CabinetListForm.
* Add keyword arguments to URL definitions. * Add keyword arguments to URL definitions.
* Use FilteredSelectionForm to add a new ACLCreateForm. * Use FilteredSelectionForm to add a new ACLCreateForm.
* Rename IndexListForm to IndexTemplateFilteredForm.
* Use FilteredSelectionForm for IndexTemplateFilteredForm.
Removals Removals
-------- --------

View File

@@ -4,29 +4,23 @@ from django import forms
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _ 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.classes import ModelProperty
from mayan.apps.common.forms import FilteredSelectionForm
from mayan.apps.documents.models import Document from mayan.apps.documents.models import Document
from .models import Index, IndexTemplateNode from .models import Index, IndexTemplateNode
from .permissions import permission_document_indexing_rebuild from .permissions import permission_document_indexing_rebuild
class IndexListForm(forms.Form): class IndexTemplateFilteredForm(FilteredSelectionForm):
indexes = forms.ModelMultipleChoiceField( class Meta:
help_text=_('Indexes to be queued for rebuilding.'), allow_multiple = True
label=_('Indexes'), queryset=Index.objects.none(), field_name = 'index_templates'
required=False, widget=forms.widgets.CheckboxSelectMultiple() help_text = _('Index templates to be queued for rebuilding.')
) label = _('Index templates')
queryset = Index.objects.filter(enabled=True)
def __init__(self, *args, **kwargs): permission = permission_document_indexing_rebuild
user = kwargs.pop('user') widget_attributes = {'class': 'select2'}
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 IndexTemplateNodeForm(forms.ModelForm): class IndexTemplateNodeForm(forms.ModelForm):

View File

@@ -156,7 +156,7 @@ class IndexViewTestCase(GenericDocumentViewTestCase):
def _request_index_rebuild_post_view(self): def _request_index_rebuild_post_view(self):
return self.post( return self.post(
viewname='indexing:rebuild_index_instances', data={ viewname='indexing:rebuild_index_instances', data={
'indexes': self.index.pk 'index_templates': self.index.pk
} }
) )

View File

@@ -9,7 +9,7 @@ from .api_views import (
) )
from .views import ( from .views import (
DocumentIndexNodeListView, IndexInstanceNodeView, IndexListView, DocumentIndexNodeListView, IndexInstanceNodeView, IndexListView,
RebuildIndexesView, SetupIndexDocumentTypesView, SetupIndexCreateView, IndexesRebuildView, SetupIndexDocumentTypesView, SetupIndexCreateView,
SetupIndexDeleteView, SetupIndexEditView, SetupIndexListView, SetupIndexDeleteView, SetupIndexEditView, SetupIndexListView,
SetupIndexTreeTemplateListView, TemplateNodeCreateView, SetupIndexTreeTemplateListView, TemplateNodeCreateView,
TemplateNodeDeleteView, TemplateNodeEditView TemplateNodeDeleteView, TemplateNodeEditView
@@ -63,7 +63,7 @@ urlpatterns = [
), ),
url( url(
regex=r'^rebuild/all/$', view=RebuildIndexesView.as_view(), regex=r'^indexes/rebuild/$', view=IndexesRebuildView.as_view(),
name='rebuild_index_instances' name='rebuild_index_instances'
), ),
url( url(

View File

@@ -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.permissions import permission_document_view
from mayan.apps.documents.views import DocumentListView from mayan.apps.documents.views import DocumentListView
from .forms import IndexListForm, IndexTemplateNodeForm from .forms import IndexTemplateFilteredForm, IndexTemplateNodeForm
from .icons import icon_index from .icons import icon_index
from .links import link_index_setup_create from .links import link_index_setup_create
from .models import ( from .models import (
@@ -365,15 +365,15 @@ class DocumentIndexNodeListView(SingleObjectListView):
) )
class RebuildIndexesView(FormView): class IndexesRebuildView(FormView):
extra_context = { extra_context = {
'title': _('Rebuild indexes'), 'title': _('Rebuild indexes'),
} }
form_class = IndexListForm form_class = IndexTemplateFilteredForm
def form_valid(self, form): def form_valid(self, form):
count = 0 count = 0
for index in form.cleaned_data['indexes']: for index in form.cleaned_data['index_templates']:
task_rebuild_index.apply_async( task_rebuild_index.apply_async(
kwargs=dict(index_id=index.pk) 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): def get_form_extra_kwargs(self):
return { return {