mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-16 22:20:24 +00:00
Merge
This commit is contained in:
parent
3796d312e3
commit
fa94f81e7f
2 changed files with 43 additions and 5 deletions
|
|
@ -11,8 +11,10 @@ from .viewmixins import AdminModel2Mixin
|
|||
|
||||
def get_description(action):
|
||||
if hasattr(action, 'description'):
|
||||
# This is for classes
|
||||
return action.description
|
||||
else:
|
||||
# This if for functions
|
||||
return capfirst(action.__name__.replace('_', ' '))
|
||||
|
||||
|
||||
|
|
@ -20,8 +22,8 @@ class BaseListAction(AdminModel2Mixin, TemplateView):
|
|||
|
||||
permission_classes = (permissions.IsStaffPermission,)
|
||||
|
||||
empty_message = 'Items must be selected in order to perform actions on them. ' + \
|
||||
'No items have been changed.'
|
||||
empty_message = 'Items must be selected in order to perform actions ' + \
|
||||
'on them. No items have been changed.'
|
||||
success_message = 'Successfully deleted %d %s'
|
||||
|
||||
queryset = None
|
||||
|
|
@ -103,12 +105,14 @@ class BaseListAction(AdminModel2Mixin, TemplateView):
|
|||
|
||||
return None
|
||||
else:
|
||||
# The user has not confirmed that they want to delete the objects, so
|
||||
# render a template asking for their confirmation.
|
||||
# The user has not confirmed that they want to delete the
|
||||
# objects, so render a template asking for their confirmation.
|
||||
return self.get(request)
|
||||
|
||||
def process_queryset(self):
|
||||
raise NotImplementedError('Must be provided to do some actions with queryset')
|
||||
raise NotImplementedError(
|
||||
'Must be provided to do some actions with queryset'
|
||||
)
|
||||
|
||||
|
||||
class DeleteSelectedAction(BaseListAction):
|
||||
|
|
|
|||
|
|
@ -4,12 +4,21 @@ from django.test import TestCase
|
|||
|
||||
from ..types import ModelAdmin2
|
||||
from ..core import Admin2
|
||||
from ..actions import get_description
|
||||
|
||||
|
||||
class Thing(models.Model):
|
||||
pass
|
||||
|
||||
|
||||
class TestAction(object):
|
||||
description = "Test Action Class"
|
||||
|
||||
|
||||
def test_function():
|
||||
pass
|
||||
|
||||
|
||||
class Admin2Test(TestCase):
|
||||
def setUp(self):
|
||||
self.admin2 = Admin2()
|
||||
|
|
@ -33,3 +42,28 @@ class Admin2Test(TestCase):
|
|||
def test_get_urls(self):
|
||||
self.admin2.register(Thing)
|
||||
self.assertEquals(8, len(self.admin2.get_urls()))
|
||||
|
||||
def test_action_description(self):
|
||||
self.admin2.register(Thing)
|
||||
self.admin2.registry[Thing].list_actions.extend([
|
||||
TestAction,
|
||||
test_function
|
||||
])
|
||||
self.assertEquals(
|
||||
get_description(
|
||||
self.admin2.registry[Thing].list_actions[0]
|
||||
),
|
||||
'Delete selected items'
|
||||
)
|
||||
self.assertEquals(
|
||||
get_description(
|
||||
self.admin2.registry[Thing].list_actions[1]
|
||||
),
|
||||
'Test Action Class'
|
||||
)
|
||||
self.assertEquals(
|
||||
get_description(
|
||||
self.admin2.registry[Thing].list_actions[2]
|
||||
),
|
||||
'Test function'
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue