Added view to create source transformations, merged and normalized most source and source transformations views
This commit is contained in:
@@ -30,7 +30,7 @@ from sources.models import SOURCE_UNCOMPRESS_CHOICE_Y, \
|
||||
from sources.staging import create_staging_file_class, StagingFile
|
||||
from sources.forms import StagingDocumentForm, WebFormForm
|
||||
from sources.forms import WebFormSetupForm, StagingFolderSetupForm
|
||||
from sources.forms import SourceTransformationForm
|
||||
from sources.forms import SourceTransformationForm, SourceTransformationForm_create
|
||||
|
||||
|
||||
def return_function(obj):
|
||||
@@ -339,16 +339,15 @@ def setup_source_list(request, source_type):
|
||||
|
||||
if source_type == SOURCE_CHOICE_WEB_FORM:
|
||||
cls = WebForm
|
||||
title = _(u'web form sources')
|
||||
elif source_type == SOURCE_CHOICE_STAGING:
|
||||
cls = StagingFolder
|
||||
title = _(u'staging folder sources')
|
||||
|
||||
context = {
|
||||
'object_list': cls.objects.all(),
|
||||
'title': title,
|
||||
'title': cls.class_fullname_plural(),
|
||||
'hide_link': True,
|
||||
'list_object_variable_name': 'source'
|
||||
'list_object_variable_name': 'source',
|
||||
'source_type': source_type,
|
||||
}
|
||||
|
||||
return render_to_response('generic_list.html', context,
|
||||
@@ -361,11 +360,9 @@ def setup_source_edit(request, source_type, source_id):
|
||||
if source_type == SOURCE_CHOICE_WEB_FORM:
|
||||
cls = WebForm
|
||||
form_class = WebFormSetupForm
|
||||
title = _(u'edit web form source: %s')
|
||||
elif source_type == SOURCE_CHOICE_STAGING:
|
||||
cls = StagingFolder
|
||||
form_class = StagingFolderSetupForm
|
||||
title = _(u'edit staging folder source: %s')
|
||||
|
||||
source = get_object_or_404(cls, pk=source_id)
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', '/')))
|
||||
@@ -383,12 +380,13 @@ def setup_source_edit(request, source_type, source_id):
|
||||
form = form_class(instance=source)
|
||||
|
||||
return render_to_response('generic_form.html', {
|
||||
'title': title % source,
|
||||
'title': _(u'edit source: %s') % source.fullname(),
|
||||
'form': form,
|
||||
'source': source,
|
||||
'navigation_object_name': 'source',
|
||||
'next': next,
|
||||
'object_name': _(u'source'),
|
||||
'source_type': source_type,
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@@ -397,15 +395,16 @@ def setup_source_delete(request, source_type, source_id):
|
||||
#check_permissions(request.user, [PERMISSION_SOURCES_SETUP_DELETE])
|
||||
if source_type == SOURCE_CHOICE_WEB_FORM:
|
||||
cls = WebForm
|
||||
title = _(u'Are you sure you wish to delete the web form source: %s?')
|
||||
form_icon = u'application_form_delete.png'
|
||||
redirect_view = 'setup_web_form_list'
|
||||
elif source_type == SOURCE_CHOICE_STAGING:
|
||||
cls = StagingFolder
|
||||
title = _(u'Are you sure you wish to delete the staging folder source: %s?')
|
||||
form_icon = u'folder_delete.png'
|
||||
redirect_view = 'setup_staging_folder_list'
|
||||
|
||||
redirect_view = reverse('setup_source_list', args=[source_type])
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', redirect_view)))
|
||||
|
||||
source = get_object_or_404(cls, pk=source_id)
|
||||
|
||||
if request.method == 'POST':
|
||||
@@ -417,16 +416,17 @@ def setup_source_delete(request, source_type, source_id):
|
||||
'source': source, 'error': e
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(reverse(redirect_view))
|
||||
return HttpResponseRedirect(redirect_view)
|
||||
|
||||
context = {
|
||||
'title': title % source,
|
||||
'title': _(u'Are you sure you wish to delete the source: %s?') % source.fullname(),
|
||||
'source': source,
|
||||
'object_name': _(u'source'),
|
||||
'navigation_object_name': 'source',
|
||||
'delete_view': True,
|
||||
'previous': reverse(redirect_view),
|
||||
'previous': previous,
|
||||
'form_icon': form_icon,
|
||||
'source_type': source_type,
|
||||
}
|
||||
|
||||
return render_to_response('generic_confirm.html', context,
|
||||
@@ -437,16 +437,12 @@ def setup_source_create(request, source_type):
|
||||
#check_permissions(request.user, [PERMISSION_SOURCES_SETUP_EDIT])
|
||||
|
||||
if source_type == SOURCE_CHOICE_WEB_FORM:
|
||||
#cls = WebForm
|
||||
cls = WebForm
|
||||
form_class = WebFormSetupForm
|
||||
title = _(u'Creating web form source')
|
||||
elif source_type == SOURCE_CHOICE_STAGING:
|
||||
#cls = StagingFolder
|
||||
cls = StagingFolder
|
||||
form_class = StagingFolderSetupForm
|
||||
title = _(u'Creating staging folder source')
|
||||
|
||||
#source = get_object_or_404(cls, pk=source_id)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = form_class(data=request.POST)
|
||||
if form.is_valid():
|
||||
@@ -460,9 +456,11 @@ def setup_source_create(request, source_type):
|
||||
form = form_class()
|
||||
|
||||
return render_to_response('generic_form.html', {
|
||||
'title': title,
|
||||
'title': _(u'Create new source of type: %s') % cls.class_fullname(),
|
||||
'form': form,
|
||||
#'object_name': _(u'source'),
|
||||
'source_type': source_type,
|
||||
'source': cls,
|
||||
'navigation_object_name': 'source',
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@@ -472,16 +470,14 @@ def setup_source_transformation_list(request, source_type, source_id):
|
||||
|
||||
if source_type == SOURCE_CHOICE_WEB_FORM:
|
||||
cls = WebForm
|
||||
#title = _(u'web form sources')
|
||||
elif source_type == SOURCE_CHOICE_STAGING:
|
||||
cls = StagingFolder
|
||||
#title = _(u'staging folder sources')
|
||||
|
||||
source = get_object_or_404(cls, pk=source_id)
|
||||
|
||||
context = {
|
||||
'object_list': SourceTransformation.objects.get_for_object(source),
|
||||
'title': _(u'transformations for: %s') % source,
|
||||
'title': _(u'transformations for: %s') % source.fullname(),
|
||||
'source': source,
|
||||
'object_name': _(u'source'),
|
||||
'navigation_object_name': 'source',
|
||||
@@ -503,7 +499,8 @@ def setup_source_transformation_edit(request, transformation_id):
|
||||
#check_permissions(request.user, [PERMISSION_SOURCES_SETUP_EDIT])
|
||||
|
||||
source_transformation = get_object_or_404(SourceTransformation, pk=transformation_id)
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', '/')))
|
||||
redirect_view = reverse('setup_source_transformation_list', args=[source_transformation.content_object.source_type, source_transformation.content_object.pk])
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', redirect_view)))
|
||||
|
||||
if request.method == 'POST':
|
||||
form = SourceTransformationForm(instance=source_transformation, data=request.POST)
|
||||
@@ -522,12 +519,10 @@ def setup_source_transformation_edit(request, transformation_id):
|
||||
'form': form,
|
||||
'source': source_transformation.content_object,
|
||||
'transformation': source_transformation,
|
||||
#'navigation_object_name_list': ['source', 'transformation'],
|
||||
'navigation_object_list': [
|
||||
{'object': 'source', 'name': _(u'source')},
|
||||
{'object': 'transformation', 'name': _(u'transformation')}
|
||||
],
|
||||
#'object_name_list': [_(u'source'), _(u'transformation')],
|
||||
'next': next,
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
@@ -537,7 +532,8 @@ def setup_source_transformation_delete(request, transformation_id):
|
||||
#check_permissions(request.user, [PERMISSION_DOCUMENT_TRANSFORM])
|
||||
|
||||
source_transformation = get_object_or_404(SourceTransformation, pk=transformation_id)
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', '/')))
|
||||
redirect_view = reverse('setup_source_transformation_list', args=[source_transformation.content_object.source_type, source_transformation.content_object.pk])
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', redirect_view)))
|
||||
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
@@ -547,12 +543,11 @@ def setup_source_transformation_delete(request, transformation_id):
|
||||
messages.error(request, _(u'Error deleting transformation; %(error)s') % {
|
||||
'error': e}
|
||||
)
|
||||
return HttpResponseRedirect(next)
|
||||
return HttpResponseRedirect(redirect_view)
|
||||
|
||||
return render_to_response('generic_confirm.html', {
|
||||
'delete_view': True,
|
||||
'transformation': source_transformation,
|
||||
#'object_name': _(u'document transformation'),
|
||||
'source': source_transformation.content_object,
|
||||
'navigation_object_list': [
|
||||
{'object': 'source', 'name': _(u'source')},
|
||||
@@ -560,38 +555,60 @@ def setup_source_transformation_delete(request, transformation_id):
|
||||
],
|
||||
'title': _(u'Are you sure you wish to delete transformation "%(transformation)s"') % {
|
||||
'transformation': source_transformation.get_transformation_display(),
|
||||
#'document_page': document_page_transformation.document_page
|
||||
},
|
||||
'next': next,
|
||||
'previous': next,
|
||||
'previous': previous,
|
||||
'form_icon': u'shape_square_delete.png',
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
'''
|
||||
def document_page_transformation_create(request, document_page_id):
|
||||
check_permissions(request.user, [PERMISSION_DOCUMENT_TRANSFORM])
|
||||
|
||||
document_page = get_object_or_404(DocumentPage, pk=document_page_id)
|
||||
def setup_source_transformation_create(request, source_type, source_id):
|
||||
#check_permissions(request.user, [PERMISSION_DOCUMENT_TRANSFORM])
|
||||
|
||||
if source_type == SOURCE_CHOICE_WEB_FORM:
|
||||
cls = WebForm
|
||||
elif source_type == SOURCE_CHOICE_STAGING:
|
||||
cls = StagingFolder
|
||||
|
||||
source = get_object_or_404(cls, pk=source_id)
|
||||
|
||||
context = {
|
||||
'object_list': SourceTransformation.objects.get_for_object(source),
|
||||
'title': _(u'transformations for: %s') % source.fullname(),
|
||||
'source': source,
|
||||
'object_name': _(u'source'),
|
||||
'navigation_object_name': 'source',
|
||||
'list_object_variable_name': 'transformation',
|
||||
'extra_columns': [
|
||||
{'name': _(u'order'), 'attribute': 'order'},
|
||||
{'name': _(u'transformation'), 'attribute': lambda x: x.get_transformation_display()},
|
||||
{'name': _(u'arguments'), 'attribute': 'arguments'}
|
||||
],
|
||||
'hide_link': True,
|
||||
'hide_object': True,
|
||||
}
|
||||
|
||||
redirect_view = reverse('setup_source_transformation_list', args=[source.source_type, source.pk])
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', redirect_view)))
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DocumentPageTransformationForm(request.POST, initial={'document_page': document_page})
|
||||
form = SourceTransformationForm_create(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return HttpResponseRedirect(reverse('document_page_view', args=[document_page_id]))
|
||||
try:
|
||||
source_tranformation = form.save(commit=False)
|
||||
source_tranformation.content_object = source
|
||||
source_tranformation.save()
|
||||
messages.success(request, _(u'Source transformation created successfully'))
|
||||
return HttpResponseRedirect(redirect_view)
|
||||
except Exception, e:
|
||||
messages.error(request, _(u'Error creating source transformation; %s') % e)
|
||||
else:
|
||||
form = DocumentPageTransformationForm(initial={'document_page': document_page})
|
||||
|
||||
form = SourceTransformationForm_create()
|
||||
|
||||
return render_to_response('generic_form.html', {
|
||||
'form': form,
|
||||
'object': document_page,
|
||||
'title': _(u'Create new transformation for page: %(page)s of document: %(document)s') % {
|
||||
'page': document_page.page_number, 'document': document_page.document},
|
||||
'web_theme_hide_menus': True,
|
||||
'source': source,
|
||||
'object_name': _(u'source'),
|
||||
'navigation_object_name': 'source',
|
||||
'title': _(u'Create new transformation for source: %s') % source,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user