Opened 17 years ago
Closed 14 years ago
#5767 closed (wontfix)
EmailField should render as a mailto anchor in admin list page
Reported by: | hax | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | newforms-admin |
Severity: | Keywords: | nfa-someday EmailField | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
It seems to me that there is no reason to not have an EmailField be a mailto link in an admin interface. These interfaces generally aren't public, so hiding from spambots shouldn't be an issue.
This is my first attempt at a patch, feedback is appreciated :)
Index: django/contrib/admin/templatetags/admin_list.py =================================================================== --- django/contrib/admin/templatetags/admin_list.py (revision 6525) +++ django/contrib/admin/templatetags/admin_list.py (working copy) @@ -177,6 +177,12 @@ result_repr = ('%%.%sf' % f.decimal_places) % field_val else: result_repr = EMPTY_CHANGELIST_VALUE + # EmailFields are mailto links + elif isinstance(f, models.EmailField): + if field_val is not None: + result_repr = '<a href="mailto:%s">%s</a>' % (escape(field_val), escape(field_val)) + else: + result_repr = EMPTY_CHANGELIST_VALUE # Fields with choices are special: Use the representation # of the choice. elif f.choices:
--maqr
Change History (7)
comment:1 by , 17 years ago
Patch needs improvement: | set |
---|---|
Summary: | Patch for EmailField to render as a mailto anchor in admin interface → EmailField should render as a mailto anchor in admin list page |
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 17 years ago
That is against the newforms-admin branch, I'm not sure why it would look like it's not.
In the future I'll attach the .diff, but from my svn info
:
URL: http://code.djangoproject.com/svn/django/branches/newforms-admin
Repository UUID: bcc190cf-cafb-0310-a4f2-bffc1f526a37
Revision: 6525
So I'm pretty sure I patched for the right branch.
Let me know,
--hax
comment:3 by , 17 years ago
Oh, silly me - how did I overlook that? For penance, I'll properly review the patch :)
- I don't see any benefit of falling back to
EMPTY_CHANGELIST_VALUE
for a text field
- Since your
if
only checks foris not None
, an empty string would return'<a href="mailto:"></a>'
comment:4 by , 17 years ago
Oops :)
I'm pretty sure this is right (and for some reason, it won't let me attach in a reply, or I'd upload it as a diff):
Index: django/contrib/admin/templatetags/admin_list.py =================================================================== --- django/contrib/admin/templatetags/admin_list.py (revision 6525) +++ django/contrib/admin/templatetags/admin_list.py (working copy) @@ -177,6 +177,12 @@ result_repr = ('%%.%sf' % f.decimal_places) % field_val else: result_repr = EMPTY_CHANGELIST_VALUE + # EmailFields are mailto links + elif isinstance(f, models.EmailField): + if field_val: + result_repr = '<a href="mailto:%s">%s</a>' % (escape(field_val), escape(field_val)) + else: + result_repr = "" # Fields with choices are special: Use the representation # of the choice. elif f.choices:
--hax
comment:5 by , 17 years ago
Keywords: | nfa-someday added |
---|
This ticket isn't critical to merge newforms-admin into trunk. Tagging with nfa-someday. While I see this as a good feature and no reason not to include it, it can already be accomplished. list_display
can accept callables so you can define a method on your model and get the same functionality.
comment:7 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
We don't do this kind of thing for URL fields, so it would be inconsistent. We also have one column int he changelist page that is a link that goes to add form and that would cause confusion about what the links do.
Creating a clickable column in the admin list page is easy enough: write a function and use that in the "fields" attribute (enabling linking for that function, etc), so creating this effect can be done in admin classes without requiring Django source changes.
Hi hax, the normal way is to attach the patch as a file rather than paste it in your description.
Since admin is being replaced, you'd be better off creating a patch against the newforms-admin branch.