add docstrings&updated docs

This commit is contained in:
Anton Zhyrney 2017-01-07 06:57:07 +02:00
parent fcae4a9f0a
commit 1317b1799c
2 changed files with 22 additions and 8 deletions

View File

@ -28,7 +28,7 @@ class SimpleView(HTTPMethodView):
def delete(self, request): def delete(self, request):
return text('I am delete method') return text('I am delete method')
app.add_route(SimpleView(), '/') app.add_route(SimpleView.as_view(), '/')
``` ```
@ -40,6 +40,19 @@ class NameView(HTTPMethodView):
def get(self, request, name): def get(self, request, name):
return text('Hello {}'.format(name)) return text('Hello {}'.format(name))
app.add_route(NameView(), '/<name>') app.add_route(NameView.as_view(), '/<name>')
```
If you want to add decorator for class, you could set decorators variable
```
class ViewWithDecorator(HTTPMethodView):
decorators = (some_decorator_here)
def get(self, request, name):
return text('Hello I have a decorator')
app.add_route(ViewWithDecorator.as_view(), '/url')
``` ```

View File

@ -7,7 +7,7 @@ class HTTPMethodView:
to every HTTP method you want to support. to every HTTP method you want to support.
For example: For example:
class DummyView(View): class DummyView(HTTPMethodView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
return text('I am get method') return text('I am get method')
@ -20,16 +20,16 @@ class HTTPMethodView:
405 response. 405 response.
If you need any url params just mention them in method definition: If you need any url params just mention them in method definition:
class DummyView(View): class DummyView(HTTPMethodView):
def get(self, request, my_param_here, *args, **kwargs): def get(self, request, my_param_here, *args, **kwargs):
return text('I am get method with %s' % my_param_here) return text('I am get method with %s' % my_param_here)
To add the view into the routing you could use To add the view into the routing you could use
1) app.add_route(DummyView(), '/') 1) app.add_route(DummyView.as_view(), '/')
2) app.route('/')(DummyView()) 2) app.route('/')(DummyView.as_view())
TODO: add doc about devorators To add any decorator you could set it into decorators variable
""" """
decorators = () decorators = ()
@ -44,7 +44,8 @@ class HTTPMethodView:
@classmethod @classmethod
def as_view(cls, *class_args, **class_kwargs): def as_view(cls, *class_args, **class_kwargs):
""" TODO: add docs """ Converts the class into an actual view function that can be used
with the routing system.
""" """
def view(*args, **kwargs): def view(*args, **kwargs):