offline / django-annoying
This is django application that try to eliminate annoying things in Django framework.
Clone this repository (size: 42.7 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/offline/django-annoying/
| commit 18: | edd2c077e3a5 |
| parent 17: | 4bbeac205e75 |
| branch: | default |
decorators now doesnt eat docstring and names of decorated function
Changed (Δ508 bytes):
raw changeset »
annoying/decorators.py (17 lines added, 1 lines removed)
Up to file-list annoying/decorators.py:
| … | … | @@ -5,7 +5,21 @@ from django.db.models import signals as |
5 |
5 |
from django.http import HttpResponse |
6 |
6 |
from django.utils import simplejson |
7 |
7 |
|
8 |
__all__ = ['render_to', 'signals', 'ajax_request' |
|
8 |
__all__ = ['render_to', 'signals', 'ajax_request', 'autostrip'] |
|
9 |
||
10 |
||
11 |
try: |
|
12 |
from functools import wraps |
|
13 |
except ImportError: |
|
14 |
def wraps(wrapped, assigned=('__module__', '__name__', '__doc__'), |
|
15 |
updated=('__dict__',)): |
|
16 |
def inner(wrapper): |
|
17 |
for attr in assigned: |
|
18 |
setattr(wrapper, attr, getattr(wrapped, attr)) |
|
19 |
for attr in updated: |
|
20 |
getattr(wrapper, attr).update(getattr(wrapped, attr, {})) |
|
21 |
return wrapper |
|
22 |
return inner |
|
9 |
23 |
|
10 |
24 |
|
11 |
25 |
def render_to(template=None): |
| … | … | @@ -51,6 +65,7 @@ def render_to(template=None): |
51 |
65 |
|
52 |
66 |
""" |
53 |
67 |
def renderer(function): |
68 |
@wraps(function) |
|
54 |
69 |
def wrapper(request, *args, **kwargs): |
55 |
70 |
output = function(request, *args, **kwargs) |
56 |
71 |
if not isinstance(output, dict): |
| … | … | @@ -139,6 +154,7 @@ def ajax_request(func): |
139 |
154 |
news_titles = [entry.title for entry in news] |
140 |
155 |
return {'news_titles': news_titles} |
141 |
156 |
""" |
157 |
@wraps(function) |
|
142 |
158 |
def wrapper(request, *args, **kwargs): |
143 |
159 |
response = func(request, *args, **kwargs) |
144 |
160 |
if isinstance(response, dict): |
