[gen] Bugfixes in the pod field.

This commit is contained in:
Gaetan Delannay 2014-09-16 15:38:29 +02:00
parent f64493764f
commit f4ea1a5570

View file

@ -381,6 +381,9 @@ class Pod(Field):
# Add the field-specific and custom contexts if present. # Add the field-specific and custom contexts if present.
if specificContext: podContext.update(specificContext) if specificContext: podContext.update(specificContext)
if customContext: podContext.update(customContext) if customContext: podContext.update(customContext)
# Variable "_checked" can be expected by a template but absent (ie,
# when generating frozen documents).
if '_checked' not in podContext: podContext['_checked'] = Object()
# Define a potential global styles mapping # Define a potential global styles mapping
if callable(self.stylesMapping): if callable(self.stylesMapping):
stylesMapping = self.callMethod(obj, self.stylesMapping) stylesMapping = self.callMethod(obj, self.stylesMapping)
@ -413,6 +416,7 @@ class Pod(Field):
'''Gets the name on disk on the frozen document corresponding to this '''Gets the name on disk on the frozen document corresponding to this
pod field, p_template and p_format.''' pod field, p_template and p_format.'''
template = template or self.template[0] template = template or self.template[0]
template = os.path.basename(template)
templateName = os.path.splitext(template)[0].replace(os.sep, '_') templateName = os.path.splitext(template)[0].replace(os.sep, '_')
return '%s_%s%s%s' % (self.name, templateName, sep, format) return '%s_%s%s%s' % (self.name, templateName, sep, format)
@ -460,19 +464,20 @@ class Pod(Field):
type='error') type='error')
if not freezeOdtOnError or (format == 'odt'): if not freezeOdtOnError or (format == 'odt'):
raise Exception(self.FREEZE_FATAL_ERROR) raise Exception(self.FREEZE_FATAL_ERROR)
obj.log('Trying to freeze the ODT version...') obj.log('freezing the ODT version...')
# Try to freeze the ODT version of the document, which does not # Freeze the ODT version of the document, which does not require
# require to call LibreOffice: the risk of error is smaller. # to call LibreOffice: the risk of error is smaller.
fileName = self.getFreezeName(template, 'odt') fileName = self.getFreezeName(template, 'odt')
result = os.path.join(dbFolder, folder, fileName) result = os.path.join(dbFolder, folder, fileName)
if os.path.exists(result): if os.path.exists(result):
obj.log('Freeze: overwriting %s...' % result) obj.log('freeze: overwriting %s...' % result)
doc = self.getValue(obj, template=template, format='odt', doc = self.getValue(obj, template=template, format='odt',
result=result) result=result)
if isinstance(doc, basestring): if isinstance(doc, basestring):
self.log(self.FREEZE_ERROR % ('odt', self.name, doc), self.log(self.FREEZE_ERROR % ('odt', self.name, doc),
type='error') type='error')
raise Exception(self.FREEZE_FATAL_ERROR) raise Exception(self.FREEZE_FATAL_ERROR)
obj.log('freezed at %s.' % result)
else: else:
# Store the uploaded file in the database. # Store the uploaded file in the database.
f = file(result, 'wb') f = file(result, 'wb')
@ -492,7 +497,9 @@ class Pod(Field):
dbFolder, folder = obj.o.getFsFolder() dbFolder, folder = obj.o.getFsFolder()
fileName = self.getFreezeName(template, format) fileName = self.getFreezeName(template, format)
frozenName = os.path.join(dbFolder, folder, fileName) frozenName = os.path.join(dbFolder, folder, fileName)
if os.path.exists(frozenName): os.remove(frozenName) if os.path.exists(frozenName):
os.remove(frozenName)
obj.log('removed (unfrozen) %s.' % frozenName)
def getFreezeFormats(self, obj, template=None): def getFreezeFormats(self, obj, template=None):
'''What are the formats into which the current user may freeze '''What are the formats into which the current user may freeze
@ -517,7 +524,9 @@ class Pod(Field):
def getCustomContext(self, obj, rq): def getCustomContext(self, obj, rq):
'''Before calling pod to compute a result, if specific elements must be '''Before calling pod to compute a result, if specific elements must be
added to the context, compute it here.''' added to the context, compute it here. This request-dependent method
is not called when computing a pod field for freezing it into the
database.'''
res = {} res = {}
# Get potential custom params from the request. Custom params must be # Get potential custom params from the request. Custom params must be
# coded as a string containing a valid Python dict. # coded as a string containing a valid Python dict.