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:
parent
5be03c2ed4
commit
9258b76bdf
|
@ -95,7 +95,7 @@ class Group:
|
||||||
hasLabel=True, hasDescr=False, hasHelp=False,
|
hasLabel=True, hasDescr=False, hasHelp=False,
|
||||||
hasHeaders=False, group=None, colspan=1, align='center',
|
hasHeaders=False, group=None, colspan=1, align='center',
|
||||||
valign='top', css_class='', master=None, masterValue=None,
|
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
|
self.name = name
|
||||||
# In its simpler form, field "columns" below can hold a list or tuple
|
# 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
|
# of column widths expressed as strings, that will be given as is in
|
||||||
|
@ -105,8 +105,14 @@ class Group:
|
||||||
self.columns = columns
|
self.columns = columns
|
||||||
self._setColumns()
|
self._setColumns()
|
||||||
# If field "wide" below is True, the HTML table corresponding to this
|
# 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
|
self.wide = wide
|
||||||
|
else:
|
||||||
|
self.wide = ''
|
||||||
# If style = 'fieldset', all widgets within the group will be rendered
|
# If style = 'fieldset', all widgets within the group will be rendered
|
||||||
# within an HTML fieldset. If style is 'section1' or 'section2', widgets
|
# within an HTML fieldset. If style is 'section1' or 'section2', widgets
|
||||||
# will be rendered after the group title.
|
# will be rendered after the group title.
|
||||||
|
@ -151,6 +157,7 @@ class Group:
|
||||||
self.masterValue = None
|
self.masterValue = None
|
||||||
if master:
|
if master:
|
||||||
self._addMaster(master, masterValue)
|
self._addMaster(master, masterValue)
|
||||||
|
self.label = label # See similar attr of Type class.
|
||||||
|
|
||||||
def _addMaster(self, master, masterValue):
|
def _addMaster(self, master, masterValue):
|
||||||
'''Specifies this group being a slave of another field: we will add css
|
'''Specifies this group being a slave of another field: we will add css
|
||||||
|
@ -236,7 +243,8 @@ class Group:
|
||||||
messages.append(poMsg)
|
messages.append(poMsg)
|
||||||
classDescr.labelsToPropagate.append(poMsg)
|
classDescr.labelsToPropagate.append(poMsg)
|
||||||
walkedGroups.add(self)
|
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.
|
# We remember walked groups for avoiding infinite recursion.
|
||||||
self.group.generateLabels(messages, classDescr, walkedGroups)
|
self.group.generateLabels(messages, classDescr, walkedGroups)
|
||||||
|
|
||||||
|
|
|
@ -87,14 +87,7 @@ class FieldDescriptor:
|
||||||
self.generator.labels.append(poMsg)
|
self.generator.labels.append(poMsg)
|
||||||
|
|
||||||
def walkAction(self):
|
def walkAction(self):
|
||||||
'''Generates the i18n-related labels.'''
|
'''Generates the i18n-related label.'''
|
||||||
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)
|
|
||||||
if self.appyType.confirm:
|
if self.appyType.confirm:
|
||||||
label = '%s_%s_confirm' % (self.classDescr.name, self.fieldName)
|
label = '%s_%s_confirm' % (self.classDescr.name, self.fieldName)
|
||||||
msg = PoMessage(label, '', PoMessage.CONFIRM)
|
msg = PoMessage(label, '', PoMessage.CONFIRM)
|
||||||
|
@ -178,7 +171,7 @@ class FieldDescriptor:
|
||||||
self.classDescr.labelsToPropagate.append(poMsg)
|
self.classDescr.labelsToPropagate.append(poMsg)
|
||||||
# Create i18n messages linked to groups
|
# Create i18n messages linked to groups
|
||||||
group = self.appyType.group
|
group = self.appyType.group
|
||||||
if group:
|
if group and not group.label:
|
||||||
group.generateLabels(messages, self.classDescr, set())
|
group.generateLabels(messages, self.classDescr, set())
|
||||||
# Manage things which are specific to String types
|
# Manage things which are specific to String types
|
||||||
if self.appyType.type == 'String': self.walkString()
|
if self.appyType.type == 'String': self.walkString()
|
||||||
|
|
|
@ -101,6 +101,8 @@ class Generator(AbstractGenerator):
|
||||||
msg('no_ref', '', msg.REF_NO),
|
msg('no_ref', '', msg.REF_NO),
|
||||||
msg('add_ref', '', msg.REF_ADD),
|
msg('add_ref', '', msg.REF_ADD),
|
||||||
msg('ref_actions', '', msg.REF_ACTIONS),
|
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_up', '', msg.REF_MOVE_UP),
|
||||||
msg('move_down', '', msg.REF_MOVE_DOWN),
|
msg('move_down', '', msg.REF_MOVE_DOWN),
|
||||||
msg('query_create', '', msg.QUERY_CREATE),
|
msg('query_create', '', msg.QUERY_CREATE),
|
||||||
|
|
|
@ -908,11 +908,8 @@ class BaseMixin:
|
||||||
if not msg:
|
if not msg:
|
||||||
# Use the default i18n messages
|
# Use the default i18n messages
|
||||||
suffix = 'ko'
|
suffix = 'ko'
|
||||||
if successfull:
|
if successfull: suffix = 'ok'
|
||||||
suffix = 'ok'
|
msg = self.translate('action_%s' % suffix)
|
||||||
appyType = self.getAppyType(rq['fieldName'])
|
|
||||||
label = '%s_action_%s' % (appyType.labelId, suffix)
|
|
||||||
msg = self.translate(label)
|
|
||||||
if (resultType == 'computation') or not successfull:
|
if (resultType == 'computation') or not successfull:
|
||||||
self.say(msg)
|
self.say(msg)
|
||||||
return self.goto(self.getUrl(rq['HTTP_REFERER']))
|
return self.goto(self.getUrl(rq['HTTP_REFERER']))
|
||||||
|
@ -1191,15 +1188,14 @@ class BaseMixin:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def translate(self, label, mapping={}, domain=None, default=None,
|
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.
|
'''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
|
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"
|
name, but to a label type linked to p_field: "label", "descr"
|
||||||
or "help". Indeed, in this case, a specific i18n mapping may be
|
or "help". Indeed, in this case, a specific i18n mapping may be
|
||||||
available on the field, so we must merge this mapping into
|
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
|
p_mapping.'''
|
||||||
instance of the class where p_field is defined.'''
|
|
||||||
cfg = self.getProductConfig()
|
cfg = self.getProductConfig()
|
||||||
if not domain: domain = cfg.PROJECTNAME
|
if not domain: domain = cfg.PROJECTNAME
|
||||||
if domain != cfg.PROJECTNAME:
|
if domain != cfg.PROJECTNAME:
|
||||||
|
@ -1215,22 +1211,15 @@ class BaseMixin:
|
||||||
else:
|
else:
|
||||||
# Get the label name, and the field-specific mapping if any.
|
# Get the label name, and the field-specific mapping if any.
|
||||||
if field:
|
if field:
|
||||||
# Maybe we do not have the field itself, but only its name
|
# p_field is the dict version of a appy type or group
|
||||||
if isinstance(field, basestring):
|
if field['type'] != 'group':
|
||||||
appyField = self.getAppyType(field, className=className)
|
fieldMapping = field['mapping'][label]
|
||||||
else:
|
|
||||||
appyField = field
|
|
||||||
if appyField:
|
|
||||||
fieldMapping = appyField.mapping[label]
|
|
||||||
if fieldMapping:
|
if fieldMapping:
|
||||||
if callable(fieldMapping):
|
if callable(fieldMapping):
|
||||||
|
appyField = self.getAppyType(field['name'])
|
||||||
fieldMapping=appyField.callMethod(self,fieldMapping)
|
fieldMapping=appyField.callMethod(self,fieldMapping)
|
||||||
mapping.update(fieldMapping)
|
mapping.update(fieldMapping)
|
||||||
# Get the label
|
label = field['%sId' % label]
|
||||||
label = getattr(appyField, label+'Id')
|
|
||||||
else:
|
|
||||||
# It must be a group.
|
|
||||||
label = '%s_group_%s_%s' % (self.meta_type, field, label)
|
|
||||||
# We will get the translation from a Translation object.
|
# We will get the translation from a Translation object.
|
||||||
# In what language must we get the translation?
|
# In what language must we get the translation?
|
||||||
if not language: language = self.getUserLanguage()
|
if not language: language = self.getUserLanguage()
|
||||||
|
|
|
@ -120,7 +120,7 @@
|
||||||
maxReached python:(multiplicity[1] != None) and (len(objs) >= multiplicity[1]);
|
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;
|
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);
|
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 '';
|
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)">
|
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>
|
<tal:comment replace="nothing">Object description</tal:comment>
|
||||||
<p class="discreet" tal:condition="python: not innerRef and appyType['hasDescr']"
|
<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>
|
<tal:comment replace="nothing">Appy (top) navigation</tal:comment>
|
||||||
<metal:nav use-macro="here/skyn/navigate/macros/appyNavigate"/>
|
<metal:nav use-macro="here/skyn/navigate/macros/appyNavigate"/>
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
</tal:asSection>
|
</tal:asSection>
|
||||||
<tal:asTabs condition="python: widget['style'] == 'tabs'">
|
<tal:asTabs condition="python: widget['style'] == 'tabs'">
|
||||||
<table cellpadding="0" cellspacing="0"
|
<table cellpadding="0" cellspacing="0"
|
||||||
tal:attributes="width python: test(widget['wide'], '100%', '');
|
tal:attributes="width widget/wide;
|
||||||
class widget/css_class">
|
class widget/css_class">
|
||||||
<tal:comment replace="nothing">First row: the tabs.</tal:comment>
|
<tal:comment replace="nothing">First row: the tabs.</tal:comment>
|
||||||
<tr valign="middle"><td style="border-bottom: 1px solid #ff8040">
|
<tr valign="middle"><td style="border-bottom: 1px solid #ff8040">
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
</tal:comment>
|
</tal:comment>
|
||||||
<table metal:define-macro="groupContent"
|
<table metal:define-macro="groupContent"
|
||||||
tal:define="cellgap widget/cellgap"
|
tal:define="cellgap widget/cellgap"
|
||||||
tal:attributes="width python: test(widget['wide'], '100%', '');
|
tal:attributes="width widget/wide;
|
||||||
align widget/align;
|
align widget/align;
|
||||||
class widget/css_class;
|
class widget/css_class;
|
||||||
cellspacing widget/cellspacing;
|
cellspacing widget/cellspacing;
|
||||||
|
@ -175,14 +175,14 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<tal:comment replace="nothing">Displays a field label.</tal:comment>
|
<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: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:description>
|
||||||
|
|
||||||
<tal:comment replace="nothing">Displays a field help.</tal:comment>
|
<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: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>
|
<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>
|
||||||
|
|
|
@ -21,7 +21,14 @@ class GroupDescr(Descr):
|
||||||
self.columnsWidths = [col.width for col in group.columns]
|
self.columnsWidths = [col.width for col in group.columns]
|
||||||
self.columnsAligns = [col.align for col in group.columns]
|
self.columnsAligns = [col.align for col in group.columns]
|
||||||
# Names of i18n labels
|
# 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.descrId = self.labelId + '_descr'
|
||||||
self.helpId = self.labelId + '_help'
|
self.helpId = self.labelId + '_help'
|
||||||
# The name of the page where the group lies
|
# The name of the page where the group lies
|
||||||
|
|
Loading…
Reference in a new issue