| 1 |
# -*- coding: utf-8 -*- |
| 2 |
from functools import wraps |
| 3 |
|
| 4 |
from django.utils.decorators import decorator_from_middleware |
| 5 |
|
| 6 |
from debreach.middleware import RandomCommentMiddleware |
| 7 |
|
| 8 |
|
| 9 |
append_random_comment = decorator_from_middleware(RandomCommentMiddleware) |
| 10 |
append_random_comment.__name__ = str('append_random_comment') |
| 11 |
append_random_comment.__doc__ = ''' |
| 12 |
Applies a random comment to the response of the decorated view in the same |
| 13 |
way as the RandomCommentMiddleware. Using both, or using the decorator |
| 14 |
multiple times is harmless and efficient. |
| 15 |
''' |
| 16 |
|
| 17 |
|
| 18 |
def random_comment_exempt(view_func): |
| 19 |
""" |
| 20 |
Marks a view as being exempt from having its response modified by the |
| 21 |
RandomCommentMiddleware |
| 22 |
""" |
| 23 |
def wrapped_view(*args, **kwargs): |
| 24 |
response = view_func(*args, **kwargs) |
| 25 |
response._random_comment_exempt = True |
| 26 |
return response |
| 27 |
return wraps(view_func)(wrapped_view) |