Convert the document print view to CBV. Tweak the print template. Make 'print all' pages the default.
This commit is contained in:
@@ -13,7 +13,7 @@ from common.forms import DetailForm, ModelForm
|
||||
from .models import (
|
||||
Document, DocumentType, DocumentPage, DocumentTypeFilename
|
||||
)
|
||||
from .literals import DEFAULT_ZIP_FILENAME, PAGE_RANGE_CHOICES
|
||||
from .literals import DEFAULT_ZIP_FILENAME, PAGE_RANGE_ALL, PAGE_RANGE_CHOICES
|
||||
from .permissions import permission_document_create
|
||||
from .widgets import DocumentPagesCarouselWidget, DocumentPageImageWidget
|
||||
|
||||
@@ -207,8 +207,9 @@ class DocumentDownloadForm(forms.Form):
|
||||
self.fields['compressed'].widget.attrs.update({'disabled': True})
|
||||
|
||||
|
||||
class PrintForm(forms.Form):
|
||||
class DocumentPrintForm(forms.Form):
|
||||
page_group = forms.ChoiceField(
|
||||
widget=forms.RadioSelect, choices=PAGE_RANGE_CHOICES
|
||||
choices=PAGE_RANGE_CHOICES, initial=PAGE_RANGE_ALL,
|
||||
widget=forms.RadioSelect
|
||||
)
|
||||
page_range = forms.CharField(label=_('Page range'), required=False)
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
|
||||
{% block content_plain %}
|
||||
{% for page in pages %}
|
||||
<img src="{% url 'rest_api:documentpage-image' page.id %}" />
|
||||
<img src="{% url 'rest_api:documentpage-image' page.id %}?size={{ size }}" />
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
setting_print_size.value
|
||||
|
||||
@@ -19,11 +19,12 @@ from .views import (
|
||||
DocumentListView, DocumentPageListView, DocumentPageRotateLeftView,
|
||||
DocumentPageRotateRightView, DocumentPageView, DocumentPageViewResetView,
|
||||
DocumentPageZoomInView, DocumentPageZoomOutView, DocumentPreviewView,
|
||||
DocumentRestoreView, DocumentRestoreManyView, DocumentTrashView,
|
||||
DocumentTrashManyView, DocumentTypeCreateView, DocumentTypeDeleteView,
|
||||
DocumentTypeDocumentListView, DocumentTypeFilenameCreateView,
|
||||
DocumentTypeFilenameDeleteView, DocumentTypeFilenameEditView,
|
||||
DocumentTypeFilenameListView, DocumentTypeListView, DocumentTypeEditView,
|
||||
DocumentPrint, DocumentRestoreView, DocumentRestoreManyView,
|
||||
DocumentTrashView, DocumentTrashManyView, DocumentTypeCreateView,
|
||||
DocumentTypeDeleteView, DocumentTypeDocumentListView,
|
||||
DocumentTypeFilenameCreateView, DocumentTypeFilenameDeleteView,
|
||||
DocumentTypeFilenameEditView, DocumentTypeFilenameListView,
|
||||
DocumentTypeListView, DocumentTypeEditView,
|
||||
DocumentVersionDownloadFormView, DocumentVersionDownloadView,
|
||||
DocumentVersionListView, DocumentVersionRevertView, DocumentView,
|
||||
EmptyTrashCanView, RecentDocumentListView, document_clear_transformations,
|
||||
@@ -31,7 +32,7 @@ from .views import (
|
||||
document_multiple_document_type_edit, document_multiple_update_page_count,
|
||||
document_page_navigation_first, document_page_navigation_last,
|
||||
document_page_navigation_next, document_page_navigation_previous,
|
||||
document_print, document_update_page_count
|
||||
document_update_page_count
|
||||
)
|
||||
|
||||
|
||||
@@ -92,7 +93,7 @@ urlpatterns = patterns(
|
||||
name='document_edit'
|
||||
),
|
||||
url(
|
||||
r'^(?P<document_id>\d+)/print/$', document_print,
|
||||
r'^(?P<pk>\d+)/print/$', DocumentPrint.as_view(),
|
||||
name='document_print'
|
||||
),
|
||||
url(
|
||||
|
||||
@@ -29,8 +29,8 @@ from converter.permissions import permission_transformation_delete
|
||||
from .events import event_document_download, event_document_view
|
||||
from .forms import (
|
||||
DocumentDownloadForm, DocumentForm, DocumentPageForm, DocumentPreviewForm,
|
||||
DocumentPropertiesForm, DocumentTypeSelectForm,
|
||||
DocumentTypeFilenameForm_create, PrintForm
|
||||
DocumentPrintForm, DocumentPropertiesForm, DocumentTypeSelectForm,
|
||||
DocumentTypeFilenameForm_create
|
||||
)
|
||||
from .literals import PAGE_RANGE_RANGE, DEFAULT_ZIP_FILENAME
|
||||
from .models import (
|
||||
@@ -1141,46 +1141,61 @@ class DocumentPageRotateRightView(DocumentPageInteractiveTransformation):
|
||||
) % 360
|
||||
|
||||
|
||||
def document_print(request, document_id):
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
class DocumentPrint(FormView):
|
||||
form_class = DocumentPrintForm
|
||||
|
||||
AccessControlList.objects.check_access(
|
||||
permissions=permission_document_print, user=request.user, obj=document
|
||||
)
|
||||
def form_valid(self, form):
|
||||
instance = self.get_object()
|
||||
|
||||
document.add_as_recent_document_for_user(request.user)
|
||||
|
||||
post_redirect = None
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', post_redirect or document.get_absolute_url())))
|
||||
|
||||
if request.method == 'POST':
|
||||
form = PrintForm(request.POST)
|
||||
if form.is_valid():
|
||||
if form.cleaned_data['page_group'] == PAGE_RANGE_RANGE:
|
||||
page_range = form.cleaned_data['page_range']
|
||||
|
||||
if page_range:
|
||||
page_range = parse_range(page_range)
|
||||
pages = document.pages.filter(page_number__in=page_range)
|
||||
pages = instance.pages.filter(page_number__in=page_range)
|
||||
else:
|
||||
pages = document.pages.all()
|
||||
pages = instance.pages.all()
|
||||
else:
|
||||
pages = document.pages.all()
|
||||
pages = instance.pages.all()
|
||||
|
||||
return render_to_response('documents/document_print.html', {
|
||||
context = self.get_context_data()
|
||||
|
||||
context.update(
|
||||
{
|
||||
'appearance_type': 'plain',
|
||||
'object': document,
|
||||
'pages': pages,
|
||||
'size': setting_print_size.value,
|
||||
'title': _('Print: %s') % document,
|
||||
}, context_instance=RequestContext(request))
|
||||
else:
|
||||
form = PrintForm()
|
||||
}
|
||||
)
|
||||
|
||||
return render_to_response('appearance/generic_form.html', {
|
||||
'form': form,
|
||||
'object': document,
|
||||
'next': next,
|
||||
'title': _('Print: %s') % document,
|
||||
return self.render_to_response(context=context)
|
||||
|
||||
def get_extra_context(self):
|
||||
instance = self.get_object()
|
||||
|
||||
context = {
|
||||
'object': instance,
|
||||
'submit_method': 'POST',
|
||||
'submit_label': _('Submit'),
|
||||
}, context_instance=RequestContext(request))
|
||||
'title': _('Print: %s') % instance,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
def get_object(self):
|
||||
instance = get_object_or_404(Document, pk=self.kwargs['pk'])
|
||||
|
||||
AccessControlList.objects.check_access(
|
||||
permissions=permission_document_print, user=self.request.user,
|
||||
obj=instance
|
||||
)
|
||||
|
||||
instance.add_as_recent_document_for_user(self.request.user)
|
||||
|
||||
return instance
|
||||
|
||||
def get_template_names(self):
|
||||
if self.request.method == 'POST':
|
||||
return ['documents/document_print.html']
|
||||
else:
|
||||
return [self.template_name]
|
||||
|
||||
Reference in New Issue
Block a user