forked from gregmuellegger/django-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yasuhisa Yamazaki
committed
Jun 18, 2014
1 parent
c44ca39
commit 4ca5521
Showing
2 changed files
with
17 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
from functools import wraps | ||
from django.views.decorators.cache import cache_page as _cache_page | ||
from django.utils.decorators import decorator_from_middleware | ||
from django_mobile.cache.middleware import CacheFlavourMiddleware | ||
|
||
from django_mobile.cache.middleware import CacheFlavourMiddleware, CacheFlavourRequestMiddleware, \ | ||
CacheFlavourResponseMiddleware | ||
|
||
__all__ = ('cache_page', 'vary_on_flavour') | ||
|
||
__all__ = ('cache_page', 'vary_on_flavour') | ||
|
||
vary_on_flavour = decorator_from_middleware(CacheFlavourMiddleware) | ||
vary_on_flavour_request = decorator_from_middleware(CacheFlavourRequestMiddleware) | ||
vary_on_flavour_response = decorator_from_middleware(CacheFlavourResponseMiddleware) | ||
|
||
|
||
def cache_page(*args, **kwargs): | ||
''' | ||
Same as django's ``cache_page`` decorator, but wraps the view into | ||
``vary_on_flavour`` decorator before. Makes it possible to serve multiple | ||
flavours without getting into trouble with django's caching that doesn't | ||
``vary_on_flavour_request`` and ``vary_on_flavour_response`` decorators. | ||
Makes it possible to serve multiple flavours without getting into trouble with django's caching that doesn't | ||
know about flavours. | ||
''' | ||
decorator = _cache_page(*args, **kwargs) | ||
|
||
def flavoured_decorator(func): | ||
return decorator(vary_on_flavour(func)) | ||
return vary_on_flavour_request(_cache_page(*args, **kwargs)(vary_on_flavour_response(func))) | ||
|
||
return flavoured_decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters