Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
Added ability to add decorators to view.
Browse files Browse the repository at this point in the history
the `decorate_with` tuple can be set on a view subclass or be passed
into the patterns method.  Any items in the tuple will be applied to the
view in the order they are given.
  • Loading branch information
rca committed Jul 31, 2013
1 parent f21fb78 commit bca2c10
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion resourceful/views.py
Expand Up @@ -33,6 +33,7 @@ class ResourceView(View):
url_prefix = None
template_dir = None
serialize_fields = None # When None default fields are serialized
decorate_with = () # Decorators for the view
query_map = {}

def __init__(self, **kwargs):
Expand Down Expand Up @@ -430,11 +431,12 @@ def patterns_for(cls, model_class=None, template_dir=None, url_prefix=None, **kw
cls.patterns(model_class=model_class, template_dir=template_dir, url_prefix=url_prefix, **kwargs)

@classmethod
def patterns(cls, model_class=None, template_dir=None, url_prefix=None, **kwargs):
def patterns(cls, model_class=None, template_dir=None, url_prefix=None, decorate_with=None, **kwargs):
# in case the model_class is defined in a subclass, but the parameter takes precedence anyway.
model_class = model_class or cls.model_class
url_prefix = url_prefix or cls.url_prefix
template_dir = template_dir or cls.template_dir
decorate_with = decorate_with or cls.decorate_with

if isinstance(model_class, six.string_types):
t_app_label, t_model_name = model_class.split('.', 1)
Expand Down Expand Up @@ -467,6 +469,10 @@ def patterns(cls, model_class=None, template_dir=None, url_prefix=None, **kwargs
**kwargs
)

# apply all decroators to the view
for decorator in decorate_with:
view = decorator(view)

urlpatterns = patterns(
'',

Expand Down

0 comments on commit bca2c10

Please sign in to comment.