Esempio n. 1
0
 def result_for_item(self, headers, result, djp, nd = 3):
     if isinstance(result, self.model):
         request = djp.request
         path  = djp.http.path_with_query(request)
         first = True
         id    = ('%s-%s') % (self.module_name,result.id)
         display = []
         item = {'id':id,'display':display}
         for field_name in headers:
             result_repr = self.getrepr(field_name, result, nd)
             if force_str(result_repr) == '':
                 result_repr = mark_safe(' ')
             if (first and not self.list_display_links) or field_name in self.list_display_links:
                 first = False
                 url = self.url_for_result(request, result, field_name)
             else:
                 url = None
             
             var = conditional_escape(result_repr)
             if url:
                 if url != path:
                     var = mark_safe('<a href="{0}" title="{1}">{1}</a>'.format(url, var))
                 else:
                     var = mark_safe('<a>{0}</a>'.format(var))
             display.append(var)
         return item
     else:
         return nice_items_id(result, nd = nd)
Esempio n. 2
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.
    """
    return ''.join([' {0}="{1}"'.format(k, conditional_escape(v)) for k, v in attrs.items()])