from tg import url from tw.forms import validators get = ViewFactory.get.im_func from pylons.i18n import ugettext as _ class CitedRelation(Relation): """ Ce champ fonctionne exactement comme le type C{Relation} de rum.fields, sauf qu'il ne fournit pas de liens entre les entités. Utilisez ce champ lorsque vous souhaitez pouvoir lier l'objet à d'autres sans que les objets pointés soient accessibles directement (modifiables). """ pass @get.around("isinstance(attr, CitedRelation) and " "action in inline_actions", prio=10) def _widget_for_cited_relation(self, resource, parent, remote_name, attr, action, args): """ Modifie la vue pour éviter que des liens d'édition/consultation vers la cible de la relation ne soient ajoutés. """ args["field"] = attr return widgets.ExpandableSpan WidgetFactory.register_widget(forms.SingleSelectField, CitedRelation, input_actions, _prio=10)
self.groups_url = groups_url self.path_url = path_url self.single_type = single_type class GroupLink(widgets.Span): def update_params(self, d): super(GroupLink, self).update_params(d) if d.value is None: d.unicode_value = u"" elif isinstance(d.value, SupItemGroup): d.unicode_value = u"/" + _("Groups of monitored items") + d.value.path else: # Sinon, c'est un MapGroup. # On masque le préfixe "/Root". d.unicode_value = u"/" + _("Groups of maps") + d.value.path[5:] @get.when("isinstance(attr, GroupRelation) and " "action in inline_actions", prio=10) def _widget_for_group_relation(self, resource, parent, remote_name, attr, action, args): args["field"] = attr return GroupLink @get.before("isinstance(attr, GroupRelation)", prio=10) def _url_for_group_relation(self, resource, parent, remote_name, attr, action, args): args["field"] = attr WidgetFactory.register_widget(GroupSelector, GroupRelation, input_actions, _prio=10)
super(Enum, self).__init__(name, required, label, default, read_only, searchable=searchable, sortable=sortable) if not isinstance(options, (list, tuple)): raise TypeError, options self.options = options class EnumDisplay(widgets.Span): def update_params(self, d): super(EnumDisplay, self).update_params(d) options = dict(d.field.options) d.escape = False template = u'<span class="rum-field-value" title="%s">%s</span>' d.unicode_value = template % (options[d.unicode_value], d.unicode_value) @get.before("isinstance(attr, Enum)") def _set_options_for_enum(self, resource, parent, remote_name, attr, action, args): args['options'] = attr.options v = validators.OneOf([o[0] for o in attr.options]) self.add_validator(v, args) @get.when("isinstance(attr, Enum) and action in inline_actions") def _show_enum_tooltip(self, resource, parent, remote_name, attr, action, args): args['field'] = attr return EnumDisplay WidgetFactory.register_widget( forms.SingleSelectField, Enum, input_actions, _prio=-1, )