Commit 7ead3ad4 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Initial fix of coding style. Implemented dynamic stylesheets.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12806 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 683b8ecf
......@@ -93,7 +93,6 @@ def add_and_edit(self, id, REQUEST):
u = "%s/%s" % (u, quote(id))
REQUEST.RESPONSE.redirect(u+'/manage_main')
class OOoTemplate(ZopePageTemplate):
"""
A page template which is able to embed and OpenOffice
......@@ -102,7 +101,7 @@ class OOoTemplate(ZopePageTemplate):
TODO:
- find a way to embed TALES in OOo documents in such
way that editing woth OOo does not destroy TAL/TALES
way that editing with OOo does not destroy TAL/TALES
- add preprocessing option to handle explicit macros in
OOo in any language. Include debugging options in this case
......@@ -130,7 +129,7 @@ class OOoTemplate(ZopePageTemplate):
constructors = (manage_addOOoTemplate, addOOoTemplate)
# Default Attributes
ooo_stylesheet = 'default_ooo_template'
ooo_stylesheet = 'Base_getODTStyleSheet'
# Default content type
#content_type = 'application/vnd.sun.xml.writer' # Writer type by default
......@@ -209,7 +208,7 @@ class OOoTemplate(ZopePageTemplate):
def _resolvePath(self, path):
return self.getPortalObject().unrestrictedTraverse(path)
def renderIncludes(self, text, sub_document=None):
def renderIncludes(self, here, text, sub_document=None):
attached_files_dict = {}
arguments_re = re.compile('(\w+)\s*=\s*"(.*?)"\s*',re.DOTALL)
......@@ -226,7 +225,6 @@ class OOoTemplate(ZopePageTemplate):
ret.append(val)
return ret
def replaceIncludes(match):
options_dict = dict( style="fr1", x="0cm", y="0cm" )
options_dict.update( dict(arguments_re.findall( match.group(1) )) )
......@@ -253,10 +251,14 @@ class OOoTemplate(ZopePageTemplate):
dir_name = '%s%d'%(self._OLE_directory_prefix,actual_idx)
if sub_document: # sub-document means sub-directory
dir_name = sub_document+'/'+dir_name
dir_name = sub_document + '/' + dir_name
try:
temp_builder = OOoBuilder(getattr(document,document.ooo_stylesheet))
ooo_stylesheet = getattr(here, document.ooo_stylesheet)
# If style is dynamic, call it
if callable(ooo_stylesheet):
ooo_stylesheet = ooo_stylesheet()
temp_builder = OOoBuilder(ooo_stylesheet)
stylesheet = temp_builder.extract('styles.xml')
except AttributeError:
stylesheet = None
......@@ -367,14 +369,14 @@ xmlns:config="http://openoffice.org/2001/config" office:version="1.0">
text:anchor-type="paragraph" svg:x="%s" svg:y="%s"
svg:width="%.3fcm" svg:height="%.3fcm" xlink:href="#Pictures/%s"
xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
"""%(options_dict['style'], actual_idx,
""" % (options_dict['style'], actual_idx,
options_dict['x'], options_dict['y'],
w, h,
pic_name.split('/')[-1] )
if not ( self.content_type.endswith('draw') or
if not (self.content_type.endswith('draw') or
self.content_type.endswith('presentation') or
self.content_type.endswith('writer') or
self.content_type.endswith('text') ):
self.content_type.endswith('text')):
replacement = '<text:p text:style-name="Standard">'+replacement+'</text:p>'
return replacement
......@@ -391,8 +393,16 @@ xmlns:config="http://openoffice.org/2001/config" office:version="1.0">
if not request:
request = get_request()
# Get parent object (the one to render this template on)
here = getattr(self, 'aq_parent', None)
if here is None:
# This is a system error
raise ValueError, 'Can not render a template without a parent acquisition context'
# Retrieve master document
ooo_document = getattr(self, self.ooo_stylesheet)
ooo_document = getattr(here, self.ooo_stylesheet)
# If style is dynamic, call it
if callable(ooo_stylesheet):
ooo_stylesheet = ooo_stylesheet()
# Create a new builder instance
ooo_builder = OOoBuilder(ooo_document)
# Pass builder instance as extra_context
......@@ -401,7 +411,7 @@ xmlns:config="http://openoffice.org/2001/config" office:version="1.0">
doc_xml = ZopePageTemplate.pt_render(self, source=source, extra_context=extra_context)
# Replace the includes
(doc_xml,attachments_dict) = self.renderIncludes(doc_xml)
(doc_xml,attachments_dict) = self.renderIncludes(here, doc_xml)
try:
default_styles_text = ooo_builder.extract('styles.xml')
......@@ -538,6 +548,3 @@ InitializeClass(FSOOoTemplate)
registerFileExtension('ooot', FSOOoTemplate)
registerMetaType(OOoTemplate.meta_type, FSOOoTemplate)
\ No newline at end of file
# vim: syntax=python shiftwidth=2
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