Added document preview and display size view, merged with 960 grid branch
This commit is contained in:
@@ -5,6 +5,7 @@ from django.utils.translation import ugettext
|
||||
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 staging import StagingFile
|
||||
|
||||
@@ -14,9 +15,34 @@ from common.forms import DetailForm
|
||||
|
||||
from models import Document, DocumentType, DocumentTypeMetadataType
|
||||
|
||||
from documents.conf.settings import AVAILABLE_FUNCTIONS
|
||||
from documents.conf.settings import AVAILABLE_MODELS
|
||||
|
||||
#from documents.conf.settings import AVAILABLE_FUNCTIONS
|
||||
#from documents.conf.settings import AVAILABLE_MODELS
|
||||
#from documents.conf.settings import DISPLAY_SIZE
|
||||
|
||||
|
||||
class ImageWidget(forms.widgets.Widget):
|
||||
def render(self, name, value, attrs=None):
|
||||
output = []
|
||||
#img = lambda x: '<a class="fancybox" href="%s"><img src="%s" /></a>' % (reverse('document_preview', args=[x.id]),
|
||||
# reverse('document_thumbnail', args=[x.id]))
|
||||
output.append('<a class="fancybox" href="%s"><img src="%s" /></a>' % (reverse('document_display', args=[value.id]),
|
||||
reverse('document_preview', args=[value.id])))
|
||||
output.append('<br /><span class="famfam active famfam-magnifier"></span>%s' % ugettext(u'Click on the image for full size view'))
|
||||
#file_name = str(value)
|
||||
#if file_name:
|
||||
# file_path = '%s%s' % (settings.MEDIA_URL, file_name)
|
||||
# try: # is image
|
||||
# Image.open(os.path.join(settings.MEDIA_ROOT, file_name))
|
||||
# output.append('<a target="_blank" href="%s">%s</a><br />%s <a target="_blank" href="%s">%s</a><br />%s ' % \
|
||||
# (file_path, thumbnail(file_name), _('Currently:'), file_path, file_name, _('Change:')))
|
||||
# except IOError: # not image
|
||||
# output.append('%s <a target="_blank" href="%s">%s</a> <br />%s ' % \
|
||||
# (_('Currently:'), file_path, file_name, _('Change:')))
|
||||
#
|
||||
#output.append(super(ImageWidget, self).render(name, value, attrs))
|
||||
return mark_safe(u''.join(output))
|
||||
|
||||
|
||||
#TODO: Turn this into a base form and let others inherit
|
||||
class DocumentForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -37,6 +63,16 @@ class DocumentForm(forms.ModelForm):
|
||||
model = Document
|
||||
exclude = ('description',)
|
||||
|
||||
class DocumentPreviewForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.document = kwargs.pop('document', None)
|
||||
super(DocumentPreviewForm, self).__init__(*args, **kwargs)
|
||||
self.fields['preview'].initial = self.document#reverse('document_preview', args=[self.document.id])
|
||||
|
||||
|
||||
preview = forms.CharField(widget=ImageWidget)
|
||||
#ImageWidget
|
||||
|
||||
|
||||
class DocumentForm_view(DetailForm):
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user