#32099: Admin action decorators
-------------------------------------+-------------------------------------
Reporter: Michal | Owner: nobody
Dabski |
Type: | Status: new
Cleanup/optimization |
Component: | Version: master
contrib.admin | Keywords:
Severity: Normal | admin,actions,decorator
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently django admin actions can be customized by adding arbitrary
properties to the action method or function (allowed_permissions ,
short_description). This method is not very discoverable, and rather un-
puthonic.
Proposed solution:
Django should provide a built-in decorator that wrap action callable and
adds any properties passed to the decorator. Because decorator can define
available properties in it's signature, this method will be less error-
prone and will make it easier to discover properties available to admin
actions.
As an added bonus, a decorator could maybe even add the action to the
`actions` list without the user having to do it explicitly.
Example:
{{{
@admin.register(models.Document)
class DocumentAdmin(ModelAdmin):
actions = 'publish',
def publish(self, request, qs):
qs.update(publish=True)
publish.short_description = _('publish document')
publish.allowed_permissions =[ 'change']
}}}
could become:
{{{
@admin.register(models.Document)
class DocumentAdmin(ModelAdmin):
actions = 'publish',
@action(short_description=_('publish document'),
allowed_permissions=['change'])
def publish(self, request, qs):
qs.update(publish=True)
}}}
This functionality is implemented by a third-party library, but it has not
been updated in 9 years:
https://github.com/kmike/django-admin-decorators
--
Ticket URL: <https://code.djangoproject.com/ticket/32099>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.75c55dfece195d3bfca9091f5ce9c232%40djangoproject.com.