Skip to content
Myr

Improved cbv and added tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent dcf2198 · Browse files · 1 file+15 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+15 added−5 removed

  • other:+15 added−5 removed

1 file+15 added−5 removed

modified:flask/views.py+15 added-5 removed
33 unmodified lines
3435 methods = None3637 def dispatch_request(self):38 """Subclasses have to override this method to implement the39 actual view functionc ode. This method is called with all40 the arguments from the URL rule.41 """42 raise NotImplementedError()4344 @classmethod45 def as_view(cls, name, *class_args, **class_kwargs):
5 unmodified lines
51 The arguments passed to :meth:`as_view` are forwarded to the52 constructor of the class.53 """54 def view(*args, **kwargs):51 self = cls(*class_args, **class_kwargs)55 self = view.view_class(*class_args, **class_kwargs)56 return self.dispatch_request(*args, **kwargs)57 # we attach the view class to the view function for two reasons:58 # first of all it allows us to easily figure out what class based59 # view this thing came from, secondly it's also used for instanciating60 # the view class so you can actually replace it with something else61 # for testing purposes and debugging.62 view.view_class = cls63 view.__name__ = name64 view.__doc__ = cls.__doc__65 view.__module__ = cls.__module__66 view.methods = cls.methods
3 unmodified lines
70class MethodViewType(type):7172 def __new__(cls, name, bases, d):73 rv = type.__new__(cls, name, bases, d)64 if rv.methods is None:65 methods = []74 if 'methods' not in d:75 methods = set(rv.methods or [])76 for key, value in d.iteritems():77 if key in http_method_funcs:68 methods.append(key.upper())78 methods.add(key.upper())79 # if we have no method at all in there we don't want to80 # add a method list. (This is for instance the case for81 # the baseclass or another subclass of a base method view82 # that does not introduce new methods).83 if methods:74 rv.methods = methods84 rv.methods = sorted(methods)85 return rv868788class MethodView(View):
24 unmodified lines