From fa94f81e7fcb86d05815eaef1e3efaf020b74f99 Mon Sep 17 00:00:00 2001 From: Daniel Greenfeld Date: Sat, 6 Jul 2013 11:36:42 +0200 Subject: [PATCH] Merge --- djadmin2/actions.py | 14 +++++++++----- djadmin2/tests/test_core.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/djadmin2/actions.py b/djadmin2/actions.py index 67e15c4..446e9d7 100644 --- a/djadmin2/actions.py +++ b/djadmin2/actions.py @@ -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): diff --git a/djadmin2/tests/test_core.py b/djadmin2/tests/test_core.py index 6828032..1d0b470 100644 --- a/djadmin2/tests/test_core.py +++ b/djadmin2/tests/test_core.py @@ -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' + )