Commit f83c4fec authored by Thibaut Deheunynck's avatar Thibaut Deheunynck

modify Tales expression when the field is a date. The Tales expression respect the date format

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21591 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 21a93aac
...@@ -341,7 +341,8 @@ def ERP5Site_createModuleScribus(self, ...@@ -341,7 +341,8 @@ def ERP5Site_createModuleScribus(self,
skin_folder, skin_folder,
object_names, object_names,
object_title, object_title,
pdf_file=import_pdf_file import_pdf_file,
global_properties
) )
LOG('ERP5Site_createModuleScribus', INFO, LOG('ERP5Site_createModuleScribus', INFO,
'createmodule < PDF settings managed') 'createmodule < PDF settings managed')
......
...@@ -373,7 +373,8 @@ def ERP5Site_updateModuleScribus(self, ...@@ -373,7 +373,8 @@ def ERP5Site_updateModuleScribus(self,
skin_folder, skin_folder,
object_names, object_names,
object_title, object_title,
pdf_file=import_pdf_file import_pdf_file,
global_properties
) )
LOG('ERP5Site_updateModuleScribus', INFO, LOG('ERP5Site_updateModuleScribus', INFO,
'createmodule < PDF settings managed') 'createmodule < PDF settings managed')
......
...@@ -44,6 +44,8 @@ from urllib import quote ...@@ -44,6 +44,8 @@ from urllib import quote
from Products.ERP5.ERP5Site import ERP5Site from Products.ERP5.ERP5Site import ERP5Site
from Products.Formulator.TALESField import TALESMethod from Products.Formulator.TALESField import TALESMethod
from Products.Formulator.MethodField import Method from Products.Formulator.MethodField import Method
from Products.ERP5Type.Utils import convertToUpperCase
# defining global variables # defining global variables
# ANFLAG tag # ANFLAG tag
# these values can be found in the Scribus document format # these values can be found in the Scribus document format
...@@ -518,12 +520,14 @@ class ManageFiles: ...@@ -518,12 +520,14 @@ class ManageFiles:
skin_folder, skin_folder,
object_names, object_names,
object_title, object_title,
pdf_file pdf_file,
global_properties
): ):
""" """
imports PDF file as a PDFForm in ERP5 and updates its TALES imports PDF file as a PDFForm in ERP5 and updates its TALES
expressions expressions
""" """
my_prefix = 'my_'
pdf_file.seek(0) pdf_file.seek(0)
factory.addPDFForm(object_names['view_pdf'], object_title, pdf_file) factory.addPDFForm(object_names['view_pdf'], object_title, pdf_file)
# iterating objects in skin_folder # iterating objects in skin_folder
...@@ -531,31 +535,60 @@ class ManageFiles: ...@@ -531,31 +535,60 @@ class ManageFiles:
if c.getId() == object_names['view_pdf']: if c.getId() == object_names['view_pdf']:
# current object is PDF Form # current object is PDF Form
cell_name_list = c.getCellNames() cell_name_list = c.getCellNames()
for cell_name in cell_name_list: for cell_name in global_properties['object'].keys():
if cell_name[0:3] == 'my_': if cell_name[:len(my_prefix)] == my_prefix:
cell_process_name_list = [] cell_process_name_list = []
for word in cell_name[3:].split('_'): suffix = cell_name[len(my_prefix):].split('_')[-1]
word = word.capitalize() # If properties field are filled in scribus, get Type form
cell_process_name_list.append(word) # global_properties. Else, guess Type by suffix id (eg: List, Date,...)
if def_usePropertySheet == 1: list_field_type_list = ('ListField', 'MultiListField', 'LinesField',)
date_field_type_list = ('DateTimeField',)
suffix_mapping = {'List' : list_field_type_list,
'Date' : date_field_type_list}
field_dict = global_properties['object'][cell_name]
field_type = field_dict.get('erp_type', suffix_mapping.get(suffix, [''])[0])
if def_usePropertySheet:
# generating PropertySheet and Document, no need to use them to # generating PropertySheet and Document, no need to use them to
# get field data # get field data
if cell_process_name_list[-1] == 'List': if field_type in list_field_type_list:
TALES = "python: " + ", ".join( TALES = "python: %s " % ', '.join(
"here.get" + "".join(cell_process_name_list) + "()" ) "here.get%s()" % convertToUpperCase(cell_name[len(my_prefix):]))
elif field_type in date_field_type_list:
attributes_dict = field_dict['attributes']
# assign the property input_order
input_order = attributes_dict['input_order']
input_order = input_order.replace('y', 'Y')
# make the Tales according to the cases
date_pattern = '/'.join(['%%%s' % s for s in list(input_order)])
if not(attributes_dict['date_only']):
date_pattern += ' %H:%M'
TALES = "python: here.get%s() is not None and here.get%s().strftime('%s') or ''"\
% (convertToUpperCase(cell_name[len(my_prefix):]),
convertToUpperCase(cell_name[len(my_prefix):]),
date_pattern)
else: else:
TALES = "python: here.get" + "".join( TALES = "python: here.get%s()" %\
cell_process_name_list) + "()" convertToUpperCase(cell_name[len(my_prefix):])
else: else:
# PropertySheet and Document if field_type in list_field_type_list:
if cell_process_name_list[-1] == 'List': TALES = "python: %s" % ', '.join(
TALES = "python: " + ", ".join( "here.getProperty('%s')" % cell_name[len(my_prefix):])
"here.getProperty('" + cell_name[3:] + "')") elif field_type in date_field_type_list:
attributes_dict = field_dict['attributes']
# assign the property input_order
input_order = attributes_dict['input_order']
input_order = input_order.replace('y', 'Y')
# make the Tales according to the cases
date_pattern = '/'.join(['%%%s' % s for s in list(input_order)])
if not(attributes_dict['date_only']):
date_pattern += ' %H:%M'
TALES = "python: here.getProperty('%s') is not None and here.getProperty('%s').strftime('%s') or ''"\
% (cell_name[len(my_prefix):],
cell_name[len(my_prefix):],
date_pattern)
else: else:
TALES = "python: here.getProperty('" + cell_name[3:] +"')" TALES = "python: here.getProperty('%s')" % cell_name[len(my_prefix):]
LOG('ManageFiles', INFO, ' %s > %s ' % (cell_name, TALES)) LOG('ManageFiles', INFO, ' %s > %s ' % (cell_name, TALES))
c.setCellTALES(cell_name, TALES) c.setCellTALES(cell_name, TALES)
......
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