Let attribute name, width, and height be controlled by schema
This commit is contained in:
parent
b29d06061b
commit
93c005765e
|
@ -163,5 +163,24 @@ class IPreviewDoc(IField):
|
|||
description=IField['missing_value'].description,
|
||||
required=False)
|
||||
|
||||
required = schema.Bool(
|
||||
title=IField['required'].title,
|
||||
description=IField['required'].description,
|
||||
default=False)
|
||||
|
||||
attribute_name = schema.TextLine(
|
||||
title=u'Attribute Name',
|
||||
description=u'Attribute Name',
|
||||
required=True,
|
||||
default=u'fichier')
|
||||
|
||||
width = schema.TextLine(
|
||||
title=u'Width',
|
||||
required=False)
|
||||
|
||||
height = schema.TextLine(
|
||||
title=u'Height',
|
||||
required=False)
|
||||
|
||||
class IPreviewDocWidget(IWidget):
|
||||
pass
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
tal:omit-tag="">
|
||||
<object tal:condition="view/href"
|
||||
tal:attributes="href view/href"
|
||||
tal:attributes="href view/href;
|
||||
width view/width;
|
||||
height view/height"
|
||||
type="application/pdf" width="200px" height="100px">
|
||||
<p>Pas de lecteur PDF intégré, vous pouvez ouvrir le fichier
|
||||
en suivant ce lien : <a tal:attributes="href view/href"
|
||||
|
|
|
@ -350,19 +350,35 @@ def PreviewDocFieldWidget(field, request):
|
|||
class PreviewDocWidget(Widget):
|
||||
implements(IPreviewDocWidget)
|
||||
|
||||
def width(self):
|
||||
if hasattr(self.field, 'width'):
|
||||
return self.field.width
|
||||
return u'200px'
|
||||
|
||||
def height(self):
|
||||
if hasattr(self.field, 'height'):
|
||||
return self.field.height
|
||||
return u'100px'
|
||||
|
||||
def get_attribute_name(self):
|
||||
if hasattr(self.field, 'attribute_name'):
|
||||
return self.field.attribute_name
|
||||
else:
|
||||
return 'fichier'
|
||||
|
||||
def href(self):
|
||||
if not hasattr(self.context, 'fichier'):
|
||||
if not hasattr(self.context, self.get_attribute_name()):
|
||||
return None
|
||||
if self.context.fichier:
|
||||
return self.form.widgets['fichier'].download_url
|
||||
if getattr(self.context, self.get_attribute_name()):
|
||||
return self.form.widgets[self.get_attribute_name()].download_url
|
||||
return None
|
||||
|
||||
def filename(self):
|
||||
if not hasattr(self.context, 'fichier'):
|
||||
if not hasattr(self.context, self.get_attribute_name()):
|
||||
return ''
|
||||
if self.context.fichier:
|
||||
if self.form.widgets['fichier'].filename_encoded:
|
||||
return self.form.widgets['fichier'].filename_encoded
|
||||
if getattr(self.context, self.get_attribute_name()):
|
||||
if self.form.widgets[self.get_attribute_name()].filename_encoded:
|
||||
return self.form.widgets[self.get_attribute_name()].filename_encoded
|
||||
return 'unknown.pdf'
|
||||
return ''
|
||||
|
||||
|
|
Reference in New Issue