Skip step 1 of create document wizard if only one document type exists
This commit is contained in:
@@ -6,6 +6,7 @@ from django.http import HttpResponseRedirect
|
||||
from django.utils.http import urlencode
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.forms.formsets import formset_factory
|
||||
|
||||
from staging import StagingFile
|
||||
|
||||
@@ -18,6 +19,8 @@ from models import Document, DocumentType, DocumentTypeMetadataType
|
||||
from documents.conf.settings import AVAILABLE_FUNCTIONS
|
||||
from documents.conf.settings import AVAILABLE_MODELS
|
||||
|
||||
|
||||
|
||||
class ImageWidget(forms.widgets.Widget):
|
||||
def render(self, name, value, attrs=None):
|
||||
output = []
|
||||
@@ -139,39 +142,48 @@ class MetadataForm(forms.Form):
|
||||
|
||||
|
||||
class DocumentCreateWizard(BoundFormWizard):
|
||||
def _generate_metadata_initial_values(self):
|
||||
initial=[]
|
||||
for item in DocumentTypeMetadataType.objects.filter(document_type=self.document_type):
|
||||
initial.append({
|
||||
'metadata_type':item.metadata_type,
|
||||
'document_type':self.document_type,
|
||||
})
|
||||
return initial
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.multiple = kwargs.pop('multiple', True)
|
||||
self.step_titles = kwargs.pop('step_titles', [
|
||||
_(u'step 1 of 2: Document type'),
|
||||
_(u'step 2 of 2: Document metadata'),
|
||||
])
|
||||
self.document_type = kwargs.pop('document_type', None)
|
||||
|
||||
super(DocumentCreateWizard, self).__init__(*args, **kwargs)
|
||||
|
||||
if self.document_type:
|
||||
self.initial = {0:self._generate_metadata_initial_values()}
|
||||
|
||||
|
||||
def render_template(self, request, form, previous_fields, step, context=None):
|
||||
context = {'step_title':self.extra_context['step_titles'][step]}
|
||||
return super(DocumentCreateWizard, self).render_template(request, form, previous_fields, step, context)
|
||||
|
||||
def parse_params(self, request, *args, **kwargs):
|
||||
self.extra_context={'step_titles':[
|
||||
_(u'step 1 of 2: Document type'),
|
||||
_(u'step 2 of 2: Document metadata'),
|
||||
]}
|
||||
self.extra_context={'step_titles':self.step_titles}
|
||||
|
||||
def process_step(self, request, form, step):
|
||||
if step == 0:
|
||||
#if step == 0:
|
||||
if isinstance(form, DocumentTypeSelectForm):
|
||||
self.document_type = form.cleaned_data['document_type']
|
||||
self.initial = {1:self._generate_metadata_initial_values()}
|
||||
|
||||
initial=[]
|
||||
for item in DocumentTypeMetadataType.objects.filter(document_type=self.document_type):
|
||||
initial.append({
|
||||
'metadata_type':item.metadata_type,
|
||||
'document_type':self.document_type,
|
||||
})
|
||||
self.initial = {1:initial}
|
||||
if step == 1:
|
||||
#if step == 1:
|
||||
if isinstance(form, MetadataFormSet):
|
||||
self.urldata = []
|
||||
for id, metadata in enumerate(form.cleaned_data):
|
||||
if metadata['value']:
|
||||
self.urldata.append(('metadata%s_id' % id,metadata['id']))
|
||||
self.urldata.append(('metadata%s_value' % id,metadata['value']))
|
||||
|
||||
|
||||
def get_template(self, step):
|
||||
return 'generic_wizard.html'
|
||||
@@ -184,3 +196,6 @@ class DocumentCreateWizard(BoundFormWizard):
|
||||
|
||||
url = reverse(view, args=[self.document_type.id])
|
||||
return HttpResponseRedirect('%s?%s' % (url, urlencode(self.urldata)))
|
||||
|
||||
|
||||
MetadataFormSet = formset_factory(MetadataForm, extra=0)
|
||||
|
||||
@@ -8,7 +8,7 @@ from django.contrib import messages
|
||||
from django.views.generic.list_detail import object_detail, object_list
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.views.generic.create_update import create_object, delete_object, update_object
|
||||
from django.forms.formsets import formset_factory
|
||||
#from django.forms.formsets import formset_factory
|
||||
from django.core.files.base import File
|
||||
from django.conf import settings
|
||||
from django.utils.http import urlencode
|
||||
@@ -23,7 +23,8 @@ from utils import from_descriptor_to_tempfile
|
||||
from models import Document, DocumentMetadata, DocumentType, MetadataType
|
||||
from forms import DocumentTypeSelectForm, DocumentCreateWizard, \
|
||||
MetadataForm, DocumentForm, DocumentForm_edit, DocumentForm_view, \
|
||||
StagingDocumentForm, DocumentTypeMetadataType, DocumentPreviewForm
|
||||
StagingDocumentForm, DocumentTypeMetadataType, DocumentPreviewForm, \
|
||||
MetadataFormSet
|
||||
|
||||
from staging import StagingFile
|
||||
|
||||
@@ -45,8 +46,16 @@ def document_list(request):
|
||||
)
|
||||
|
||||
def document_create(request, multiple=True):
|
||||
MetadataFormSet = formset_factory(MetadataForm, extra=0)
|
||||
wizard = DocumentCreateWizard(form_list=[DocumentTypeSelectForm, MetadataFormSet], multiple=multiple)
|
||||
if DocumentType.objects.all().count() == 1:
|
||||
wizard = DocumentCreateWizard(
|
||||
document_type=DocumentType.objects.all()[0],
|
||||
form_list=[MetadataFormSet], multiple=multiple,
|
||||
step_titles = [
|
||||
_(u'document metadata'),
|
||||
])
|
||||
else:
|
||||
wizard = DocumentCreateWizard(form_list=[DocumentTypeSelectForm, MetadataFormSet], multiple=multiple)
|
||||
|
||||
return wizard(request)
|
||||
|
||||
def document_create_sibling(request, document_id, multiple=True):
|
||||
@@ -329,7 +338,6 @@ def document_edit(request, document_id):
|
||||
|
||||
def document_edit_metadata(request, document_id):
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
MetadataFormSet = formset_factory(MetadataForm, extra=0)
|
||||
|
||||
initial=[]
|
||||
for item in DocumentTypeMetadataType.objects.filter(document_type=document.document_type):
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
* Added python-magic for smarter MIME type detection (https://github.com/ahupp/python-magic)
|
||||
* Added a new Document model field: file_mime_encoding
|
||||
* Show only document metadata in document list view
|
||||
* Added python-magic for smarter MIME type detection (https://github.com/ahupp/python-magic).
|
||||
* Added a new Document model field: file_mime_encoding.
|
||||
* Show only document metadata in document list view.
|
||||
* If one document type exists, the create document wizard skips the first step.
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
* Cache thumbnails and preview by document hash not by uuid - DONE
|
||||
* Show document metadata in document list - DONE
|
||||
* Add css grids - DONE
|
||||
* If theres only one document type on db skip step 1 of wizard - DONE
|
||||
* Document list filtering by metadata
|
||||
* Filterform date filtering widget
|
||||
* Validate GET data before saving file
|
||||
* Check duplicated files using checksum
|
||||
* If theres only one document type on db skip step 1 of wizard
|
||||
* Show last 5 recent metadata setups for easy switch
|
||||
* Change to model signals
|
||||
* Allow document type to be changed in document edit view
|
||||
@@ -53,5 +53,8 @@
|
||||
* Divide navigation links search by object and by view
|
||||
* Add show_summary method to model to display as results of a search
|
||||
* Add unpaper to pre OCR document cleanup
|
||||
* Support distributed OCR queues (RabbitMQ & Celery?)
|
||||
* DXF viewer - http://code.google.com/p/dxf-reader/source/browse/#svn%2Ftrunk
|
||||
* Group documents by metadata
|
||||
* Support spreadsheets, wordprocessing docs using openoffice in server mode
|
||||
* WebDAV support
|
||||
|
||||
Reference in New Issue
Block a user