Add dedicated pages append action

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-10-10 11:53:40 -04:00
parent ff03ea07ca
commit 739d496799
7 changed files with 85 additions and 33 deletions
+6 -6
View File
@@ -53,8 +53,8 @@ class MultiFormView(DjangoFormView):
template_name = 'appearance/generic_form.html'
def _create_form(self, form_name, klass):
form_kwargs = self.get_form_kwargs(form_name)
form_create_method = 'create_%s_form' % form_name
form_kwargs = self.get_form_kwargs(form_name=form_name)
form_create_method = 'create_{}_form'.format(form_name)
if hasattr(self, form_create_method):
form = getattr(self, form_create_method)(**form_kwargs)
else:
@@ -71,7 +71,7 @@ class MultiFormView(DjangoFormView):
def forms_valid(self, forms):
for form_name, form in forms.items():
form_valid_method = '%s_form_valid' % form_name
form_valid_method = '{}_form_valid'.format(form_name)
if hasattr(self, form_valid_method):
return getattr(self, form_valid_method)(form)
@@ -98,8 +98,8 @@ class MultiFormView(DjangoFormView):
def get_form_kwargs(self, form_name):
kwargs = {}
kwargs.update({'initial': self.get_initial(form_name)})
kwargs.update({'prefix': self.get_prefix(form_name)})
kwargs.update({'initial': self.get_initial(form_name=form_name)})
kwargs.update({'prefix': self.get_prefix(form_name=form_name)})
if self.request.method in ('POST', 'PUT'):
kwargs.update({
@@ -124,7 +124,7 @@ class MultiFormView(DjangoFormView):
)
def get_initial(self, form_name):
initial_method = 'get_%s_initial' % form_name
initial_method = 'get_{}_initial'.format(form_name)
if hasattr(self, initial_method):
return getattr(self, initial_method)()
else:
+11 -4
View File
@@ -21,9 +21,10 @@ from .handlers import (
handler_create_default_document_source, handler_initialize_periodic_tasks
)
from .links import (
link_document_create_multiple, link_setup_sources,
link_setup_source_check_now, link_setup_source_create_imap_email,
link_setup_source_create_pop3_email, link_setup_source_create_sane_scanner,
link_document_create_multiple, link_document_pages_append,
link_setup_sources, link_setup_source_check_now,
link_setup_source_create_imap_email, link_setup_source_create_pop3_email,
link_setup_source_create_sane_scanner,
link_setup_source_create_watch_folder, link_setup_source_create_webform,
link_setup_source_create_staging_folder, link_setup_source_delete,
link_setup_source_edit, link_setup_source_logs, link_staging_file_delete,
@@ -145,10 +146,16 @@ class SourcesApp(MayanAppConfig):
menu_secondary.bind_links(
links=(link_document_version_upload,),
sources=(
'documents:document_version_list', 'documents:upload_version',
'documents:document_version_list', 'sources:upload_version',
'documents:document_version_revert'
)
)
menu_secondary.bind_links(
links=(link_document_pages_append,),
sources=(
'documents:document_pages', 'sources:document_pages_append'
)
)
post_upgrade.connect(
receiver=handler_initialize_periodic_tasks,
+18 -11
View File
@@ -23,18 +23,25 @@ class NewDocumentForm(DocumentForm):
class NewVersionForm(forms.Form):
def __init__(self, *args, **kwargs):
super(NewVersionForm, self).__init__(*args, **kwargs)
comment = forms.CharField(
help_text=_('An optional comment to explain the upload.'),
label=_('Comment'), required=False,
widget=forms.widgets.Textarea(attrs={'rows': 4}),
)
self.fields['comment'] = forms.CharField(
label=_('Comment'),
required=False,
widget=forms.widgets.Textarea(attrs={'rows': 4}),
)
self.fields['append_pages'] = forms.BooleanField(
initial=False, label=_('Append pages?'),
required=False,
)
append_pages = forms.BooleanField(
help_text=_(
'If selected, the pages of the file uploaded will be appended '
'to the existing document pages. Otherwise the pages of the '
'upload will replace the existing pages of the document.'
), label=_('Append pages?'), required=False,
)
def __init__(self, *args, **kwargs):
hide_append_pages = kwargs.pop('hide_append_pages', False)
super(NewVersionForm, self).__init__(*args, **kwargs)
if hide_append_pages:
self.fields['append_pages'].widget = forms.widgets.HiddenInput()
class UploadBaseForm(forms.Form):
+4
View File
@@ -9,6 +9,10 @@ icon_document_version_upload = Icon(
driver_name='fontawesome', symbol='upload'
)
icon_log = Icon(driver_name='fontawesome', symbol='exclamation-triangle')
icon_document_pages_append = Icon(
driver_name='fontawesome-dual', primary_symbol='copy',
secondary_symbol='plus'
)
icon_setup_sources = Icon(driver_name='fontawesome', symbol='upload')
icon_setup_source_check_now = Icon(driver_name='fontawesome', symbol='check')
icon_setup_source_delete = Icon(driver_name='fontawesome', symbol='times')
+7
View File
@@ -113,6 +113,13 @@ link_staging_file_delete = Link(
permissions=(permission_document_new_version, permission_document_create),
tags='dangerous', text=_('Delete'), view='sources:staging_file_delete',
)
link_document_pages_append = Link(
args='resolved_object.pk',
icon_class_path='mayan.apps.sources.icons.icon_document_pages_append',
permissions=(permission_document_new_version,),
text=_('Append pages'),
view='sources:document_pages_append'
)
link_document_version_upload = Link(
args='resolved_object.pk', condition=document_new_version_not_blocked,
icon_class_path='mayan.apps.sources.icons.icon_document_version_upload',
+12 -3
View File
@@ -7,9 +7,10 @@ from .api_views import (
APIStagingSourceListView, APIStagingSourceView
)
from .views import (
SetupSourceCheckView, SetupSourceCreateView, SetupSourceDeleteView,
SetupSourceEditView, SetupSourceListView, SourceLogListView,
StagingFileDeleteView, UploadInteractiveVersionView, UploadInteractiveView
DocumentPagesAppendView, SetupSourceCheckView, SetupSourceCreateView,
SetupSourceDeleteView, SetupSourceEditView, SetupSourceListView,
SourceLogListView, StagingFileDeleteView, UploadInteractiveVersionView,
UploadInteractiveView
)
from .wizards import DocumentCreateWizard
@@ -41,6 +42,14 @@ urlpatterns = [
regex=r'^documents/(?P<document_pk>\d+)/versions/upload/interactive/$',
view=UploadInteractiveVersionView.as_view(), name='upload_version'
),
url(
regex=r'^documents/(?P<document_pk>\d+)/pages/append/interactive/(?P<source_id>\d+)/$',
view=DocumentPagesAppendView.as_view(), name='document_pages_append'
),
url(
regex=r'^documents/(?P<document_pk>\d+)/pages/append/interactive/$',
view=DocumentPagesAppendView.as_view(), name='document_pages_append'
),
# Setup views
+27 -9
View File
@@ -452,13 +452,6 @@ class UploadInteractiveVersionView(UploadBaseView):
files=kwargs.get('files', None),
)
def create_document_form_form(self, **kwargs):
return self.get_form_classes()['document_form'](
prefix=kwargs['prefix'],
data=kwargs.get('data', None),
files=kwargs.get('files', None),
)
def get_form_classes(self):
return {
'document_form': NewVersionForm,
@@ -471,8 +464,33 @@ class UploadInteractiveVersionView(UploadBaseView):
).get_context_data(**kwargs)
context['object'] = self.document
context['title'] = _(
'Upload a new version from source: %s'
) % self.source.label
'Upload a new version for document "%(document)s" from source: %(source)s'
) % {'document': self.document, 'source': self.source.label}
context['submit_label'] = _('Submit')
return context
class DocumentPagesAppendView(UploadInteractiveVersionView):
def get_document_form_initial(self):
return {
'append_pages': True,
}
def get_form_extra_kwargs(self, form_name):
if form_name == 'document_form':
return {
'hide_append_pages': True
}
def get_context_data(self, **kwargs):
context = super(
DocumentPagesAppendView, self
).get_context_data(**kwargs)
context['title'] = _(
'Append pages to document "%(document)s" from source: %(source)s'
) % {'document': self.document, 'source': self.source.label}
return context