Skip to content

Commit 03fc99a

Browse files
committed
Fixed the new admin bits to not explode on Django 1.1.
1 parent 4a46b0c commit 03fc99a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

haystack/admin.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
try:
1212
from django.contrib.admin.options import csrf_protect_m
1313
except ImportError:
14-
raise ImproperlyConfigured("Using the ``SearchModelAdmin`` requires Django 1.1+.")
14+
from haystack.utils.decorators import method_decorator
15+
16+
# Do nothing on Django 1.1 and below.
17+
def csrf_protect(view):
18+
def wraps(request, *args, **kwargs):
19+
return view(request, *args, **kwargs)
20+
return wraps
21+
22+
csrf_protect_m = method_decorator(csrf_protect)
1523

1624

1725
class SearchChangeList(ChangeList):
@@ -97,7 +105,7 @@ def changelist_view(self, request, extra_context=None):
97105
'action_form': action_form,
98106
'actions_on_top': self.actions_on_top,
99107
'actions_on_bottom': self.actions_on_bottom,
100-
'actions_selection_counter': self.actions_selection_counter,
108+
'actions_selection_counter': getattr(self, 'actions_selection_counter', 0),
101109
}
102110
context.update(extra_context or {})
103111
context_instance = template.RequestContext(request, current_app=self.admin_site.name)

haystack/utils/decorators.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Backport of Django 1.2's ``django.utils.decorators``.
2+
try:
3+
from functools import wraps, update_wrapper, WRAPPER_ASSIGNMENTS
4+
except ImportError:
5+
from django.utils.functional import wraps, update_wrapper, WRAPPER_ASSIGNMENTS # Python 2.4 fallback.
6+
7+
8+
def method_decorator(decorator):
9+
"""
10+
Converts a function decorator into a method decorator
11+
"""
12+
def _dec(func):
13+
def _wrapper(self, *args, **kwargs):
14+
def bound_func(*args2, **kwargs2):
15+
return func(self, *args2, **kwargs2)
16+
# bound_func has the signature that 'decorator' expects i.e. no
17+
# 'self' argument, but it is a closure over self so it can call
18+
# 'func' correctly.
19+
return decorator(bound_func)(*args, **kwargs)
20+
return wraps(func)(_wrapper)
21+
update_wrapper(_dec, decorator)
22+
# Change the name to aid debugging.
23+
_dec.__name__ = 'method_decorator(%s)' % decorator.__name__
24+
return _dec

0 commit comments

Comments
 (0)