Commit 52c3bced authored by Kevin Deldycke's avatar Kevin Deldycke

Be carefull : tabs were used to indent python code


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3520 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b0fdf613
...@@ -48,19 +48,19 @@ try: ...@@ -48,19 +48,19 @@ try:
SUPPORTS_WEBDAV_LOCKS = 1 SUPPORTS_WEBDAV_LOCKS = 1
except ImportError: except ImportError:
SUPPORTS_WEBDAV_LOCKS = 0 SUPPORTS_WEBDAV_LOCKS = 0
# FIXME: Programs linked against mandriva libgcj v 3.4.0 ave a strange # FIXME: Programs linked against mandriva libgcj v 3.4.0 ave a strange
# issue that make them impossible to popen within zope. # issue that make them impossible to popen within zope.
# That's why we do not use the 'real' pdftk but a replacement program, # That's why we do not use the 'real' pdftk but a replacement program,
# pdftk-emulation available from nexedi's RPM repositories. # pdftk-emulation available from nexedi's RPM repositories.
PDFTK_EXECUTABLE = "pdftk-emulation" PDFTK_EXECUTABLE = "pdftk-emulation"
class PDFTk : class PDFTk :
""" """
A class to wrapp calls to pdftk executable, found at A class to wrapp calls to pdftk executable, found at
http://www.accesspdf.com/pdftk/ http://www.accesspdf.com/pdftk/
""" """
def catPages(self, pdfFile, cat_option) : def catPages(self, pdfFile, cat_option) :
""" limit to a specific range of pages, like pdftk's cat option""" """ limit to a specific range of pages, like pdftk's cat option"""
return self._getOutput( return self._getOutput(
PDFTK_EXECUTABLE+ PDFTK_EXECUTABLE+
...@@ -69,28 +69,28 @@ class PDFTk : ...@@ -69,28 +69,28 @@ class PDFTk :
def dumpDataFields(self, pdfFile) : def dumpDataFields(self, pdfFile) :
""" returns the output of pdftk dump_data_fields as dict """ """ returns the output of pdftk dump_data_fields as dict """
return self._parseDumpDataFields(self.dumpDataFieldsTxt(pdfFile)) return self._parseDumpDataFields(self.dumpDataFieldsTxt(pdfFile))
def fillFormWithDict(self, pdfFile, values) : def fillFormWithDict(self, pdfFile, values) :
""" fill the form with values in """ """ fill the form with values in """
return self.fillFormWithFDF(pdfFile, self._createFdf(values)) return self.fillFormWithFDF(pdfFile, self._createFdf(values))
def fillFormWithFDF(self, pdfFile, fdfFile) : def fillFormWithFDF(self, pdfFile, fdfFile) :
""" fill the form of pdfFile with the FDF data fdfFile """ """ fill the form of pdfFile with the FDF data fdfFile """
pdfFormFileName = mktemp(suffix=".pdf") pdfFormFileName = mktemp(suffix=".pdf")
fdfFormFileName = mktemp(suffix=".fdf") fdfFormFileName = mktemp(suffix=".fdf")
if hasattr(pdfFile, "read") : if hasattr(pdfFile, "read") :
pdfFile = pdfFile.read() pdfFile = pdfFile.read()
tmpPdfFile=open(pdfFormFileName, "w") tmpPdfFile=open(pdfFormFileName, "w")
tmpPdfFile.write(pdfFile) tmpPdfFile.write(pdfFile)
tmpPdfFile.close() tmpPdfFile.close()
if hasattr(fdfFile, "read") : if hasattr(fdfFile, "read") :
fdfFile = fdfFile.read() fdfFile = fdfFile.read()
tmpFdfFile=open(fdfFormFileName, "w") tmpFdfFile=open(fdfFormFileName, "w")
tmpFdfFile.write(fdfFile) tmpFdfFile.write(fdfFile)
tmpFdfFile.close() tmpFdfFile.close()
out = self._getOutput( out = self._getOutput(
PDFTK_EXECUTABLE+ PDFTK_EXECUTABLE+
" %s fill_form %s output - "%( " %s fill_form %s output - "%(
...@@ -98,14 +98,14 @@ class PDFTk : ...@@ -98,14 +98,14 @@ class PDFTk :
os.remove(fdfFormFileName) os.remove(fdfFormFileName)
os.remove(pdfFormFileName) os.remove(pdfFormFileName)
return out return out
def dumpDataFieldsTxt(self, pdfFile) : def dumpDataFieldsTxt(self, pdfFile) :
""" returns the output of pdftk dump_data_fields as text, """ returns the output of pdftk dump_data_fields as text,
pdf file is either the file object or its content""" pdf file is either the file object or its content"""
return self._getOutput( return self._getOutput(
PDFTK_EXECUTABLE+" - dump_data_fields", pdfFile, PDFTK_EXECUTABLE+" - dump_data_fields", pdfFile,
assert_not_empty=0) assert_not_empty=0)
def _parseDumpDataFields(self, data_fields_dump) : def _parseDumpDataFields(self, data_fields_dump) :
""" parses the output of pdftk X.pdf dump_data_fields and """ parses the output of pdftk X.pdf dump_data_fields and
returns a sequence of dicts [{key = value}] """ returns a sequence of dicts [{key = value}] """
...@@ -121,7 +121,7 @@ class PDFTk : ...@@ -121,7 +121,7 @@ class PDFTk :
if field != {} : if field != {} :
fields+=[field] fields+=[field]
return fields return fields
def _getOutput(self, command, input=None, assert_not_empty=1) : def _getOutput(self, command, input=None, assert_not_empty=1) :
""" returns the output of command with sending input through command's """ returns the output of command with sending input through command's
input stream (if input parameter is given) """ input stream (if input parameter is given) """
...@@ -129,7 +129,7 @@ class PDFTk : ...@@ -129,7 +129,7 @@ class PDFTk :
if input: if input:
if hasattr(input, "read") : if hasattr(input, "read") :
input = input.read() input = input.read()
try : try :
stdin.write(input) stdin.write(input)
except IOError, e: except IOError, e:
raise IOError, str(e) + " ( make sure "\ raise IOError, str(e) + " ( make sure "\
...@@ -137,17 +137,17 @@ class PDFTk : ...@@ -137,17 +137,17 @@ class PDFTk :
stdin.close() stdin.close()
ret = stdout.read() ret = stdout.read()
stdout.close() stdout.close()
if assert_not_empty and len(ret) == 0 : if assert_not_empty and len(ret) == 0 :
raise IOError, "Got no output from external program, make sure"\ raise IOError, "Got no output from external program, make sure"\
" %s exists and is in your $PATH"%PDFTK_EXECUTABLE " %s exists and is in your $PATH"%PDFTK_EXECUTABLE
return ret return ret
def _escapeString(self, value) : def _escapeString(self, value) :
if value is None : if value is None :
return "" return ""
string = str(value) string = str(value)
escaped = '' escaped = ''
for c in string : for c in string :
if (ord(c) == 0x28 or # open paren if (ord(c) == 0x28 or # open paren
ord(c) == 0x29 or # close paren ord(c) == 0x29 or # close paren
ord(c) == 0x5c): # backslash ord(c) == 0x5c): # backslash
...@@ -157,23 +157,23 @@ class PDFTk : ...@@ -157,23 +157,23 @@ class PDFTk :
else: else:
escaped += c escaped += c
return escaped return escaped
def _createFdf(self, values, pdfFormUrl=None) : def _createFdf(self, values, pdfFormUrl=None) :
""" create an fdf document with the dict values """ """ create an fdf document with the dict values """
fdf = "%FDF-1.2\x0d%\xe2\xe3\xcf\xd3\x0d\x0a" fdf = "%FDF-1.2\x0d%\xe2\xe3\xcf\xd3\x0d\x0a"
fdf+= "1 0 obj\x0d<< \x0d/FDF << /Fields [ " fdf+= "1 0 obj\x0d<< \x0d/FDF << /Fields [ "
for key, value in values.items(): for key, value in values.items():
fdf+= "<< /T (%s) /V (%s)>> \x0d"%( fdf+= "<< /T (%s) /V (%s)>> \x0d"%(
self._escapeString(key), self._escapeString(key),
self._escapeString(value)) self._escapeString(value))
fdf+= "] \x0d" fdf+= "] \x0d"
# the PDF form filename or URL, if any # the PDF form filename or URL, if any
if pdfFormUrl not in ("", None) : if pdfFormUrl not in ("", None) :
fdf+= "/F ("+self._escapeString(pdfFormUrl)+") \x0d" fdf+= "/F ("+self._escapeString(pdfFormUrl)+") \x0d"
fdf+= ">> \x0d>> \x0dendobj\x0d"; fdf+= ">> \x0d>> \x0dendobj\x0d";
fdf+= "trailer\x0d<<\x0d/Root 1 0 R \x0d\x0d>>\x0d%%EOF\x0d\x0a" fdf+= "trailer\x0d<<\x0d/Root 1 0 R \x0d\x0d>>\x0d%%EOF\x0d\x0a"
return fdf return fdf
...@@ -182,8 +182,8 @@ manage_addPDFForm = DTMLFile("dtml/PDFForm_add", globals()) ...@@ -182,8 +182,8 @@ manage_addPDFForm = DTMLFile("dtml/PDFForm_add", globals())
def addPDFForm(self, id, title="", pdf_file=None, REQUEST=None): def addPDFForm(self, id, title="", pdf_file=None, REQUEST=None):
""" Add a pdf form to folder. """ """ Add a pdf form to folder. """
# add actual object # add actual object
id = self._setObject(id, PDFForm(id, title, pdf_file)) id = self._setObject(id, PDFForm(id, title, pdf_file))
# upload content # upload content
if pdf_file: if pdf_file:
self._getOb(id).manage_upload(pdf_file) self._getOb(id).manage_upload(pdf_file)
...@@ -195,16 +195,16 @@ def addPDFForm(self, id, title="", pdf_file=None, REQUEST=None): ...@@ -195,16 +195,16 @@ def addPDFForm(self, id, title="", pdf_file=None, REQUEST=None):
u = "%s/%s" % (u, quote(id)) u = "%s/%s" % (u, quote(id))
REQUEST.RESPONSE.redirect(u+'/manage_main') REQUEST.RESPONSE.redirect(u+'/manage_main')
class CalculatedValues : class CalculatedValues :
""" """
This class holds a reference to calculated values, for use in TALES, This class holds a reference to calculated values, for use in TALES,
because in PDF Form filling, there is lots of references to others cell because in PDF Form filling, there is lots of references to others cell
values (sums ...). This class will be in TALES context under the key 'cell' values (sums ...). This class will be in TALES context under the key 'cell'
It will make possible the use of TALES expressions like : It will make possible the use of TALES expressions like :
cell/a95 cell/a95
python: cell['a1'] + cell['a2'] python: cell['a1'] + cell['a2']
""" """
security = ClassSecurityInfo() security = ClassSecurityInfo()
def __init__(self, values, key, not_founds) : def __init__(self, values, key, not_founds) :
...@@ -213,11 +213,11 @@ class CalculatedValues : ...@@ -213,11 +213,11 @@ class CalculatedValues :
'not_founds' is the list in which we will put not found values """ 'not_founds' is the list in which we will put not found values """
self.__values = values self.__values = values
self.__key = key self.__key = key
self.__not_founds = not_founds self.__not_founds = not_founds
def __getitem__(self, attr) : def __getitem__(self, attr) :
if not self.__values.has_key(attr) : if not self.__values.has_key(attr) :
self.__not_founds.append(attr) self.__not_founds.append(attr)
return 0 # We do not return None, so that cell['a1'] + cell['a2'] return 0 # We do not return None, so that cell['a1'] + cell['a2']
# doesn't complain that NoneType doesn't support + when a1 not found # doesn't complain that NoneType doesn't support + when a1 not found
return self.__values[attr] return self.__values[attr]
__getattr__ = __getitem__ __getattr__ = __getitem__
...@@ -226,7 +226,7 @@ allow_class(CalculatedValues) ...@@ -226,7 +226,7 @@ allow_class(CalculatedValues)
class PDFForm(File): class PDFForm(File):
""" """
This class allows to fill PDF Form with TALES expressions, This class allows to fill PDF Form with TALES expressions,
using a TALES expression for each cell. using a TALES expression for each cell.
""" """
meta_type = "ERP5 PDF Form" meta_type = "ERP5 PDF Form"
...@@ -239,54 +239,54 @@ class PDFForm(File): ...@@ -239,54 +239,54 @@ class PDFForm(File):
property_sheets = ( PropertySheet.Base property_sheets = ( PropertySheet.Base
, PropertySheet.SimpleItem , PropertySheet.SimpleItem
) )
# Constructors # Constructors
constructors = (manage_addPDFForm, addPDFForm) constructors = (manage_addPDFForm, addPDFForm)
manage_options = ( manage_options = (
( (
{'label':'Edit Cell TALES', 'action':'manage_cells'}, {'label':'Edit Cell TALES', 'action':'manage_cells'},
{'label':'Display Cell Names', 'action':'showCellNames'}, {'label':'Display Cell Names', 'action':'showCellNames'},
{'label':'Test PDF generation', 'action':'generatePDF'}, {'label':'Test PDF generation', 'action':'generatePDF'},
{'label':'View original', 'action':'viewOriginal'}, {'label':'View original', 'action':'viewOriginal'},
) + ) +
filter(lambda option:option['label'] != "View", File.manage_options) filter(lambda option:option['label'] != "View", File.manage_options)
) )
pdftk = PDFTk() pdftk = PDFTk()
def __init__ (self, id, title, pdf_file) : def __init__ (self, id, title, pdf_file) :
# holds all the cell informations, even those not related to this form # holds all the cell informations, even those not related to this form
self.all_cells = PersistentMapping() self.all_cells = PersistentMapping()
# holds the cells related to this pdf form # holds the cells related to this pdf form
self.cells = PersistentMapping() self.cells = PersistentMapping()
# the page range we want to print # the page range we want to print
self.__page_range__ = "" self.__page_range__ = ""
# the method to format values # the method to format values
self.__format_method__ = "" self.__format_method__ = ""
if not pdf_file : if not pdf_file :
raise ValueError ("The pdf form file should not be empty") raise ValueError ("The pdf form file should not be empty")
# File constructor will call manage_upload, so we don't need to call it # File constructor will call manage_upload, so we don't need to call it
File.__init__(self, id, title, pdf_file) File.__init__(self, id, title, pdf_file)
security.declareProtected('Change Images and Files', 'manage_upload') security.declareProtected('Change Images and Files', 'manage_upload')
def manage_upload(self, file=None, REQUEST=None) : def manage_upload(self, file=None, REQUEST=None) :
""" Zope calls this when the content of the enclosed file changes. """ Zope calls this when the content of the enclosed file changes.
The 'cells' attribute is updated, but already defined cells are not The 'cells' attribute is updated, but already defined cells are not
erased, they are saved in the 'all_cells' attribute so if the pdf erased, they are saved in the 'all_cells' attribute so if the pdf
file is reverted, you do not loose the cells definitions. file is reverted, you do not loose the cells definitions.
""" """
if not file or not hasattr(file, "read") : if not file or not hasattr(file, "read") :
raise ValueError ("The pdf form file should not be empty") raise ValueError ("The pdf form file should not be empty")
file.seek(0) # file is always valid here file.seek(0) # file is always valid here
values = self.pdftk.dumpDataFields(file) values = self.pdftk.dumpDataFields(file)
for v in values : for v in values :
if v["FieldType"] != "Button" : if v["FieldType"] != "Button" :
k = v["FieldName"] k = v["FieldName"]
if not self.all_cells.has_key(k) : if not self.all_cells.has_key(k) :
self.cells[k] = "" self.cells[k] = ""
else : else :
self.cells[k] = self.all_cells[k] self.cells[k] = self.all_cells[k]
self.all_cells.update(self.cells) self.all_cells.update(self.cells)
...@@ -297,91 +297,91 @@ class PDFForm(File): ...@@ -297,91 +297,91 @@ class PDFForm(File):
return self.manage_main(self,REQUEST,manage_tabs_message=message) return self.manage_main(self,REQUEST,manage_tabs_message=message)
security.declareProtected('View management screens', 'manage_cells') security.declareProtected('View management screens', 'manage_cells')
manage_cells = PageTemplateFile('www/PDFForm_manageCells', manage_cells = PageTemplateFile('www/PDFForm_manageCells',
globals(), __name__='manage_cells') globals(), __name__='manage_cells')
security.declareProtected('View', 'viewOriginal') security.declareProtected('View', 'viewOriginal')
def viewOriginal(self, REQUEST=None, RESPONSE=None, *args, **kwargs) : def viewOriginal(self, REQUEST=None, RESPONSE=None, *args, **kwargs) :
""" publish original pdf """ """ publish original pdf """
pdf = File.index_html(self, REQUEST, RESPONSE, *args, **kwargs) pdf = File.index_html(self, REQUEST, RESPONSE, *args, **kwargs)
RESPONSE.setHeader('Content-Type','application/pdf') RESPONSE.setHeader('Content-Type','application/pdf')
RESPONSE.setHeader('Content-Disposition','inline;filename="%s.pdf"' RESPONSE.setHeader('Content-Disposition','inline;filename="%s.pdf"'
% (self.title_or_id())) % (self.title_or_id()))
return pdf return pdf
security.declareProtected('View', 'showCellNames') security.declareProtected('View', 'showCellNames')
def showCellNames(self, REQUEST=None, RESPONSE=None, *args, **kwargs) : def showCellNames(self, REQUEST=None, RESPONSE=None, *args, **kwargs) :
""" generates a pdf with fields filled-in by their names, """ generates a pdf with fields filled-in by their names,
usefull to fill in settings. usefull to fill in settings.
""" """
values = {} values = {}
for cell in self.cells.keys() : for cell in self.cells.keys() :
values[cell] = cell values[cell] = cell
pdf = self.pdftk.fillFormWithDict(str(self.data), values) pdf = self.pdftk.fillFormWithDict(str(self.data), values)
if RESPONSE : if RESPONSE :
RESPONSE.setHeader('Content-Type','application/pdf') RESPONSE.setHeader('Content-Type','application/pdf')
RESPONSE.setHeader('Content-Length',len(pdf)) RESPONSE.setHeader('Content-Length',len(pdf))
RESPONSE.setHeader('Content-Disposition', RESPONSE.setHeader('Content-Disposition',
'inline;filename="%s.template.pdf"'%( 'inline;filename="%s.template.pdf"'%(
self.title_or_id())) self.title_or_id()))
return pdf return pdf
security.declareProtected('Change Images and Files', 'doEditCells') security.declareProtected('Change Images and Files', 'doEditCells')
def doEditCells(self, REQUEST): def doEditCells(self, REQUEST):
""" This is the action to the 'Edit Cell TALES' tab. """ """ This is the action to the 'Edit Cell TALES' tab. """
if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked(): if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked():
raise ResourceLockedError, "File is locked via WebDAV" raise ResourceLockedError, "File is locked via WebDAV"
for k, v in self.cells.items() : for k, v in self.cells.items() :
self.setCellTALES(k, REQUEST.get(str(k), v)) self.setCellTALES(k, REQUEST.get(str(k), v))
self.__format_method__ = REQUEST.get("__format_method__") self.__format_method__ = REQUEST.get("__format_method__")
self.__page_range__ = REQUEST.get("__page_range__") self.__page_range__ = REQUEST.get("__page_range__")
message = "Saved changes." message = "Saved changes."
if getattr(self, '_v_warnings', None): if getattr(self, '_v_warnings', None):
message = ("<strong>Warning:</strong> <i>%s</i>" message = ("<strong>Warning:</strong> <i>%s</i>"
% '<br>'.join(self._v_warnings)) % '<br>'.join(self._v_warnings))
return self.manage_cells(manage_tabs_message=message) return self.manage_cells(manage_tabs_message=message)
security.declareProtected('View', 'generatePDF') security.declareProtected('View', 'generatePDF')
def generatePDF(self, REQUEST=None, RESPONSE=None, *args, **kwargs) : def generatePDF(self, REQUEST=None, RESPONSE=None, *args, **kwargs) :
""" generates the PDF with form filled in """ """ generates the PDF with form filled in """
values = self.calculateCellValues(REQUEST, *args, **kwargs) values = self.calculateCellValues(REQUEST, *args, **kwargs)
context = {'here' : self, 'request' : REQUEST} context = {'here' : self, 'request' : REQUEST}
if hasattr(self, "__format_method__") and self.__format_method__ not in ('', None) : if hasattr(self, "__format_method__") and self.__format_method__ not in ('', None) :
compiled_tales = getEngine().compile(self.__format_method__) compiled_tales = getEngine().compile(self.__format_method__)
format_method = getEngine().getContext(context).evaluate(compiled_tales) format_method = getEngine().getContext(context).evaluate(compiled_tales)
# try to support both method name and method object # try to support both method name and method object
if not callable(format_method) : if not callable(format_method) :
format_method = self.restrictedTraverse(format_method) format_method = self.restrictedTraverse(format_method)
if callable(format_method) : if callable(format_method) :
for k, v in values.items() : for k, v in values.items() :
values[k] = format_method(v, cell_name=k) values[k] = format_method(v, cell_name=k)
else : else :
LOG("PDFForm", 0, 'format method ("%r") is not callable' % format_method) LOG("PDFForm", 0, 'format method ("%r") is not callable' % format_method)
data = str(self.data) data = str(self.data)
if self.__page_range__ not in ('', None) : if self.__page_range__ not in ('', None) :
compiled_tales = getEngine().compile(self.__page_range__) compiled_tales = getEngine().compile(self.__page_range__)
page_range = getEngine().getContext(context).evaluate(compiled_tales) page_range = getEngine().getContext(context).evaluate(compiled_tales)
if page_range : if page_range :
data = self.pdftk.catPages(str(self.data), page_range) data = self.pdftk.catPages(str(self.data), page_range)
pdf = self.pdftk.fillFormWithDict(data, values) pdf = self.pdftk.fillFormWithDict(data, values)
if RESPONSE : if RESPONSE :
RESPONSE.setHeader('Content-Type','application/pdf') RESPONSE.setHeader('Content-Type','application/pdf')
RESPONSE.setHeader('Content-Length',len(pdf)) RESPONSE.setHeader('Content-Length',len(pdf))
RESPONSE.setHeader('Content-Disposition','inline;filename="%s.pdf"' RESPONSE.setHeader('Content-Disposition','inline;filename="%s.pdf"'
% (self.title_or_id())) % (self.title_or_id()))
return pdf return pdf
index_html = generatePDF index_html = generatePDF
__call__ = generatePDF __call__ = generatePDF
security.declareProtected('View', 'calculateCellValues') security.declareProtected('View', 'calculateCellValues')
def calculateCellValues(self, REQUEST=None, *args, **kwargs) : def calculateCellValues(self, REQUEST=None, *args, **kwargs) :
""" returns a dict of cell values """ """ returns a dict of cell values """
# values to be returned # values to be returned
values = {} values = {}
# list of values that need to be reevaluated (i.e. they depend on the # list of values that need to be reevaluated (i.e. they depend on the
# value of a cell that was not already evaluated when evaluating them ) # value of a cell that was not already evaluated when evaluating them )
uncalculated_values = [] uncalculated_values = []
for cell_name in self.cells.keys() : for cell_name in self.cells.keys() :
...@@ -397,9 +397,9 @@ class PDFForm(File): ...@@ -397,9 +397,9 @@ class PDFForm(File):
# to evaluate them again, if an iteration doesn't decrement # to evaluate them again, if an iteration doesn't decrement
# the length of this list, there are some circular references # the length of this list, there are some circular references
# and we cannot continue. # and we cannot continue.
while 1 : while 1 :
uncalculated_values_len = len(uncalculated_values) uncalculated_values_len = len(uncalculated_values)
if uncalculated_values_len == 0 : if uncalculated_values_len == 0 :
return values return values
for cell_name in uncalculated_values : for cell_name in uncalculated_values :
not_founds = [] not_founds = []
...@@ -413,16 +413,16 @@ class PDFForm(File): ...@@ -413,16 +413,16 @@ class PDFForm(File):
raise "Circular reference", "unable to evaluate cells " \ raise "Circular reference", "unable to evaluate cells " \
+ `uncalculated_values` + `uncalculated_values`
security.declareProtected('View', 'getCellNames') security.declareProtected('View', 'getCellNames')
def getCellNames(self, REQUEST=None) : def getCellNames(self, REQUEST=None) :
""" returns a list of cell names """ """ returns a list of cell names """
names = self.cells.keys() names = self.cells.keys()
names.sort() names.sort()
return names return names
security.declareProtected('Change Images and Files', 'setCellTALES') security.declareProtected('Change Images and Files', 'setCellTALES')
def setCellTALES(self, cell_name, TALES): def setCellTALES(self, cell_name, TALES):
""" changes the TALES expression that will be used to evaluate """ changes the TALES expression that will be used to evaluate
cell value """ cell value """
if type(TALES) != types.StringType : if type(TALES) != types.StringType :
LOG("PDFForm", 100, LOG("PDFForm", 100,
...@@ -430,13 +430,13 @@ class PDFForm(File): ...@@ -430,13 +430,13 @@ class PDFForm(File):
%(cell_name, `TALES`)) %(cell_name, `TALES`))
raise ValueError, 'TALES must be a string' raise ValueError, 'TALES must be a string'
self.all_cells[str(cell_name)] = self.cells[str(cell_name)] = TALES self.all_cells[str(cell_name)] = self.cells[str(cell_name)] = TALES
security.declareProtected('View', 'getCellTALES') security.declareProtected('View', 'getCellTALES')
def getCellTALES(self, cell_name): def getCellTALES(self, cell_name):
""" returns the TALES expression associated with this cell """ """ returns the TALES expression associated with this cell """
return self.cells[str(cell_name)] return self.cells[str(cell_name)]
security.declareProtected('View', 'evaluateCell') security.declareProtected('View', 'evaluateCell')
def evaluateCell(self, cell_name, REQUEST=None, **kwargs): def evaluateCell(self, cell_name, REQUEST=None, **kwargs):
""" evaluate the TALES expression for this cell """ """ evaluate the TALES expression for this cell """
cell_name = str(cell_name) cell_name = str(cell_name)
...@@ -444,17 +444,17 @@ class PDFForm(File): ...@@ -444,17 +444,17 @@ class PDFForm(File):
# (and this also raises the KeyError for non existant cells) # (and this also raises the KeyError for non existant cells)
if not self.cells[cell_name] : if not self.cells[cell_name] :
return None return None
context = {'here' : self, 'request' : REQUEST} context = {'here' : self, 'request' : REQUEST}
context.update (kwargs) context.update (kwargs)
compiled_tales = getEngine().compile(self.cells[cell_name]) compiled_tales = getEngine().compile(self.cells[cell_name])
value = getEngine().getContext(context).evaluate(compiled_tales) value = getEngine().getContext(context).evaluate(compiled_tales)
return value return value
security.declareProtected('Change Images and Files', 'setAllCellTALES') security.declareProtected('Change Images and Files', 'setAllCellTALES')
def setAllCellTALES(self, new_cells) : def setAllCellTALES(self, new_cells) :
""" set all cell values from a dict containing { name: TALES } """ """ set all cell values from a dict containing { name: TALES } """
for cell_name, cell_TALES in new_cells.items() : for cell_name, cell_TALES in new_cells.items() :
self.setCellTALES(cell_name, cell_TALES) self.setCellTALES(cell_name, cell_TALES)
security.declareProtected('View', 'getFormatMethodTALES') security.declareProtected('View', 'getFormatMethodTALES')
...@@ -462,23 +462,23 @@ class PDFForm(File): ...@@ -462,23 +462,23 @@ class PDFForm(File):
""" returns the TALES expression for the format method attribute """ """ returns the TALES expression for the format method attribute """
# backward compat # backward compat
if not hasattr(self, "__format_method__") : if not hasattr(self, "__format_method__") :
self.__format_method__ = "" self.__format_method__ = ""
return self.__format_method__ return self.__format_method__
security.declareProtected('Change Images and Files', 'setFormatMethodTALES') security.declareProtected('Change Images and Files', 'setFormatMethodTALES')
def setFormatMethodTALES(self, TALES): def setFormatMethodTALES(self, TALES):
""" sets TALES expression for the format method attribute """ """ sets TALES expression for the format method attribute """
self.__format_method__ = str(TALES) self.__format_method__ = str(TALES)
security.declareProtected('View', 'getPageRangeTALES') security.declareProtected('View', 'getPageRangeTALES')
def getPageRangeTALES(self): def getPageRangeTALES(self):
""" returns the TALES expression for the page range attribute """ """ returns the TALES expression for the page range attribute """
return self.__page_range__ return self.__page_range__
security.declareProtected('Change Images and Files', 'setPageRangeTALES') security.declareProtected('Change Images and Files', 'setPageRangeTALES')
def setPageRangeTALES(self, TALES): def setPageRangeTALES(self, TALES):
""" sets TALES expression for the page range attribute """ """ sets TALES expression for the page range attribute """
self.__page_range__ = str(TALES) self.__page_range__ = str(TALES)
InitializeClass(PDFForm) InitializeClass(PDFForm)
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