Callable Class View

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class View(object):
    def __new__(cls, request, **kwargs):
        obj = super(View, cls).__new__(cls)
        return obj(request, **kwargs)
    
    def __init__(self):
        pass
        
    def __call__(self, request, **kwargs):
        pass

class GetPostView(View):
    def __call__(self, request, **kwargs):
        if request.POST:
            return self.Post(request, **kwargs)
        return self.Get(request, **kwargs)
    
    def Get(self, request, **kwargs):
        pass
        
    def Post(self, request, **kwargs):
        pass

More like this

  1. Simple views dispatcher by http methods by kmerenkov 2 years, 6 months ago
  2. Callable object as signal receiver by diverman 3 years, 1 month ago
  3. Ajax API class by kcarnold 3 years, 11 months ago
  4. Dynamically insert or append a value to an admin option, e.g. list_display or list_filter by frankban 9 months ago
  5. Language aware cache decorator by bartTC 3 years ago

Comments

mike_45 (on February 3, 2009):

Nice. Just what the doctor ordered.

#

(Forgotten your password?)