[pod+gen] Added POD rendering based on ODS templates. Integrated with gen.

This commit is contained in:
Gaetan Delannay 2013-02-05 08:51:25 +01:00
parent d5d99b67eb
commit 43261fde60
8 changed files with 144 additions and 92 deletions

View file

@ -272,6 +272,12 @@ class ZopeInstaller:
appyType.template)
if os.path.exists(fileName):
setattr(appyTool, attrName, fileName)
# If the template is ods, set the default format to ods
# (because default is odt)
if fileName.endswith('.ods'):
formats = appyTool.getAttributeName('formats',
appyClass, appyType.name)
setattr(appyTool, formats, ['ods'])
appyTool.log('Imported "%s" in the tool in ' \
'attribute "%s"'% (fileName, attrName))
else:

View file

@ -94,6 +94,8 @@ appyLabels = [
('pdf', 'PDF'),
('doc', 'DOC'),
('rtf', 'RTF'),
('ods', 'ODS'),
('xls', 'XLS'),
('front_page_text', 'Welcome to this Appy-powered site.'),
('captcha_text', 'Please type "${text}" (without the double quotes) in the ' \
'field besides, but without the character at position ' \

BIN
gen/ui/ods.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 B

BIN
gen/ui/xls.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

View file

@ -54,7 +54,7 @@ class ToolWrapper(AbstractWrapper):
(user.o.absolute_url(), user.title,access))
return res + '\n'.join(rows) + '</table>'
podOutputFormats = ('odt', 'pdf', 'doc', 'rtf')
podOutputFormats = ('odt', 'pdf', 'doc', 'rtf', 'ods', 'xls')
def getPodOutputFormats(self):
'''Gets the available output formats for POD documents.'''
return [(of, self.translate(of)) for of in self.podOutputFormats]
@ -185,4 +185,36 @@ class ToolWrapper(AbstractWrapper):
except Exception, e:
failed.append(startObject)
return nb, failed
def validate(self, new, errors):
'''Validates that uploaded POD templates and output types are
compatible.'''
page = self.request.get('page', 'main')
if page == 'documents':
# Check that uploaded templates and output formats are compatible.
for fieldName in dir(new):
# Ignore fields which are not POD templates.
if not fieldName.startswith('podTemplate'): continue
# Get the file name, either from the newly uploaded file or
# from the existing file stored in the database.
if getattr(new, fieldName):
fileName = getattr(new, fieldName).filename
else:
fileName = getattr(self, fieldName).name
# Get the extension of the uploaded file.
ext = os.path.splitext(fileName)[1][1:]
# Get the chosen output formats for this template.
formatsFieldName = 'formatsFor%s' % fieldName[14:]
formats = getattr(new, formatsFieldName)
error = False
if ext == 'odt':
error = ('ods' in formats) or ('xls' in formats)
elif ext == 'ods':
error = ('odt' in formats) or ('pdf' in formats) or \
('doc' in formats) or ('rtf' in formats)
if error:
msg = 'This (these) format(s) cannot be used with ' \
'this template.'
setattr(errors, formatsFieldName, msg)
return self._callCustom('validate', new, errors)
# ------------------------------------------------------------------------------