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.

This commit is contained in:
Gaetan Delannay 2011-09-11 01:59:22 +02:00
parent 5be03c2ed4
commit 9258b76bdf
7 changed files with 40 additions and 41 deletions

View file

@ -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%.
# 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)

View file

@ -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()

View file

@ -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),

View file

@ -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()

View file

@ -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 @@
<tal:comment replace="nothing">Object description</tal:comment>
<p class="discreet" tal:condition="python: not innerRef and appyType['hasDescr']"
tal:content="python: contextObj.translate('descr', field=appyType['name'])"></p>
tal:content="python: contextObj.translate('descr', field=appyType)"></p>
<tal:comment replace="nothing">Appy (top) navigation</tal:comment>
<metal:nav use-macro="here/skyn/navigate/macros/appyNavigate"/>

View file

@ -82,7 +82,7 @@
</tal:asSection>
<tal:asTabs condition="python: widget['style'] == 'tabs'">
<table cellpadding="0" cellspacing="0"
tal:attributes="width python: test(widget['wide'], '100%', '');
tal:attributes="width widget/wide;
class widget/css_class">
<tal:comment replace="nothing">First row: the tabs.</tal:comment>
<tr valign="middle"><td style="border-bottom: 1px solid #ff8040">
@ -130,7 +130,7 @@
</tal:comment>
<table metal:define-macro="groupContent"
tal:define="cellgap widget/cellgap"
tal:attributes="width python: test(widget['wide'], '100%', '');
tal:attributes="width widget/wide;
align widget/align;
class widget/css_class;
cellspacing widget/cellspacing;
@ -175,14 +175,14 @@
</table>
<tal:comment replace="nothing">Displays a field label.</tal:comment>
<tal:label metal:define-macro="label" condition="widget/hasLabel"><label tal:attributes="for widget/name" tal:condition="python: not ((widget['type'] == 'Action') or ((widget['type'] == 'Ref') and (widget['add'])))" tal:content="structure python: contextObj.translate('label', field=widget['name'])"></label></tal:label>
<tal:label metal:define-macro="label" condition="widget/hasLabel"><label tal:attributes="for widget/name" tal:condition="python: not ((widget['type'] == 'Action') or ((widget['type'] == 'Ref') and (widget['add'])))" tal:content="structure python: contextObj.translate('label', field=widget)"></label></tal:label>
<tal:comment replace="nothing">Displays a field description.</tal:comment>
<tal:description metal:define-macro="description" condition="widget/hasDescr"><span class="discreet" tal:content="structure python: contextObj.translate('descr', field=widget['name'])"></span>
<tal:description metal:define-macro="description" condition="widget/hasDescr"><span class="discreet" tal:content="structure python: contextObj.translate('descr', field=widget)"></span>
</tal:description>
<tal:comment replace="nothing">Displays a field help.</tal:comment>
<tal:help metal:define-macro="help"><acronym tal:attributes="title python: contextObj.translate('help', field=widget['name'])"><img tal:attributes="src string: $portal_url/skyn/help.png"/></acronym></tal:help>
<tal:help metal:define-macro="help"><acronym tal:attributes="title python: contextObj.translate('help', field=widget)"><img tal:attributes="src string: $portal_url/skyn/help.png"/></acronym></tal:help>
<tal:comment replace="nothing">Displays validation-error-related info about a field.</tal:comment>
<tal:validation metal:define-macro="validation"><acronym tal:condition="inError" tal:attributes="title python: errors[name]"><img tal:attributes="src string: $portal_url/skyn/warning.png"/></acronym><img tal:condition="not: inError" tal:attributes="src string: $portal_url/skyn/warning_no.gif"/></tal:validation>

View file

@ -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