Example #1
0
 def as_ul(self):
     if not self: return ''
     return format_html('<ul class="errorlist">{0}</ul>',
                        format_html_join('', '<li>{0}</li>',
                                         ((force_text(e),) for e in self)
                                         )
                        )
Example #2
0
 def model_index_html(self, request, model, site):
     fields = self.field_dict(model)
     if not fields:
         return ''
     return format_html('<p class="filter"><strong>View calendar by:</strong> {0}</p>',
                        format_html_join(', ', '<a href="calendars/{0}/">{1}</a>',
                                         ((f.name, force_text(capfirst(f.verbose_name))) for f in fields.values())))
Example #3
0
 def as_ul(self):
     if not self: return ''
     return format_html('<ul class="errorlist">{0}</ul>',
                        format_html_join('', '<li>{0}{1}</li>',
                                         ((k, force_text(v))
                                          for k, v in self.items())
                        ))
Example #4
0
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.  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'.
    """
    return format_html_join('', ' {0}="{1}"', attrs.items())
Example #5
0
    def render(self, name, value, attrs):
        encoded = value

        if not is_password_usable(encoded):
            return "None"

        final_attrs = self.build_attrs(attrs)

        try:
            hasher = identify_hasher(encoded)
        except ValueError:
            summary = mark_safe("<strong>Invalid password format or unknown hashing algorithm.</strong>")
        else:
            summary = format_html_join('',
                                       "<strong>{0}</strong>: {1} ",
                                       ((ugettext(key), value)
                                        for key, value in hasher.safe_summary(encoded).items())
                                       )

        return format_html("<div{0}>{1}</div>", flatatt(final_attrs), summary)
Example #6
0
 def render(self):
     """Outputs a <ul> for this set of radio fields."""
     return format_html('<ul>\n{0}\n</ul>',
                        format_html_join('\n', '<li>{0}</li>',
                                         [(force_text(w),) for w in self]
                                         ))
Example #7
0
 def render(self):
     """Outputs a <ul> for this set of radio fields."""
     return format_html('<ul{0}>\n{1}\n</ul>',
                        flatatt(self.attrs),
                        format_html_join('\n', '<li>{0}</li>',
                                         ((force_text(w),) for w in self)))