From 9258b76bdf51a4cf6e6eb5c3707e3d09ca1b2c1f Mon Sep 17 00:00:00 2001
From: Gaetan Delannay
Date: Sun, 11 Sep 2011 01:59:22 +0200
Subject: [PATCH] appy.gen: do not generate _action_ok and action_ko i18n
messages anymore; added param Group.label, similar to Type.label; allowed to
specify in param Group.wide any table width.
---
gen/__init__.py | 16 ++++++++++++----
gen/plone25/descriptors.py | 11 ++---------
gen/plone25/generator.py | 2 ++
gen/plone25/mixins/__init__.py | 29 +++++++++--------------------
gen/plone25/skin/widgets/ref.pt | 4 ++--
gen/plone25/skin/widgets/show.pt | 10 +++++-----
gen/utils.py | 9 ++++++++-
7 files changed, 40 insertions(+), 41 deletions(-)
diff --git a/gen/__init__.py b/gen/__init__.py
index 7a6c7ac..55a5a02 100644
--- a/gen/__init__.py
+++ b/gen/__init__.py
@@ -95,7 +95,7 @@ class Group:
hasLabel=True, hasDescr=False, hasHelp=False,
hasHeaders=False, group=None, colspan=1, align='center',
valign='top', css_class='', master=None, masterValue=None,
- cellpadding=1, cellspacing=1, cellgap='0.6em'):
+ cellpadding=1, cellspacing=1, cellgap='0.6em', label=None):
self.name = name
# In its simpler form, field "columns" below can hold a list or tuple
# of column widths expressed as strings, that will be given as is in
@@ -105,8 +105,14 @@ class Group:
self.columns = columns
self._setColumns()
# If field "wide" below is True, the HTML table corresponding to this
- # group will have width 100%.
- self.wide = wide
+ # group will have width 100%. You can also specify some string value,
+ # which will be used for HTML param "width".
+ if wide == True:
+ self.wide = '100%'
+ elif isinstance(wide, basestring):
+ self.wide = wide
+ else:
+ self.wide = ''
# If style = 'fieldset', all widgets within the group will be rendered
# within an HTML fieldset. If style is 'section1' or 'section2', widgets
# will be rendered after the group title.
@@ -151,6 +157,7 @@ class Group:
self.masterValue = None
if master:
self._addMaster(master, masterValue)
+ self.label = label # See similar attr of Type class.
def _addMaster(self, master, masterValue):
'''Specifies this group being a slave of another field: we will add css
@@ -236,7 +243,8 @@ class Group:
messages.append(poMsg)
classDescr.labelsToPropagate.append(poMsg)
walkedGroups.add(self)
- if self.group and (self.group not in walkedGroups):
+ if self.group and (self.group not in walkedGroups) and \
+ not self.group.label:
# We remember walked groups for avoiding infinite recursion.
self.group.generateLabels(messages, classDescr, walkedGroups)
diff --git a/gen/plone25/descriptors.py b/gen/plone25/descriptors.py
index d79eaf8..764b362 100644
--- a/gen/plone25/descriptors.py
+++ b/gen/plone25/descriptors.py
@@ -87,14 +87,7 @@ class FieldDescriptor:
self.generator.labels.append(poMsg)
def walkAction(self):
- '''Generates the i18n-related labels.'''
- for suffix in ('ok', 'ko'):
- label = '%s_%s_action_%s' % (self.classDescr.name, self.fieldName,
- suffix)
- msg = PoMessage(label, '',
- getattr(PoMessage, 'ACTION_%s' % suffix.upper()))
- self.generator.labels.append(msg)
- self.classDescr.labelsToPropagate.append(msg)
+ '''Generates the i18n-related label.'''
if self.appyType.confirm:
label = '%s_%s_confirm' % (self.classDescr.name, self.fieldName)
msg = PoMessage(label, '', PoMessage.CONFIRM)
@@ -178,7 +171,7 @@ class FieldDescriptor:
self.classDescr.labelsToPropagate.append(poMsg)
# Create i18n messages linked to groups
group = self.appyType.group
- if group:
+ if group and not group.label:
group.generateLabels(messages, self.classDescr, set())
# Manage things which are specific to String types
if self.appyType.type == 'String': self.walkString()
diff --git a/gen/plone25/generator.py b/gen/plone25/generator.py
index 96c62e0..1dc4de3 100644
--- a/gen/plone25/generator.py
+++ b/gen/plone25/generator.py
@@ -101,6 +101,8 @@ class Generator(AbstractGenerator):
msg('no_ref', '', msg.REF_NO),
msg('add_ref', '', msg.REF_ADD),
msg('ref_actions', '', msg.REF_ACTIONS),
+ msg('action_ok', '', msg.ACTION_OK),
+ msg('action_ko', '', msg.ACTION_KO),
msg('move_up', '', msg.REF_MOVE_UP),
msg('move_down', '', msg.REF_MOVE_DOWN),
msg('query_create', '', msg.QUERY_CREATE),
diff --git a/gen/plone25/mixins/__init__.py b/gen/plone25/mixins/__init__.py
index 49cbfdc..3d923f1 100644
--- a/gen/plone25/mixins/__init__.py
+++ b/gen/plone25/mixins/__init__.py
@@ -908,11 +908,8 @@ class BaseMixin:
if not msg:
# Use the default i18n messages
suffix = 'ko'
- if successfull:
- suffix = 'ok'
- appyType = self.getAppyType(rq['fieldName'])
- label = '%s_action_%s' % (appyType.labelId, suffix)
- msg = self.translate(label)
+ if successfull: suffix = 'ok'
+ msg = self.translate('action_%s' % suffix)
if (resultType == 'computation') or not successfull:
self.say(msg)
return self.goto(self.getUrl(rq['HTTP_REFERER']))
@@ -1191,15 +1188,14 @@ class BaseMixin:
return res
def translate(self, label, mapping={}, domain=None, default=None,
- language=None, format='html', field=None, className=None):
+ language=None, format='html', field=None):
'''Translates a given p_label into p_domain with p_mapping.
If p_field is given, p_label does not correspond to a full label
name, but to a label type linked to p_field: "label", "descr"
or "help". Indeed, in this case, a specific i18n mapping may be
available on the field, so we must merge this mapping into
- p_mapping. If p_className is not given, we consider p_self being an
- instance of the class where p_field is defined.'''
+ p_mapping.'''
cfg = self.getProductConfig()
if not domain: domain = cfg.PROJECTNAME
if domain != cfg.PROJECTNAME:
@@ -1215,22 +1211,15 @@ class BaseMixin:
else:
# Get the label name, and the field-specific mapping if any.
if field:
- # Maybe we do not have the field itself, but only its name
- if isinstance(field, basestring):
- appyField = self.getAppyType(field, className=className)
- else:
- appyField = field
- if appyField:
- fieldMapping = appyField.mapping[label]
+ # p_field is the dict version of a appy type or group
+ if field['type'] != 'group':
+ fieldMapping = field['mapping'][label]
if fieldMapping:
if callable(fieldMapping):
+ appyField = self.getAppyType(field['name'])
fieldMapping=appyField.callMethod(self,fieldMapping)
mapping.update(fieldMapping)
- # Get the label
- label = getattr(appyField, label+'Id')
- else:
- # It must be a group.
- label = '%s_group_%s_%s' % (self.meta_type, field, label)
+ label = field['%sId' % label]
# We will get the translation from a Translation object.
# In what language must we get the translation?
if not language: language = self.getUserLanguage()
diff --git a/gen/plone25/skin/widgets/ref.pt b/gen/plone25/skin/widgets/ref.pt
index 4fa7b5f..777d82b 100644
--- a/gen/plone25/skin/widgets/ref.pt
+++ b/gen/plone25/skin/widgets/ref.pt
@@ -120,7 +120,7 @@
maxReached python:(multiplicity[1] != None) and (len(objs) >= multiplicity[1]);
showPlusIcon python:not appyType['isBack'] and appyType['add'] and not maxReached and member.has_permission(addPermission, folder) and canWrite;
atMostOneRef python: (multiplicity[1] == 1) and (len(objs)<=1);
- label python: contextObj.translate('label', field=appyType['name']);
+ label python: contextObj.translate('label', field=appyType);
addConfirmMsg python: appyType['addConfirm'] and tool.translate('%s_addConfirm' % appyType['labelId']) or '';
navBaseCall python: 'askRefField(\'%s\',\'%s\',\'%s\',\'%s\',**v**)' % (ajaxHookId, contextObj.absolute_url(), fieldName, innerRef)">
@@ -167,7 +167,7 @@
Object description
+ tal:content="python: contextObj.translate('descr', field=appyType)">
Displays a field label.
-
+Displays a field description.
-
+Displays a field help.
-
+Displays validation-error-related info about a field.
diff --git a/gen/utils.py b/gen/utils.py
index 62fd2ee..63d7884 100644
--- a/gen/utils.py
+++ b/gen/utils.py
@@ -21,7 +21,14 @@ class GroupDescr(Descr):
self.columnsWidths = [col.width for col in group.columns]
self.columnsAligns = [col.align for col in group.columns]
# Names of i18n labels
- self.labelId = '%s_group_%s' % (metaType, self.name)
+ labelName = self.name
+ prefix = metaType
+ if group.label:
+ if isinstance(group.label, basestring): prefix = group.label
+ else: # It is a tuple (metaType, name)
+ if group.label[1]: labelName = group.label[1]
+ if group.label[0]: prefix = group.label[0]
+ self.labelId = '%s_group_%s' % (prefix, labelName)
self.descrId = self.labelId + '_descr'
self.helpId = self.labelId + '_help'
# The name of the page where the group lies