fs_loader now accepts a file object as a possible value o media.
This commit is contained in:
parent
9d8d79110c
commit
2a0f00c2d5
1 changed files with 9 additions and 5 deletions
14
secretary.py
14
secretary.py
|
|
@ -345,6 +345,7 @@ class Renderer(object):
|
||||||
extension = guess_extension(mime)
|
extension = guess_extension(mime)
|
||||||
|
|
||||||
media_path = 'Pictures/%s%s' % (name, extension)
|
media_path = 'Pictures/%s%s' % (name, extension)
|
||||||
|
media.seek(0)
|
||||||
self.files[media_path] = media.read(-1)
|
self.files[media_path] = media.read(-1)
|
||||||
if hasattr(media, 'close'):
|
if hasattr(media, 'close'):
|
||||||
media.close()
|
media.close()
|
||||||
|
|
@ -359,10 +360,12 @@ class Renderer(object):
|
||||||
|
|
||||||
def fs_loader(self, media, *args, **kwargs):
|
def fs_loader(self, media, *args, **kwargs):
|
||||||
"""Loads a file from the file system.
|
"""Loads a file from the file system.
|
||||||
:param media: relative or absolute path of file to load.
|
:param media: A file object or a relative or absolute path of a file.
|
||||||
:type media: unicode
|
:type media: unicode
|
||||||
"""
|
"""
|
||||||
if path.isfile(media):
|
if hasattr(media, 'seek') and hasattr(media, 'read'):
|
||||||
|
return (media, 'image/jpeg')
|
||||||
|
elif path.isfile(media):
|
||||||
filename = media
|
filename = media
|
||||||
else:
|
else:
|
||||||
if not self.media_path:
|
if not self.media_path:
|
||||||
|
|
@ -420,9 +423,10 @@ class Renderer(object):
|
||||||
image_node.setAttribute(k, v)
|
image_node.setAttribute(k, v)
|
||||||
|
|
||||||
# Keep original image reference value
|
# Keep original image reference value
|
||||||
frame.setAttribute('draw:name',
|
if isinstance(self.template_images[key]['value'], basestring):
|
||||||
self.template_images[key]['value'])
|
frame.setAttribute('draw:name',
|
||||||
|
self.template_images[key]['value'])
|
||||||
|
|
||||||
# Does the madia loader returned something?
|
# Does the madia loader returned something?
|
||||||
if not image:
|
if not image:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue