Commit 389479a0 authored by Romain Courteaud's avatar Romain Courteaud

Allow to:

 - explicitely define the skin folder in the proxy field's form ID field.
 - surcharge a field library for a custom project by only putting inside
   the modified fields. Untouched field can be left inside standard
   field library.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30848 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 848f91b8
......@@ -54,6 +54,9 @@ from Products.Formulator.TALESField import TALESMethod
from Products.ERP5Form.Form import StaticValue, TALESValue, OverrideValue, DefaultValue, EditableValue
from Products.ERP5Form.Form import copyMethod, isCacheable
from Products.CMFCore.Skinnable import SKINDATA
from thread import get_ident
_USE_ORIGINAL_GET_VALUE_MARKER = []
_field_value_cache = {}
......@@ -423,15 +426,54 @@ class ProxyField(ZMIField):
form = self.aq_parent
object = form.aq_parent
try:
proxy_form = getattr(object, self.get_value('form_id'))
proxy_field = aq_base(getattr(proxy_form, self.get_value('field_id')))
form_id = self.get_value('form_id')
proxy_field = None
form_id_with_skin_folder_name_flag = False
if '/' in form_id:
# If a / is in the form_id, it means that skin_folder is explicitly
# defined. If so, prevent acquisition to get the form.
form_id_with_skin_folder_name_flag = True
proxy_form = aq_base(object.portal_skins).unrestrictedTraverse(form_id, None)
else:
proxy_form = getattr(object, form_id, None)
if (proxy_form is not None):
field_id = self.get_value('field_id')
try:
proxy_field = aq_base(getattr(proxy_form, field_id))
except (AttributeError, TypeError):
proxy_field = None
if form_id_with_skin_folder_name_flag is False:
# Try to get the field from another field library with a lower
# priority.
# This should return no field if the skin folder name is defined in
# form_id.
skin_info = SKINDATA.get(get_ident())
if skin_info is not None:
skin_selection_name, ignore, resolve = skin_info
portal_skins = aq_base(self.portal_skins)
selection_dict = portal_skins._getSelections()
candidate_folder_id_list = selection_dict[skin_selection_name].split(',')
for candidate_folder_id in candidate_folder_id_list:
candidate_folder = getattr(portal_skins, candidate_folder_id, None)
if candidate_folder is not None:
proxy_form = getattr(candidate_folder, form_id, None)
if proxy_form is not None:
proxy_field = getattr(proxy_form, field_id, None)
if proxy_field is not None:
break
if proxy_field is not None:
proxy_field = proxy_field.__of__(form)
except (AttributeError, TypeError):
else:
LOG('ProxyField', WARNING,
'Could not get a field from a proxy field %s in %s' % \
(self.id, object.id))
proxy_field = None
if cache is True:
self._setTemplateFieldCache(proxy_field)
return proxy_field
......
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2002-2009 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Testing.ZopeTestCase.PortalTestCase import PortalTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.SecurityTestCase import SecurityTestCase
import transaction
import unittest
class TestProxyField(ERP5TypeTestCase):
"""
Check proxy field
"""
def getTitle(self):
return "TestProxyField"
def changeSkin(self, skin_name):
"""
Change current Skin
"""
request = self.app.REQUEST
self.getPortal().portal_skins.changeSkin(skin_name)
request.set('portal_skin', skin_name)
def testEmptySurchargedFieldLibrary(self):
"""
This test checks that it is not required to duplicate all fields in a custom
field library
"""
portal_skins = self.getSkinsTool()
# Create an empty field library
portal_skins.manage_addProduct['OFSP'].manage_addFolder('customized_geek')
skin_folder = portal_skins._getOb('customized_geek')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
'Base_viewGeekFieldLibrary',
'View')
form = skin_folder._getOb('Base_viewGeekFieldLibrary', None)
# Create the default field library with a template field
portal_skins.manage_addProduct['OFSP'].manage_addFolder('erp5_geek')
skin_folder = portal_skins._getOb('erp5_geek')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
'Base_viewGeekFieldLibrary',
'View')
form = skin_folder._getOb('Base_viewGeekFieldLibrary', None)
form.manage_addField('my_title', 'Generic Title', 'StringField')
# Custom field library has to have an higher priority
selection = portal_skins.getSkinPath('View')
selection = selection.split(',')
selection.append('customized_geek')
selection.append('erp5_geek')
portal_skins.manage_skinLayers(skinpath=tuple(selection),
skinname='View', add_skin=1)
portal_skins.getPortalObject().changeSkin(None)
skin_folder = portal_skins._getOb('custom')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form('Base_viewGeek',
'View')
form = skin_folder._getOb('Base_viewGeek', None)
form.manage_addField('my_title', 'Title', 'ProxyField')
field = getattr(form, 'my_title')
field.manage_edit_xmlrpc(dict(
form_id='Base_viewGeekFieldLibrary', field_id='my_title'))
self.assertEquals('Generic Title', field.get_value('title'))
def testPathOfTemplateField(self):
"""
This test checks if it is possible to specify the skin folder of a form
"""
portal_skins = self.getSkinsTool()
portal_skins.manage_addProduct['OFSP'].manage_addFolder('customized_geek')
skin_folder = portal_skins._getOb('customized_geek')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
'Base_viewGeekFieldLibrary',
'View')
form = skin_folder._getOb('Base_viewGeekFieldLibrary', None)
form.manage_addField('my_title', 'Customized Title', 'StringField')
portal_skins.manage_addProduct['OFSP'].manage_addFolder('erp5_geek')
skin_folder = portal_skins._getOb('erp5_geek')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
'Base_viewGeekFieldLibrary',
'View')
form = skin_folder._getOb('Base_viewGeekFieldLibrary', None)
form.manage_addField('my_title', 'Generic Title', 'StringField')
# Custom field library has to have an higher priority
selection = portal_skins.getSkinPath('View')
selection = selection.split(',')
selection.append('customized_geek')
selection.append('erp5_geek')
portal_skins.manage_skinLayers(skinpath=tuple(selection),
skinname='View', add_skin=1)
portal_skins.getPortalObject().changeSkin(None)
skin_folder = portal_skins._getOb('custom')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form('Base_viewGeek',
'View')
form = skin_folder._getOb('Base_viewGeek', None)
form.manage_addField('my_title', 'Title', 'ProxyField')
field = getattr(form, 'my_title')
# Explicitely enter skin folder of the template field's form
field.manage_edit_xmlrpc(dict(
form_id='erp5_geek/Base_viewGeekFieldLibrary', field_id='my_title'))
self.assertEquals('Generic Title', field.get_value('title'))
def testSkinSelectionTemplateField(self):
"""
Check that proxy field values are generated from the current skin selection
"""
portal_skins = self.getSkinsTool()
portal_skins.manage_addProduct['OFSP'].manage_addFolder('customized_geek')
skin_folder = portal_skins._getOb('customized_geek')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
'Base_viewGeekFieldLibrary',
'View')
form = skin_folder._getOb('Base_viewGeekFieldLibrary', None)
portal_skins.manage_addProduct['OFSP'].manage_addFolder('erp5_geek')
skin_folder = portal_skins._getOb('erp5_geek')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
'Base_viewGeekFieldLibrary',
'View')
form = skin_folder._getOb('Base_viewGeekFieldLibrary', None)
form.manage_addField('my_title', 'Generic Title', 'StringField')
selection = portal_skins.getSkinPath('View')
selection = selection.split(',')
selection.append('customized_geek')
selection.append('erp5_geek')
portal_skins.addSkinSelection('CustomizedView', ','.join(selection))
selection = portal_skins.getSkinPath('View')
selection = selection.split(',')
selection.append('erp5_geek')
selection.append('customized_geek')
portal_skins.addSkinSelection('GenericView', ','.join(selection))
# XXX KeyError is raised if skin selection View is not modified.
# This part has to be removed has soon as this bug is fixed
selection = portal_skins.getSkinPath('View')
portal_skins.manage_skinLayers(skinpath=tuple(selection),
skinname='View')
portal_skins.getPortalObject().changeSkin(None)
skin_folder = portal_skins._getOb('custom')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form('Base_viewGeek',
'View')
form = skin_folder._getOb('Base_viewGeek', None)
form.manage_addField('my_title', 'Title', 'ProxyField')
field = getattr(form, 'my_title')
field.manage_edit_xmlrpc(dict(
form_id='Base_viewGeekFieldLibrary', field_id='my_title'))
self.assertEquals(None, field.get_value('title'))
self.changeSkin('GenericView')
self.assertEquals('Generic Title', field.get_value('title'))
self.changeSkin('CustomizedView')
self.assertEquals('Customized Title', field.get_value('title'))
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