Move post document upload processing of metadata and tags from sources.model to each wizard step.
Signed-off-by: Michael Price <loneviking72@gmail.com>
This commit is contained in:
committed by
Roberto Rosario
parent
460d747424
commit
05966afe1e
68
mayan/apps/metadata/wizard_steps.py
Normal file
68
mayan/apps/metadata/wizard_steps.py
Normal file
@@ -0,0 +1,68 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from metadata.api import decode_metadata_from_url, save_metadata_list
|
||||
from metadata.forms import DocumentMetadataFormSet
|
||||
|
||||
from sources.wizards import WizardStep, WizardStepDocumentType
|
||||
|
||||
|
||||
class WizardStepMetadata(WizardStep):
|
||||
form_class = DocumentMetadataFormSet
|
||||
label = _('Enter document metadata')
|
||||
name = 'metadata_entry'
|
||||
number = 1
|
||||
|
||||
@classmethod
|
||||
def condition(cls, wizard):
|
||||
"""
|
||||
Skip step if document type has no associated metadata
|
||||
"""
|
||||
cleaned_data = wizard.get_cleaned_data_for_step(WizardStepDocumentType.name) or {}
|
||||
|
||||
document_type = cleaned_data.get('document_type')
|
||||
|
||||
if document_type:
|
||||
return document_type.metadata.exists()
|
||||
|
||||
@classmethod
|
||||
def get_form_initial(cls, wizard):
|
||||
initial = []
|
||||
|
||||
step_data = wizard.get_cleaned_data_for_step(WizardStepDocumentType.name)
|
||||
if step_data:
|
||||
document_type = step_data['document_type']
|
||||
for document_type_metadata_type in document_type.metadata.all():
|
||||
initial.append(
|
||||
{
|
||||
'document_type': document_type,
|
||||
'metadata_type': document_type_metadata_type.metadata_type,
|
||||
}
|
||||
)
|
||||
|
||||
return initial
|
||||
|
||||
@classmethod
|
||||
def done(cls, wizard):
|
||||
result = {}
|
||||
cleaned_data = wizard.get_cleaned_data_for_step(cls.name)
|
||||
if cleaned_data:
|
||||
for identifier, metadata in enumerate(wizard.get_cleaned_data_for_step(cls.name)):
|
||||
if metadata.get('update'):
|
||||
result['metadata%s_id' % identifier] = metadata['id']
|
||||
result['metadata%s_value' % identifier] = metadata['value']
|
||||
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def step_post_upload_process(cls, document, request_data=None):
|
||||
metadata_dict_list = decode_metadata_from_url(url_dict=request_data)
|
||||
if metadata_dict_list:
|
||||
save_metadata_list(
|
||||
metadata_list=metadata_dict_list, document=document,
|
||||
create=True
|
||||
)
|
||||
|
||||
|
||||
WizardStep.register(WizardStepMetadata)
|
||||
Reference in New Issue
Block a user