def render_icon(icon, **kwargs): """Render a Bootstrap glyphicon icon.""" attrs = {"class": add_css_class("glyphicon glyphicon-{icon}".format(icon=icon), kwargs.get("extra_classes", ""))} title = kwargs.get("title") if title: attrs["title"] = title return render_tag("span", attrs=attrs)
def render_icon(icon, title=""): """ Render a Bootstrap glyphicon icon """ attrs = {"class": "glyphicon glyphicon-{icon}".format(icon=icon)} if title: attrs["title"] = title return render_tag("span", attrs=attrs)
def hidden_input(self): """ HTML for the hidden input element """ return render_tag('input', attrs={ 'id': self.hidden_id, 'name': self.bound.html_name, 'type': 'hidden', 'value': self.bound.value() or "" })
def render_icon(icon, title=''): """ Render a Bootstrap glyphicon icon """ attrs = { 'class': 'glyphicon glyphicon-{icon}'.format(icon=icon), } if title: attrs['title'] = title return render_tag('span', attrs=attrs)
def gen_hidden_div(self): """ Generate HTML code for the div that contains hidden tags """ self.gen_full_js() content = self.js_script if not self.multiple and not self.gen_select: content += self.hidden_input() self.html += render_tag('div', content=content, attrs={'id': self.div2_id})
def comments_javascript(): add_url = reverse('comments:add') javascript = """ <script> window.COMMENTS_ADD_COMMENT_URL = '{}'; </script> """.format(add_url) url = settings.STATIC_URL + 'js/comments.js' commentsjs = render_tag('script', attrs={'src': url}) javascript = mark_safe(javascript + commentsjs) itemjstmpl = get_template('comments/_item_js.html').render({}) javascript += itemjstmpl return javascript
def render_icon(icon, **kwargs): """ Render a Bootstrap glyphicon icon """ attrs = { "class": add_css_class( "glyphicon glyphicon-{icon}".format(icon=icon), kwargs.get("extra_classes", ""), ) } title = kwargs.get("title") if title: attrs["title"] = title return render_tag("span", attrs=attrs)
def render_icon(icon, **kwargs): """ Render a Bootstrap glyphicon icon """ attrs = { 'class': add_css_class( 'glyphicon glyphicon-{icon}'.format(icon=icon), kwargs.get('extra_classes', ''), ) } title = kwargs.get('title') if title: attrs['title'] = title return render_tag('span', attrs=attrs)
def render_alert(content, alert_type=None, dismissable=True): """Render a Bootstrap alert.""" button = "" if not alert_type: alert_type = "info" css_classes = ["alert", "alert-" + text_value(alert_type)] if dismissable: css_classes.append("alert-dismissable") button = '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' button_placeholder = "__BUTTON__" return mark_safe( render_tag( "div", attrs={"class": " ".join(css_classes)}, content=button_placeholder + text_value(content) ).replace(button_placeholder, button) )
def render_alert(content, alert_type=None, dismissable=True): """ Render a Bootstrap alert """ button = "" if not alert_type: alert_type = "info" css_classes = ["alert", "alert-" + text_value(alert_type)] if dismissable: css_classes.append("alert-dismissable") button = '<button type="button" class="close" ' + 'data-dismiss="alert" aria-hidden="true">×</button>' button_placeholder = "__BUTTON__" return mark_safe( render_tag( "div", attrs={"class": " ".join(css_classes)}, content=button_placeholder + text_value(content) ).replace(button_placeholder, button) )
def render_alert(content, alert_type=None, dismissable=True): """ Render a Bootstrap alert """ button = '' if not alert_type: alert_type = 'info' css_classes = ['alert', 'alert-' + text_value(alert_type)] if dismissable: css_classes.append('alert-dismissable') button = '<button type="button" class="close" ' + \ 'data-dismiss="alert" aria-hidden="true">×</button>' button_placeholder = '__BUTTON__' return mark_safe(render_tag( 'div', attrs={'class': ' '.join(css_classes)}, content=button_placeholder + text_value(content), ).replace(button_placeholder, button))
def test_render_tag(self): self.assertEqual(render_tag("span"), "<span></span>") self.assertEqual(render_tag("span", content="foo"), "<span>foo</span>") self.assertEqual(render_tag("span", attrs={"bar": 123}, content="foo"), '<span bar="123">foo</span>')
def get_script(self): """ Insert the JS code inside a script tag """ self.js_script = render_tag('script', content=mark_safe(self.js_script))