def render(self): """Initialize renderer""" html = [] active = 'active' if self._active else 'inactive' config = self._field._config.renderer has_errors = len(self._field.get_errors()) has_warnings = len(self._field.get_warnings()) class_options = "form-group %s %s %s" % ((has_errors and 'has-error'), (has_warnings and 'has-warning'), (active)) html.append(HTML.tag("div", _closed=False, rules=u"{}".format(";".join(rules_to_string(self._field))), formgroup="{}".format(self._field.name), desired="{}".format(self._field.desired), required="{}".format(self._field.required), class_=class_options)) html.append(self._render_label()) # All items which can potentially be linked. However this list # of items may be already filtered be defining a default filter # in the overview configuration which is used for this renderer. items = self.itemlist.items selected_items = self._get_selected_items(items) if self._field.readonly or self.onlylinked == "true": items = selected_items # Filter options based on the configured filter expression of # the renderer. Please note the this method return a list of # tuples. item_tuples = self._field.filter_options(items) # Get filtered options and only use the items which are # in the origin items list and has passed filtering. item_tuples = self._field.filter_options(items) # Filter the items again based on the permissions. This means # resetting the third value in the tuple. if self.showall != "true" and not self._field.readonly: item_tuples = filter_options_on_permissions(self._field._form._request, item_tuples) values = {'items': item_tuples, 'selected_item_ids': [i.id for i in selected_items], 'field': self._field, 'clazz': self.get_class(), 'pclazz': self._field._form._item.__class__, 'request': self._field._form._request, '_': self._field._form._translate, 's': security, 'h': helpers, 'url_getter': get_link_url, 'tableconfig': get_table_config(self.itemlist.clazz, config.table)} html.append(literal(self.template.render(**values))) html.append(self._render_errors()) html.append(self._render_help()) html.append(HTML.tag("/div", _closed=False)) return literal("").join(html)
def render(self): """Initialize renderer""" html = [] active = 'active' if self._active else 'inactive' config = self._field._config.renderer has_errors = len(self._field.get_errors()) has_warnings = len(self._field.get_warnings()) class_options = "form-group %s %s %s" % ((has_errors and 'has-error'), (has_warnings and 'has-warning'),(active)) html.append(HTML.tag("div", _closed=False, rules=u"{}".format(";".join(self._field.rules_to_string)), formgroup="{}".format(self._field.name), desired="{}".format(self._field.desired), required="{}".format(self._field.required), class_=class_options)) html.append(self._render_label()) if self._field.is_readonly() or self.onlylinked == "true": items = self._get_selected_items(self.itemlist.items) else: items = self.itemlist.items # Get filtered options and only use the items which are # in the origin items list and has passed filtering. items = self._field.filter_options(items) # Now filter the items based on the user permissions if self.showall != "true": items = filter_options_on_permissions(self._field._form._request, items) values = {'items': items, 'field': self._field, 'clazz': self.get_class(), 'pclazz': self._field._form._item.__class__, 'request': self._field._form._request, '_': self._field._form._translate, 's': security, 'h': helpers, 'tableconfig': get_table_config(self.itemlist.clazz, config.table)} html.append(literal(self.template.render(**values))) html.append(self._render_errors()) html.append(self._render_help()) html.append(HTML.tag("/div", _closed=False)) return literal("").join(html)
def render_link(self): html = [] items = [] try: item = getattr(self._field._form._item, self._field.name) except AttributeError: log.warning("Missing %s attribute in %s" % (self._field.name, self._field._form._item)) return literal("").join(html) if not isinstance(item, list): items.append(item) else: items = item for item in items: url = get_link_url(item, self._field._form._request) if url: html.append(HTML.tag("a", href=("%s" % url), _closed=False)) html.append(escape(unicode(item))) html.append(HTML.tag("/a", _closed=False)) return literal("").join(html)
def _render_body(self, items): out = [] _ = self._request.translate item_label = escape(get_item_modul(self._request, self._item).get_label()) mapping = {'action': escape(_(self._action.capitalize()).lower()), 'item': item_label, 'Action': escape(_(self._action.capitalize()))} out.append(_("Do you really want to ${action}" " the following ${item} items?", mapping=mapping)) out.append(HTML.tag("br", _closed=False)) out.append(HTML.tag("ol", _closed=False)) for item in items: out.append(HTML.tag("li", _closed=False)) out.append(escape(unicode(item))) out.append(HTML.tag("/li", _closed=False)) out.append(HTML.tag("/ol", _closed=False)) out.append(_('Please press "${Action}" to ${action} the item.' ' Press "Cancel" to cancel the action.', mapping=mapping)) return literal("").join(out)