Use FilteredSelectionForm for IndexListForm
Rename IndexListForm to IndexTemplateFilteredForm. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -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)
|
||||
===================
|
||||
|
||||
@@ -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
|
||||
--------
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user