Merged all document widget generation code into one place
This commit is contained in:
+22
-61
@@ -9,10 +9,11 @@ from common.forms import DetailForm
|
||||
from common.literals import PAGE_SIZE_CHOICES, PAGE_ORIENTATION_CHOICES
|
||||
from common.conf.settings import DEFAULT_PAPER_SIZE
|
||||
from common.conf.settings import DEFAULT_PAGE_ORIENTATION
|
||||
from common.widgets import TextAreaDiv
|
||||
from common.widgets import TextAreaDiv
|
||||
|
||||
from documents.models import Document, DocumentType, \
|
||||
DocumentPage, DocumentPageTransformation, DocumentTypeFilename
|
||||
from documents.widgets import document_html_widget
|
||||
|
||||
|
||||
# Document page forms
|
||||
@@ -32,22 +33,10 @@ class DocumentPageImageWidget(forms.widgets.Widget):
|
||||
rotation = final_attrs.get('rotation', 0)
|
||||
if value:
|
||||
output = []
|
||||
output.append('''
|
||||
<div class="full-height scrollable" style="overflow: auto;">
|
||||
<div class="tc">
|
||||
<img class="lazy-load" data-href="%(img)s?page=%(page)d&zoom=%(zoom)d&rotation=%(rotation)d" src="%(static_url)s/images/ajax-loader.gif" alt="%(string)s" />
|
||||
<noscript>
|
||||
<img src="%(img)s?page=%(page)d&zoom=%(zoom)d&rotation=%(rotation)d" alt="%(string)s" />
|
||||
</noscript>
|
||||
</div>
|
||||
</div>''' % {
|
||||
'img': reverse('document_display', args=[value.document.id]),
|
||||
'page': value.page_number,
|
||||
'zoom': zoom,
|
||||
'rotation': rotation,
|
||||
'static_url': settings.STATIC_URL,
|
||||
'string': ugettext(u'page image')
|
||||
})
|
||||
output.append('<div class="full-height scrollable" style="overflow: auto;">')
|
||||
|
||||
output.append(document_html_widget(value.document, size='document_display', page=value.page_number, zoom=zoom, rotation=rotation))
|
||||
output.append('</div>')
|
||||
return mark_safe(u''.join(output))
|
||||
else:
|
||||
return u''
|
||||
@@ -113,52 +102,24 @@ class DocumentPagesCarouselWidget(forms.widgets.Widget):
|
||||
output.append(u'<div style="white-space:nowrap; overflow: auto;">')
|
||||
|
||||
for page in value.documentpage_set.all():
|
||||
try:
|
||||
page.document.get_valid_image()
|
||||
template = u'''<div style="display: inline-block; margin: 5px 10px 10px 10px;">
|
||||
<div class="tc">%(page_string)s %(page)s</div>
|
||||
<div class="tc" style="border: 1px solid black; margin: 5px 0px 5px 0px;">
|
||||
<a rel="page_gallery" class="fancybox-noscaling" href="%(view_url)s?page=%(page)d">
|
||||
<img class="lazy-load" data-href="%(img)s?page=%(page)d" src="%(static_url)s/images/ajax-loader.gif" alt="%(string)s" />
|
||||
<noscript>
|
||||
<img src="%(img)s?page=%(page)d" alt="%(string)s" />
|
||||
</noscript>
|
||||
</a>
|
||||
</div>
|
||||
<div class="tc">
|
||||
<a class="fancybox-iframe" href="%(url)s"><span class="famfam active famfam-page_white_go"></span>%(details_string)s</a>
|
||||
</div>
|
||||
</div>'''
|
||||
except:
|
||||
template = u'''<div style="display: inline-block; margin: 5px 10px 10px 10px;">
|
||||
<div class="tc">%(page_string)s %(page)s</div>
|
||||
<div class="tc" style="border: 1px solid black; margin: 5px 0px 5px 0px;">
|
||||
<img class="lazy-load" data-href="%(img)s?page=%(page)d" src="%(static_url)s/images/ajax-loader.gif" alt="%(string)s" />
|
||||
<noscript>
|
||||
<img src="%(img)s?page=%(page)d" alt="%(string)s" />
|
||||
</noscript>
|
||||
</div>
|
||||
<div class="tc">
|
||||
<a class="fancybox-iframe" href="%(url)s"><span class="famfam active famfam-page_white_go"></span>%(details_string)s</a>
|
||||
</div>
|
||||
</div>'''
|
||||
|
||||
|
||||
output.append(template % {
|
||||
'url': reverse('document_page_view', args=[page.pk]),
|
||||
'img': reverse('document_preview_multipage', args=[value.pk]),
|
||||
'page': page.page_number,
|
||||
'view_url': reverse('document_display', args=[page.document.pk]),
|
||||
'page_string': ugettext(u'Page'),
|
||||
'details_string': ugettext(u'Details'),
|
||||
'static_url': settings.STATIC_URL,
|
||||
'string': _(u'document page')
|
||||
})
|
||||
output.append(u'<div style="display: inline-block; margin: 5px 10px 10px 10px;">')
|
||||
output.append(
|
||||
document_html_widget(
|
||||
page.document,
|
||||
size='document_preview_multipage',
|
||||
click_view='document_display',
|
||||
page=page.page_number,
|
||||
gallery_name='document_pages',
|
||||
fancybox_class='fancybox-noscaling',
|
||||
)
|
||||
)
|
||||
output.append(u'<div class="tc">')
|
||||
output.append(u'<a class="fancybox-iframe" href="%s"><span class="famfam active famfam-page_white_go"></span>%s</a>' % (reverse('document_page_view', args=[page.pk]), ugettext(u'Details')))
|
||||
output.append(u'</div>')
|
||||
output.append(u'</div>')
|
||||
|
||||
output.append(u'</div>')
|
||||
output.append(
|
||||
u'<br /><span class="famfam active famfam-magnifier"></span>%s' %
|
||||
ugettext(u'Click on the image for full size preview'))
|
||||
output.append(u'<br /><span class="famfam active famfam-magnifier"></span>%s' % ugettext(u'Click on the image for full size preview'))
|
||||
|
||||
return mark_safe(u''.join(output))
|
||||
|
||||
|
||||
+46
-15
@@ -2,25 +2,56 @@ from django.utils.safestring import mark_safe
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.http import urlencode
|
||||
|
||||
from converter.exceptions import UnknownFileFormat, UnkownConvertError
|
||||
|
||||
|
||||
def document_thumbnail(document):
|
||||
try:
|
||||
document.get_valid_image()
|
||||
template = u'<a class="fancybox" href="%(url)s"><img class="lazy-load" data-href="%(thumbnail)s" src="%(static_url)s/images/ajax-loader.gif" alt="%(string)s" /><noscript><img src="%(thumbnail)s" alt="%(string)s" /></noscript></a>'
|
||||
except:
|
||||
template = u'<img class="lazy-load" data-href="%(thumbnail)s" src="%(static_url)s/images/ajax-loader.gif" alt="%(string)s" /><noscript><img src="%(thumbnail)s" alt="%(string)s" /></noscript>'
|
||||
|
||||
try:
|
||||
return mark_safe(template % {
|
||||
'url': reverse('document_preview', args=[document.pk]),
|
||||
'thumbnail': reverse('document_thumbnail', args=[document.pk]),
|
||||
'static_url': settings.STATIC_URL,
|
||||
'string': _(u'thumbnail')
|
||||
})
|
||||
except:
|
||||
return u''
|
||||
return document_html_widget(document, click_view='document_preview')
|
||||
|
||||
|
||||
def document_link(document):
|
||||
return mark_safe(u'<a href="%s">%s</a>' % (reverse('document_view_simple', args=[document.pk]), document))
|
||||
|
||||
|
||||
def document_html_widget(document, size='document_thumbnail', click_view=None, page=None, zoom=None, rotation=None, gallery_name=None, fancybox_class='fancybox'):
|
||||
result = []
|
||||
|
||||
alt_text = _(u'document page image')
|
||||
query_dict = {}
|
||||
|
||||
if page:
|
||||
query_dict['page'] = page
|
||||
|
||||
if zoom:
|
||||
query_dict['zoom'] = zoom
|
||||
|
||||
if rotation:
|
||||
query_dict['rotation'] = rotation
|
||||
|
||||
if gallery_name:
|
||||
gallery_template = u'rel="%s"' % gallery_name
|
||||
else:
|
||||
gallery_template = u''
|
||||
|
||||
query_string = urlencode(query_dict)
|
||||
preview_view = u'%s?%s' % (reverse(size, args=[document.pk]), query_string)
|
||||
|
||||
try:
|
||||
document.get_valid_image()
|
||||
result.append('<div class="tc">')
|
||||
if click_view:
|
||||
result.append('<a %s class="%s" href="%s">' % (gallery_template, fancybox_class, u'%s?%s' % (reverse(click_view, args=[document.pk]), query_string)))
|
||||
result.append('<img style="border: 1px solid black;" class="lazy-load" data-href="%s" src="%s/images/ajax-loader.gif" alt="%s" />' % (preview_view, settings.STATIC_URL, alt_text))
|
||||
result.append('<noscript><img style="border: 1px solid black;" src="%s" alt="%s" /></noscript>' % (preview_view, alt_text))
|
||||
if click_view:
|
||||
result.append('</a>')
|
||||
result.append('</div>')
|
||||
except UnknownFileFormat, UnkownConvertError:
|
||||
result.append('<div class="tc">')
|
||||
result.append('<img class="lazy-load" data-href="%s" src="%s/images/ajax-loader.gif" alt="%s" />' % (preview_view, settings.STATIC_URL, alt_text))
|
||||
result.append('<noscript><img src="%s" alt="%s" /></noscript>' % (preview_view, alt_text))
|
||||
result.append('</div>')
|
||||
|
||||
return mark_safe(u''.join(result))
|
||||
|
||||
+17
-54
@@ -6,6 +6,7 @@ from django.utils.safestring import mark_safe
|
||||
from django.template.defaultfilters import capfirst
|
||||
from django.conf import settings
|
||||
|
||||
from documents.widgets import document_html_widget
|
||||
from tags.widgets import get_tags_inline_widget
|
||||
|
||||
from linking.models import SmartLink, SmartLinkCondition
|
||||
@@ -36,62 +37,24 @@ class SmartLinkImageWidget(forms.widgets.Widget):
|
||||
''' % {
|
||||
'famfam': link.get('famfam', u'link'),
|
||||
'text': capfirst(link['text']),
|
||||
'action': reverse(link.get('view'), args=[value['current_document'].pk, value['group'].pk])
|
||||
'action': reverse(link.get('view'), args=[value['current_document'].pk, value['smart_link_instance'].pk])
|
||||
})
|
||||
output.append(u'</div>')
|
||||
|
||||
output.append(u'<div style="white-space:nowrap; overflow: auto;">')
|
||||
for document in value['group_data']:
|
||||
tags_template = get_tags_inline_widget(document)
|
||||
|
||||
try:
|
||||
document.get_valid_image()
|
||||
template = u'''<div style="display: inline-block; margin: 0px 10px 10px 10px; %(current)s">
|
||||
<div class="tc">%(document_name)s</div>
|
||||
<div class="tc">%(page_string)s: %(document_pages)d</div>
|
||||
%(tags_template)s
|
||||
<div class="tc">
|
||||
<a rel="group_%(group_id)d_documents_gallery" class="fancybox-noscaling" href="%(view_url)s">
|
||||
<img class="lazy-load" style="border: 1px solid black; margin: 10px;" src="%(static_url)s/images/ajax-loader.gif" data-href="%(img)s" alt="%(string)s" />
|
||||
<noscript>
|
||||
<img style="border: 1px solid black; margin: 10px;" src="%(img)s" alt="%(string)s" />
|
||||
</noscript>
|
||||
</a>
|
||||
</div>
|
||||
<div class="tc">
|
||||
<a href="%(url)s"><span class="famfam active famfam-page_go"></span>%(details_string)s</a>
|
||||
</div>
|
||||
</div>'''
|
||||
except:
|
||||
template = u'''<div style="display: inline-block; margin: 0px 10px 10px 10px; %(current)s">
|
||||
<div class="tc">%(document_name)s</div>
|
||||
<div class="tc">%(page_string)s: %(document_pages)d</div>
|
||||
%(tags_template)s
|
||||
<div class="tc">
|
||||
<img class="lazy-load" style="border: 1px solid black; margin: 10px;" src="%(static_url)s/images/ajax-loader.gif" data-href="%(img)s" alt="%(string)s" />
|
||||
<noscript>
|
||||
<img style="border: 1px solid black; margin: 10px;" src="%(img)s" alt="%(string)s" />
|
||||
</noscript>
|
||||
</div>
|
||||
<div class="tc">
|
||||
<a href="%(url)s"><span class="famfam active famfam-page_go"></span>%(details_string)s</a>
|
||||
</div>
|
||||
</div>'''
|
||||
|
||||
output.append(template % {
|
||||
'url': reverse('document_view_simple', args=[document.pk]),
|
||||
'img': reverse('document_preview_multipage', args=[document.pk]),
|
||||
'current': u'border: 5px solid black; padding: 3px;' if value['current_document'] == document else u'',
|
||||
'view_url': reverse('document_display', args=[document.pk]),
|
||||
'document_pages': document.documentpage_set.count(),
|
||||
'page_string': ugettext(u'Pages'),
|
||||
'details_string': ugettext(u'Select'),
|
||||
'group_id': value['group'].pk,
|
||||
'document_name': document,
|
||||
'static_url': settings.STATIC_URL,
|
||||
'tags_template': tags_template if tags_template else u'',
|
||||
'string': _(u'smart links'),
|
||||
})
|
||||
for document in value['documents']:
|
||||
output.append(u'<div style="display: inline-block; margin: 0px 10px 10px 10px; %s">' % (u'border: 5px solid black; padding: 3px;' if value['current_document'] == document else u''))
|
||||
output.append(u'<div class="tc">%s</div>' % document)
|
||||
output.append(u'<div class="tc">%s: %d</div>' % (ugettext(u'Pages'), document.documentpage_set.count()))
|
||||
output.append(get_tags_inline_widget(document))
|
||||
output.append(u'<div style="padding: 5px;">' % document)
|
||||
output.append(document_html_widget(document, click_view='document_display', size='document_preview_multipage', fancybox_class='fancybox-noscaling', gallery_name=u'smart_link_%d_documents_gallery' % value['smart_link_instance'].pk))
|
||||
output.append(u'</div>')
|
||||
output.append(u'<div class="tc">')
|
||||
output.append(u'<a href="%s"><span class="famfam active famfam-page_go"></span>%s</a>' % (reverse('document_view_simple', args=[document.pk]), ugettext(u'Select')))
|
||||
output.append(u'</div>')
|
||||
output.append(u'</div>')
|
||||
|
||||
output.append(u'</div>')
|
||||
output.append(
|
||||
u'<br /><span class="famfam active famfam-magnifier"></span>%s' %
|
||||
@@ -114,8 +77,8 @@ class SmartLinkInstanceForm(forms.Form):
|
||||
label=u'%s (%d)' % (unicode(data['title']), len(data['documents'])),
|
||||
required=False,
|
||||
initial={
|
||||
'group': smart_link_instance,
|
||||
'group_data': data['documents'],
|
||||
'smart_link_instance': smart_link_instance,
|
||||
'documents': data['documents'],
|
||||
'current_document': current_document,
|
||||
'links': links
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user