Commit d1582b54 authored by Michel Pelletier's avatar Michel Pelletier

Added tag() method contributed by Bruce Perens.

parent e05de84e
......@@ -84,7 +84,7 @@
##############################################################################
"""Image object"""
__version__='$Revision: 1.78 $'[11:-2]
__version__='$Revision: 1.79 $'[11:-2]
import Globals, string, struct, content_types
from OFS.content_types import guess_content_type
......@@ -144,13 +144,17 @@ class File(Persistent,Implicit,PropertyManager,
)
__ac_permissions__=(
('View management screens', ('manage','manage_main',
'manage_uploadForm',)),
('Change Images and Files', ('manage_edit','manage_upload','PUT')),
('View', ('index_html','view_image_or_file','getSize','getContentType',
'')),
('FTP access', ('manage_FTPstat','manage_FTPget','manage_FTPlist')),
('Delete objects', ('DELETE',)),
('View management screens',
('manage', 'manage_main', 'manage_uploadForm',)),
('Change Images and Files',
('manage_edit','manage_upload','PUT')),
('View',
('index_html', 'tag', 'view_image_or_file', 'getSize',
'getContentType', '')),
('FTP access',
('manage_FTPstat','manage_FTPget','manage_FTPlist')),
('Delete objects',
('DELETE',)),
)
......@@ -440,6 +444,37 @@ class Image(File):
self.absolute_url(), width, height, self.title_or_id()
)
def tag(self, height=None, width=None, alt=None, **args):
"""
Generate an HTML IMG tag for this image, with customization.
Arguments to self.tag() can be any valid attributes of an IMG tag.
'src' will always be an absolute pathname, to prevent redundant
downloading of images. Defaults are applied intelligently for
'height', 'width', and 'alt'.
"""
if not alt:
alt=self.title_or_id()
string='<img src="%s" alt="%s"' % (self.absolute_url(), alt)
if not height:
height = self.height
if height:
string = "%s height=%s" % (string, height)
if not width:
width = self.width
if width:
string = "%s width=%s" % (string, width)
for key in args.keys():
value = args.get(key)
string = "%s %s=%s" % (string, key, value)
return string + '>'
def cookId(id, title, file):
if not id and hasattr(file,'filename'):
filename=file.filename
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment