Пример #1
0
 def _get_new_field_html(self, field_name):
     try:
         f, attr, value = lookup_field(field_name, self.org_obj, self)
     except (AttributeError, ObjectDoesNotExist):
         return EMPTY_CHANGELIST_VALUE
     else:
         allow_tags = False
         if f is None:
             allow_tags = getattr(attr, 'allow_tags', False)
             boolean = getattr(attr, 'boolean', False)
             if boolean:
                 allow_tags = True
                 text = boolean_icon(value)
             else:
                 text = smart_unicode(value)
         else:
             if isinstance(f.rel, models.ManyToOneRel):
                 field_val = getattr(self.org_obj, f.name)
                 if field_val is None:
                     text = EMPTY_CHANGELIST_VALUE
                 else:
                     text = field_val
             else:
                 text = display_for_field(value, f)
         return mark_safe(text) if allow_tags else conditional_escape(text)
Пример #2
0
 def init(self):
     self.label = label_for_field(self.field_name, self.obj.__class__,
                                  model_admin=self.admin_view,
                                  return_attr=False
                                  )
     try:
         f, attr, value = lookup_field(
             self.field_name, self.obj, self.admin_view)
     except (AttributeError, ObjectDoesNotExist):
         self.text
     else:
         if f is None:
             self.allow_tags = getattr(attr, 'allow_tags', False)
             boolean = getattr(attr, 'boolean', False)
             if boolean:
                 self.allow_tags = True
                 self.text = boolean_icon(value)
             else:
                 self.text = smart_unicode(value)
         else:
             if isinstance(f.rel, models.ManyToOneRel):
                 self.text = getattr(self.obj, f.name)
             else:
                 self.text = display_for_field(value, f)
         self.field = f
         self.attr = attr
         self.value = value
Пример #3
0
    def result_item(self, obj, field_name, row):
        """
        Generates the actual list of data.
        """
        item = ResultItem(field_name, row)
        try:
            f, attr, value = lookup_field(field_name, obj, self)
        except (AttributeError, ObjectDoesNotExist):
            item.text = mark_safe("<span class='text-muted'>%s</span>" % EMPTY_CHANGELIST_VALUE)
        else:
            if f is None:
                item.allow_tags = getattr(attr, 'allow_tags', False)
                boolean = getattr(attr, 'boolean', False)
                if boolean:
                    item.allow_tags = True
                    item.text = boolean_icon(value)
                else:
                    item.text = smart_unicode(value)
            else:
                if isinstance(f.rel, models.ManyToOneRel):
                    field_val = getattr(obj, f.name)
                    if field_val is None:
                        item.text = mark_safe("<span class='text-muted'>%s</span>" % EMPTY_CHANGELIST_VALUE)
                    else:
                        item.text = field_val
                else:
                    item.text = display_for_field(value, f)
                if isinstance(f, models.DateField)\
                    or isinstance(f, models.TimeField)\
                        or isinstance(f, models.ForeignKey):
                    item.classes.append('nowrap')

            item.field = f
            item.attr = attr
            item.value = value

        # If list_display_links not defined, add the link tag to the first field
        if (item.row['is_display_first'] and not self.list_display_links) \
                or field_name in self.list_display_links:
            item.row['is_display_first'] = False
            item.is_display_link = True
            if self.list_display_links_details:
                item_res_uri = self.model_admin_url("detail", getattr(obj, self.pk_attname))
                if item_res_uri:
                    if self.has_change_permission(obj):
                        edit_url = self.model_admin_url("change", getattr(obj, self.pk_attname))
                    else:
                        edit_url = ""
                    item.wraps.append('<a data-res-uri="%s" data-edit-uri="%s" class="details-handler" rel="tooltip" title="%s">%%s</a>'
                                     % (item_res_uri, edit_url, _(u'Details of %s') % str(obj)))
            else:
                url = self.url_for_result(obj)
                item.wraps.append(u'<a href="%s">%%s</a>' % url)

        return item