Opened 9 years ago

Closed 9 years ago

#766 closed enhancement (fixed)

[patch, new-admin] Allow html tags if "allow_tags" model's method attribute is present

Reported by: plisk Owned by: rjwittams
Component: contrib.admin Version:
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by hugo)

Subj, to use like shown below. It allows to include html in object list. Patch against revision 1153, change is in function items_for_result.

class Policy(meta.Model):
        subject = meta.CharField(maxlength=100)
        date_added = meta.DateTimeField('Date Added', default=datetime.today())

        def link_view(self):
                return '<a href="' + str(self.id) + '/view/' + '">view</a>'
        link_view.short_description = 'Action'
        link_view.allow_tags = True

        class META:
                admin = meta.Admin(
                                        list_display = ('subject', 'date_added', 'link_view'),
                                )

Attachments (2)

admin_list.patch (914 bytes) - added by plisk 9 years ago.
Add support for allow_tags attribute
allow_tags_AttributeError.patch (872 bytes) - added by plisk 9 years ago.
correct exception handling ?

Download all attachments as: .zip

Change History (8)

comment:1 Changed 9 years ago by hugo

  • Description modified (diff)

Changed 9 years ago by plisk

Add support for allow_tags attribute

comment:2 Changed 9 years ago by rjwittams

Hm, not sure about applying this in new-admin (changes admin behaviour). I can see it could be useful.
Adrian, Jacob, any thoughts?

comment:3 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [1174]) Fixed #766 -- Custom methods in admin.list_display can now have an allow_tags attribute, which doesn't strip tags in the methods' output. Thanks, plisk

comment:4 Changed 9 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

Sorry to bother, but after revising the code i guess its written with potential exception catch missing. Seems like "func = getattr(result, field_name)" should be in try block and exception is AttributeError and not ObjectDoesNotExist ? Maybe i'm not right, but just want to be sure it will be always working correctly. Below is patch for this.

Changed 9 years ago by plisk

correct exception handling ?

comment:5 Changed 9 years ago by rjwittams

Applied exception fix to new-admin.

Should be applied in trunk if new-admin isn't merged soon....

comment:6 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed in [1434].

Note: See TracTickets for help on using tickets.
Back to Top