Add wizard step to insert the document being uploaded to a cabinet.
Signed-off-by: Michael Price <loneviking72@gmail.com>
This commit is contained in:
committed by
Roberto Rosario
parent
9abe4e8f96
commit
a9e8076abe
@@ -53,6 +53,7 @@ Next (2018-XX-XX)
|
|||||||
- Return to the same source view after uploading a document.
|
- Return to the same source view after uploading a document.
|
||||||
- Add new WizardStep class to decouple the wizard step configuration.
|
- Add new WizardStep class to decouple the wizard step configuration.
|
||||||
- Add support for deregister upload wizard steps.
|
- Add support for deregister upload wizard steps.
|
||||||
|
- Add wizard step to insert the document being uploaded to a cabinet.
|
||||||
|
|
||||||
2.8 (2018-02-27)
|
2.8 (2018-02-27)
|
||||||
================
|
================
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class CabinetsApp(MayanAppConfig):
|
|||||||
def ready(self):
|
def ready(self):
|
||||||
super(CabinetsApp, self).ready()
|
super(CabinetsApp, self).ready()
|
||||||
from actstream import registry
|
from actstream import registry
|
||||||
|
from .wizard_steps import WizardStepCabinets # NOQA
|
||||||
|
|
||||||
Document = apps.get_model(
|
Document = apps.get_model(
|
||||||
app_label='documents', model_name='Document'
|
app_label='documents', model_name='Document'
|
||||||
|
|||||||
53
mayan/apps/cabinets/tests/test_wizard_steps.py
Normal file
53
mayan/apps/cabinets/tests/test_wizard_steps.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from documents.models import Document
|
||||||
|
from documents.permissions import permission_document_create
|
||||||
|
from documents.tests import (
|
||||||
|
GenericDocumentViewTestCase, TEST_SMALL_DOCUMENT_PATH,
|
||||||
|
)
|
||||||
|
from sources.models import WebFormSource
|
||||||
|
from sources.tests.literals import (
|
||||||
|
TEST_SOURCE_LABEL, TEST_SOURCE_UNCOMPRESS_N
|
||||||
|
)
|
||||||
|
|
||||||
|
from ..models import Cabinet
|
||||||
|
|
||||||
|
from .literals import TEST_CABINET_LABEL
|
||||||
|
|
||||||
|
|
||||||
|
class CabinetDocumentUploadTestCase(GenericDocumentViewTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(CabinetDocumentUploadTestCase, self).setUp()
|
||||||
|
self.login_user()
|
||||||
|
self.source = WebFormSource.objects.create(
|
||||||
|
enabled=True, label=TEST_SOURCE_LABEL,
|
||||||
|
uncompress=TEST_SOURCE_UNCOMPRESS_N
|
||||||
|
)
|
||||||
|
|
||||||
|
self.document.delete()
|
||||||
|
|
||||||
|
def _request_upload_interactive_document_create_view(self):
|
||||||
|
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||||
|
return self.post(
|
||||||
|
viewname='sources:upload_interactive', args=(self.source.pk,),
|
||||||
|
data={
|
||||||
|
'document_type_id': self.document_type.pk,
|
||||||
|
'source-file': file_object,
|
||||||
|
'cabinets': self.cabinet.pk
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def _create_cabinet(self):
|
||||||
|
self.cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL)
|
||||||
|
|
||||||
|
def test_upload_interactive_view_with_access(self):
|
||||||
|
self._create_cabinet()
|
||||||
|
self.grant_access(
|
||||||
|
permission=permission_document_create, obj=self.document_type
|
||||||
|
)
|
||||||
|
response = self._request_upload_interactive_document_create_view()
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
print '1', self.cabinet
|
||||||
|
print '2', Document.objects.first().cabinets.all()
|
||||||
|
self.assertTrue(self.cabinet in Document.objects.first().cabinets.all())
|
||||||
54
mayan/apps/cabinets/wizard_steps.py
Normal file
54
mayan/apps/cabinets/wizard_steps.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from furl import furl
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
|
from django.utils.encoding import force_text
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from sources.wizards import WizardStep
|
||||||
|
|
||||||
|
from .forms import CabinetListForm
|
||||||
|
|
||||||
|
|
||||||
|
class WizardStepCabinets(WizardStep):
|
||||||
|
form_class = CabinetListForm
|
||||||
|
label = _('Select cabinets')
|
||||||
|
name = 'cabinet_selection'
|
||||||
|
number = 3
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def condition(cls, wizard):
|
||||||
|
Cabinet = apps.get_model(
|
||||||
|
app_label='cabinets', model_name='Cabinet'
|
||||||
|
)
|
||||||
|
return Cabinet.objects.exists()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_form_kwargs(self, wizard):
|
||||||
|
return {
|
||||||
|
'help_text': _('Cabinets to which the document will be added.'),
|
||||||
|
'user': wizard.request.user
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def done(cls, wizard):
|
||||||
|
result = {}
|
||||||
|
cleaned_data = wizard.get_cleaned_data_for_step(cls.name)
|
||||||
|
if cleaned_data:
|
||||||
|
result['cabinets'] = [
|
||||||
|
force_text(cabinet.pk) for cabinet in cleaned_data['cabinets']
|
||||||
|
]
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def step_post_upload_process(cls, document, querystring=None):
|
||||||
|
furl_instance = furl(querystring)
|
||||||
|
Cabinet = apps.get_model(app_label='cabinets', model_name='Cabinet')
|
||||||
|
|
||||||
|
for cabinet in Cabinet.objects.filter(pk__in=furl_instance.args.getlist('cabinets')):
|
||||||
|
cabinet.documents.add(document)
|
||||||
|
|
||||||
|
|
||||||
|
WizardStep.register(WizardStepCabinets)
|
||||||
Reference in New Issue
Block a user