def errorlist(self, name=None, **attrs): """ Renders errors in a <ul> element if there are multiple, otherwise will use a div. Unless specified in attrs, class will be "Alert". If no errors present returns an empty string. `name` : errors for name. If **None** all errors will be rendered. """ if name is None: errors = self.all_errors() else: errors = self.errors_for(name) if not errors: return "" if "class_" not in attrs: attrs["class_"] = "Alert" if len(errors) > 1: content = "\n".join(HTML.tag("li", error) for error in errors) return HTML.tag("ul", tags.literal(content), **attrs) return HTML.tag("div", errors[0], **attrs)
def errorlist(self, name=None, **attrs): """ Renders errors in a <ul> element if there are multiple, otherwise will use a div. Unless specified in attrs, class will be "Alert". If no errors present returns an empty string. `name` : errors for name. If **None** all errors will be rendered. """ if name is None: errors = self.all_errors() else: errors = self.errors_for(name) if not errors: return '' if 'class_' not in attrs: attrs['class_'] = "Alert" if len(errors) > 1: content = Markup("\n").join(HTML.tag("li", error) for error in errors) return HTML.tag("ul", tags.literal(content), **attrs) return Markup(''' <div class="ui-widget clearfix" style="margin: 0.25em;"> <div class="ui-state-error error-field-wrapper"> <span class="ui-icon ui-icon-alert error-notice-icon"></span>%s </div> </div> ''') % errors[0]
def errorlist(self, name=None, **attrs): _ = self.form.request.translate """ Renders errors in a <ul> element if there are multiple, otherwise will use a div. Unless specified in attrs, class will be "Alert". If no errors present returns an empty string. `name` : errors for name. If **None** all errors will be rendered. """ if name is None: errors = self.all_errors() else: errors = self.errors_for(name) if not errors: return '' if 'class_' not in attrs: attrs['class_'] = "Alert" if len(errors) > 1: content = Markup("\n").join( HTML.tag("li", error) for error in errors) return HTML.tag("ul", tags.literal(content), **attrs) return Markup(''' <div class="ui-widget clearfix" style="margin: 0.25em;"> <div class="ui-state-error error-field-wrapper"> <span class="ui-icon ui-icon-alert error-notice-icon">%s</span>%s </div> </div> ''') % (_('Error'), errors[0])
def errorlist(self, name=None, **attrs): """ Renders errors in a <ul> element. Unless specified in attrs, class will be "error". If no errors present returns an empty string. `name` : errors for name. If **None** all errors will be rendered. """ if not self.form: return None if name is None: errors = self.form.all_errors() else: errors = self.form.errors_for(name) if not errors: return '' content = "\n".join(HTML.tag("li", error) for error in errors) if 'class_' not in attrs: attrs['class_'] = "error" return HTML.tag("ul", tags.literal(content), **attrs)
def hidden_tag(self, *names): """ Convenience for printing all hidden fields in a form inside a hidden DIV. Will also render the CSRF hidden field. """ inputs = [self.hidden(name) for name in names] inputs.append(self.csrf()) return HTML.tag("div", tags.literal("".join(inputs)), style="display:none;")
def tag_development(self, theme, url): """ Return an HTML fragment to use a require.js entry point in development. """ return ''.join([ HTML.script(literal(js_preamble)), HTML.script(src=self.require_config_path), render_js_paths(theme), HTML.script(src=self.require_path), HTML.script(src=url), ])
def hidden_tag(self, *names): """ Convenience for printing all hidden fields in a form inside a hidden DIV. Will also render the CSRF hidden field. :versionadded: 0.4 """ inputs = [self.hidden(name) for name in names] inputs.append(self.csrf()) return HTML.tag("div", tags.literal("".join(inputs)), style="display:none;")
def errorlist(self, name): """ Return a list of errors for the given field as a ``ul`` tag. """ name = self._get_name(name) errors = self.errors_for(name) if not errors: return '' content = "\n".join(HTML.tag("li", error) for error in errors) return HTML.tag("ul", tags.literal(content), class_='error')
def asset_tag(request, key, **kwargs): """ Request method to render an HTML fragment containing tags which reference the supplied entry point. This will dispatch to the appropriate tag rendering function based on context and entry point type. """ theme = request.theme asset = theme.stacked_assets[key] settings = request.registry.settings should_compile = asbool(settings.get('pyramid_frontend.compile')) if should_compile: filename = theme.compiled_asset_path(key) url_path = '/compiled/' + theme.key + '/' + filename else: url_path = asset.url_path return literal( asset.tag(theme, url_path, production=should_compile, **kwargs))
def asset_tag(request, key, **kwargs): """ Request method to render an HTML fragment containing tags which reference the supplied entry point. This will dispatch to the appropriate tag rendering function based on context and entry point type. """ theme = request.theme asset = theme.stacked_assets[key] settings = request.registry.settings should_compile = asbool(settings.get('pyramid_frontend.compile')) if should_compile: filename = theme.compiled_asset_path(key) url_path = '/compiled/' + theme.key + '/' + filename else: url_path = asset.url_path return literal(asset.tag(theme, url_path, production=should_compile, **kwargs))
def errorlist(self, name=None, **attrs): """ Renders errors in a <ul> element. Unless specified in attrs, class will be "error". If no errors present returns an empty string. `name` : errors for name. If **None** all errors will be rendered. """ if name is None: errors = self.all_errors() else: errors = self.errors_for(name) if not errors: return '' content = "\n".join(HTML.tag("li", error) for error in errors) if 'class_' not in attrs: attrs['class_'] = "error" return HTML.tag("ul", tags.literal(content), **attrs)