M
M
Maxim Vasiliev2014-09-29 08:34:27
Django
Maxim Vasiliev, 2014-09-29 08:34:27

How to pass a class method as a parameter to a class method decorator?

The layout is like this:

class Foo():
    @condition(last_modified_func=get_obj_mtime)
    def retrieve(self, request, *args, **kwargs):
        блаблабла

def condition(etag_func=None, last_modified_func=None):
    def decorator(func):
        @wraps(func, assigned=available_attrs(func))
        def inner(request, *args, **kwargs):
            # Get HTTP request headers
            блаблабла

The last_modified_func parameter must be passed to the method associated with the object, or at least the class.
What else is there to turn into?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentine, 2014-09-29
@vvpoloskin

What is not working now? At first glance, inner should have self as its first argument, which is an instance of the Foo class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question