Opened 18 years ago

Closed 18 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: no UI/UX: no

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 18 years ago.
Add support for allow_tags attribute
allow_tags_AttributeError.patch (872 bytes ) - added by plisk 18 years ago.
correct exception handling ?

Download all attachments as: .zip

Change History (8)

comment:1 by hugo, 18 years ago

Description: modified (diff)

by plisk, 18 years ago

Attachment: admin_list.patch added

Add support for allow_tags attribute

comment:2 by rjwittams, 18 years ago

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 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(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 by anonymous, 18 years ago

Resolution: fixed
Status: closedreopened

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.

by plisk, 18 years ago

correct exception handling ?

comment:5 by rjwittams, 18 years ago

Applied exception fix to new-admin.

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

comment:6 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: reopenedclosed

Fixed in [1434].

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