Files
mayan-edms/mayan/apps/cabinets/wizard_steps.py
Roberto Rosario 0e86f2ad8a Refactor the model accesors
Refactor the accesors to behave like methods instead of properties.
This means all accesors will be prepended with the string
"get_" and will include a set of parenthesis.

Improve the ModeAttribute class to use the method's
short_description. This commit also adds support for a
new method .help_text attribute has been added.

Move accessors to their own module, named "methods.py".

Remove the PropertyHelper class as the accessors no longer
need it.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
2018-12-15 04:49:40 -04:00

57 lines
1.6 KiB
Python

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 mayan.apps.sources.wizards import WizardStep
from .forms import CabinetListForm
from .permissions import permission_cabinet_add_document
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 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 get_form_kwargs(self, wizard):
return {
'help_text': _('Cabinets to which the document will be added.'),
'permission': permission_cabinet_add_document,
'user': wizard.request.user
}
@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)