Python django.utils.html.format_html_join() Examples
The following are 30
code examples of django.utils.html.format_html_join().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.html
, or try the search function
.
Example #1
Source File: forms.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
def render(self, name, value, attrs): encoded = value final_attrs = self.build_attrs(attrs) if not encoded or encoded.startswith(UNUSABLE_PASSWORD_PREFIX): summary = mark_safe("<strong>%s</strong>" % ugettext("No password set.")) else: try: hasher = identify_hasher(encoded) except ValueError: summary = mark_safe("<strong>%s</strong>" % ugettext( "Invalid password format or unknown hashing algorithm.")) else: summary = format_html_join('', "<strong>{}</strong>: {} ", ((ugettext(key), value) for key, value in hasher.safe_summary(encoded).items()) ) return format_html("<div{}>{}</div>", flatatt(final_attrs), summary)
Example #2
Source File: wagtail_hooks.py From wagtailcolourpicker with MIT License | 6 votes |
def insert_editor_js(): js_files = [ # We require this file here to make sure it is loaded before the other. 'wagtailadmin/js/draftail.js', 'colourpicker/js/colourpicker.js', ] js_includes = format_html_join( '\n', '<script src="{0}"></script>', ((static(filename), ) for filename in js_files) ) js_includes += format_html( "<script>window.chooserUrls.colourChooser = '{0}';</script>", reverse('wagtailcolourpicker:chooser') ) return js_includes
Example #3
Source File: forms.py From openhgsenti with Apache License 2.0 | 6 votes |
def render(self, name, value, attrs): encoded = value final_attrs = self.build_attrs(attrs) if not encoded or encoded.startswith(UNUSABLE_PASSWORD_PREFIX): summary = mark_safe("<strong>%s</strong>" % ugettext("No password set.")) else: try: hasher = identify_hasher(encoded) except ValueError: summary = mark_safe("<strong>%s</strong>" % ugettext( "Invalid password format or unknown hashing algorithm.")) else: summary = format_html_join('', "<strong>{}</strong>: {} ", ((ugettext(key), value) for key, value in hasher.safe_summary(encoded).items()) ) return format_html("<div{}>{}</div>", flatatt(final_attrs), summary)
Example #4
Source File: utils.py From python2017 with MIT License | 6 votes |
def flatatt(attrs): """ Convert a dictionary of attributes to a single string. The returned string will contain a leading space followed by key="value", XML-style pairs. In the case of a boolean value, the key will appear without a value. It is assumed that the keys do not need to be XML-escaped. If the passed dictionary is empty, then return an empty string. The result is passed through 'mark_safe' (by way of 'format_html_join'). """ key_value_attrs = [] boolean_attrs = [] for attr, value in attrs.items(): if isinstance(value, bool): if value: boolean_attrs.append((attr,)) elif value is not None: key_value_attrs.append((attr, value)) return ( format_html_join('', ' {}="{}"', sorted(key_value_attrs)) + format_html_join('', ' {}', sorted(boolean_attrs)) )
Example #5
Source File: utils.py From openhgsenti with Apache License 2.0 | 6 votes |
def flatatt(attrs): """ Convert a dictionary of attributes to a single string. The returned string will contain a leading space followed by key="value", XML-style pairs. In the case of a boolean value, the key will appear without a value. It is assumed that the keys do not need to be XML-escaped. If the passed dictionary is empty, then return an empty string. The result is passed through 'mark_safe' (by way of 'format_html_join'). """ key_value_attrs = [] boolean_attrs = [] for attr, value in attrs.items(): if isinstance(value, bool): if value: boolean_attrs.append((attr,)) else: key_value_attrs.append((attr, value)) return ( format_html_join('', ' {}="{}"', sorted(key_value_attrs)) + format_html_join('', ' {}', sorted(boolean_attrs)) )
Example #6
Source File: utils.py From python with Apache License 2.0 | 6 votes |
def flatatt(attrs): """ Convert a dictionary of attributes to a single string. The returned string will contain a leading space followed by key="value", XML-style pairs. In the case of a boolean value, the key will appear without a value. It is assumed that the keys do not need to be XML-escaped. If the passed dictionary is empty, then return an empty string. The result is passed through 'mark_safe' (by way of 'format_html_join'). """ key_value_attrs = [] boolean_attrs = [] for attr, value in attrs.items(): if isinstance(value, bool): if value: boolean_attrs.append((attr,)) elif value is not None: key_value_attrs.append((attr, value)) return ( format_html_join('', ' {}="{}"', sorted(key_value_attrs)) + format_html_join('', ' {}', sorted(boolean_attrs)) )
Example #7
Source File: messages.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
def validation_error(request, message, form, buttons=None): if not form.non_field_errors(): # just output the generic "there were validation errors" message, and leave # the per-field highlighting to do the rest detail = '' else: # display the full list of field and non-field validation errors all_errors = [] for field_name, errors in form.errors.items(): if field_name == NON_FIELD_ERRORS: prefix = '' else: try: field_label = form[field_name].label except KeyError: field_label = field_name prefix = "%s: " % field_label for error in errors: all_errors.append(prefix + error) errors_html = format_html_join('\n', '<li>{}</li>', ((e,) for e in all_errors)) detail = format_html("""<ul class="errorlist">{}</ul>""", errors_html) return messages.error(request, render(message, buttons, detail=detail))
Example #8
Source File: utils.py From Hands-On-Application-Development-with-PyCharm with MIT License | 6 votes |
def flatatt(attrs): """ Convert a dictionary of attributes to a single string. The returned string will contain a leading space followed by key="value", XML-style pairs. In the case of a boolean value, the key will appear without a value. It is assumed that the keys do not need to be XML-escaped. If the passed dictionary is empty, then return an empty string. The result is passed through 'mark_safe' (by way of 'format_html_join'). """ key_value_attrs = [] boolean_attrs = [] for attr, value in attrs.items(): if isinstance(value, bool): if value: boolean_attrs.append((attr,)) elif value is not None: key_value_attrs.append((attr, value)) return ( format_html_join('', ' {}="{}"', sorted(key_value_attrs)) + format_html_join('', ' {}', sorted(boolean_attrs)) )
Example #9
Source File: utils.py From bioforum with MIT License | 6 votes |
def flatatt(attrs): """ Convert a dictionary of attributes to a single string. The returned string will contain a leading space followed by key="value", XML-style pairs. In the case of a boolean value, the key will appear without a value. It is assumed that the keys do not need to be XML-escaped. If the passed dictionary is empty, then return an empty string. The result is passed through 'mark_safe' (by way of 'format_html_join'). """ key_value_attrs = [] boolean_attrs = [] for attr, value in attrs.items(): if isinstance(value, bool): if value: boolean_attrs.append((attr,)) elif value is not None: key_value_attrs.append((attr, value)) return ( format_html_join('', ' {}="{}"', sorted(key_value_attrs)) + format_html_join('', ' {}', sorted(boolean_attrs)) )
Example #10
Source File: widgets.py From django-is-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _render_readonly(self, name, value, attrs=None, renderer=None, request=None, form=None, initial_value=None): if request and value and isinstance(value, (list, tuple)): rendered_values = [] for value_item in value: choice = self._choice(value_item) if choice: value_item = force_text(choice[1]) if choice.obj: rendered_values.append(self._render_object(request, choice.obj, value_item)) else: rendered_values.append(value_item) return format_html( '<p>{}</p>', format_html_join(', ', '{}', ((v,) for v in rendered_values)) if rendered_values else EMPTY_VALUE ) else: return super(ModelObjectReadonlyWidget, self)._render_readonly( name, value, attrs, renderer, request, form, initial_value )
Example #11
Source File: wagtail_hooks.py From wagtail-cookiecutter-foundation with MIT License | 6 votes |
def editor_js(): # Add extra JS files to the admin js_files = [ 'js/hallo-custom.js', ] js_includes = format_html_join( '\n', '<script src="{0}{1}"></script>', ((settings.STATIC_URL, filename) for filename in js_files) ) return js_includes + format_html( """ <script> registerHalloPlugin('blockquotebutton'); registerHalloPlugin('blockquotebuttonwithclass'); </script> """ )
Example #12
Source File: wagtail_hooks.py From wagtailmodelchoosers with MIT License | 5 votes |
def wagtailmodelchoosers_admin_js(): js_files = ( 'wagtailmodelchoosers/wagtailmodelchoosers.js', 'wagtailmodelchoosers/polyfills.js', ) js_includes = format_html_join( '\n', '<script src="{}"></script>', ((static(filename),) for filename in js_files) ) return js_includes
Example #13
Source File: widgets.py From django-is-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
def flat_data_attrs(attrs): return format_html_join('', ' data-{0}="{1}"', sorted(attrs.items()))
Example #14
Source File: wagtail_hooks.py From wagtail-embedvideos with BSD 3-Clause "New" or "Revised" License | 5 votes |
def editor_js(): js_files = [ 'wagtail_embed_videos/js/embed-video-chooser.js', ] js_includes = format_html_join('\n', '<script src="{0}{1}"></script>', ( (settings.STATIC_URL, filename) for filename in js_files) ) return js_includes + format_html( """ <script> window.chooserUrls.embedVideoChooser = '{0}'; </script> """, reverse('wagtail_embed_videos_chooser') )
Example #15
Source File: wagtail_hooks.py From wagtail-headless-preview with BSD 3-Clause "New" or "Revised" License | 5 votes |
def editor_js(): if hasattr(settings, "HEADLESS_PREVIEW_LIVE") and settings.HEADLESS_PREVIEW_LIVE: js_files = ["js/live-preview.js"] return format_html_join( "\n", '<script src="{0}{1}"></script>', ((settings.STATIC_URL, filename) for filename in js_files), ) return ""
Example #16
Source File: wagtail_hooks.py From WF-website with GNU Affero General Public License v3.0 | 5 votes |
def editor_js(): js_files = [ 'js/contact_person_slug.js', ] js_includes = format_html_join('\n', '<script src="{0}{1}"></script>', ((settings.STATIC_URL, filename) for filename in js_files) ) return js_includes
Example #17
Source File: __init__.py From django-is-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
def render_model_objects_with_link(request, objs): return format_html_join(', ', '{}', ((render_model_object_with_link(request, obj),) for obj in objs))
Example #18
Source File: utils.py From python2017 with MIT License | 5 votes |
def as_ul(self): if not self: return '' return format_html( '<ul class="errorlist">{}</ul>', format_html_join('', '<li>{}{}</li>', ((k, force_text(v)) for k, v in self.items())) )
Example #19
Source File: utils.py From python2017 with MIT License | 5 votes |
def as_ul(self): if not self.data: return '' return format_html( '<ul class="{}">{}</ul>', self.error_class, format_html_join('', '<li>{}</li>', ((force_text(e),) for e in self)) )
Example #20
Source File: models.py From scirius with GNU General Public License v3.0 | 5 votes |
def get_icons(self): from scirius.utils import get_middleware_module actions_dict = get_middleware_module('common').get_user_actions_dict() actions = UserActionObject.objects.filter(user_action=self).all() icons = [(self.get_icon(), self.username)] for action in actions: # ==== Coner cases # transformation is str type # or workaround for UserAction which can contains no instance but str (ex: create a source without a ruleset) if action.action_key == 'transformation' or \ (action.action_key == 'ruleset' and action.action_value == 'No Ruleset') or \ action.action_key == 'threat_status': continue ct = action.content_type klass = ct.model_class() if hasattr(klass, 'get_icon'): lb = action.action_value icon = klass.get_icon() instances = klass.objects.filter(pk=action.object_id).all() if len(instances): if isinstance(instances[0], Source): icon = Source.get_icon(instances[0]) if isinstance(instances[0], Rule): lb = instances[0].pk icons.append((icon, lb)) html = format_html_join( '\n', '<div class="list-view-pf-additional-info-item"><span class="fa {}"></span>{}</div>', ((icon, klass_name) for icon, klass_name in icons) ) return html
Example #21
Source File: wagtail_hooks.py From madewithwagtail with MIT License | 5 votes |
def editor_css(): """ Add extra CSS files to the admin """ css_files = [ 'wagtailadmin/css/admin.css', ] css_includes = format_html_join( '\n', '<link rel="stylesheet" href="{0}{1}">', ((settings.STATIC_URL, filename) for filename in css_files)) return css_includes
Example #22
Source File: form_as_div.py From ctf-gameserver with ISC License | 5 votes |
def as_ul(self): elements = format_html_join('\n', '<li class="list-group-item list-group-item-danger">{}</li>', ((e,) for e in self)) return format_html('<ul class="list-group">\n{}\n</ul>', elements)
Example #23
Source File: form_as_div.py From ctf-gameserver with ISC License | 5 votes |
def as_ul(self): elements = format_html_join('\n', '<li class="list-group-item list-group-item-danger">{}</li>', ((e,) for e in self)) return format_html('<ul class="list-group">\n{}\n</ul>', elements)
Example #24
Source File: form_as_div.py From ctf-gameserver with ISC License | 5 votes |
def as_ul(self): elements = format_html_join('\n', '<li class="list-group-item list-group-item-danger">{}</li>', ((e,) for e in self)) return format_html('<ul class="list-group">\n{}\n</ul>', elements)
Example #25
Source File: form_as_div.py From ctf-gameserver with ISC License | 5 votes |
def as_ul(self): elements = format_html_join('\n', '<li class="list-group-item list-group-item-danger">{}</li>', ((e,) for e in self)) return format_html('<ul class="list-group">\n{}\n</ul>', elements)
Example #26
Source File: form_as_div.py From ctf-gameserver with ISC License | 5 votes |
def as_ul(self): elements = format_html_join('\n', '<li class="list-group-item list-group-item-danger">{}</li>', ((e,) for e in self)) return format_html('<ul class="list-group">\n{}\n</ul>', elements)
Example #27
Source File: wagtail_hooks.py From wagtailnews with BSD 2-Clause "Simplified" License | 5 votes |
def editor_js(): js_files = [ static('js/news_chooser.js'), ] js_includes = format_html_join( '\n', '<script src="{0}"></script>\n', ((filename, ) for filename in js_files) ) urls = format_html( '<script>window.chooserUrls.newsChooser = "{}";</script>', reverse('wagtailnews:chooser')) return js_includes + urls
Example #28
Source File: wagtail_hooks.py From wagtail-review with BSD 3-Clause "New" or "Revised" License | 5 votes |
def editor_js(): js_files = [ 'wagtail_review/js/wagtail-review-admin.js', ] js_includes = format_html_join( '\n', '<script src="{0}{1}"></script>', ((settings.STATIC_URL, filename) for filename in js_files) ) return js_includes # Inject code into the action menu that tells the UI which page is being viewed # This isn't actually a menu item. It's the only way to inject code into the Wagtail # editor where we also have the page ID
Example #29
Source File: fields.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def __str__(self): table = format_html_join( '\n', '<tbody>{}</tbody>', ((form.as_table(),) for form in self.form_set)) table = format_html( '\n<table class="{}-array-model-field">' '\n{}' '\n</table>', self.name, table) return format_html('{}\n{}', table, self.form_set.management_form)
Example #30
Source File: wagtail_hooks.py From wagtail-blog-app with MIT License | 5 votes |
def editor_js(): js_files = [ 'global/js/hallo-code-snippet.js', 'global/js/hallo-code-block.js', 'global/js/hallo-tables.js', 'global/js/hallo-quote-snippet.js', 'global/js/hallo-htmledit.js', ] js_includes = format_html_join( '\n', '<script src="{0}{1}"></script>', ((settings.STATIC_URL, filename) for filename in js_files) ) return js_includes + format_html( """ <script> registerHalloPlugin('codesnippet'); registerHalloPlugin('codeblock'); registerHalloPlugin('tables'); registerHalloPlugin('quotesnippet'); registerHalloPlugin('editHtmlButton'); </script> """ )