2018-10-13 08:41:51 +02:00
|
|
|
from typing import Any, Dict, List
|
2017-08-23 20:51:06 +02:00
|
|
|
|
2015-02-12 22:42:54 +01:00
|
|
|
from rest_framework.response import Response
|
2015-02-17 20:07:44 +01:00
|
|
|
from rest_framework.views import APIView as _APIView
|
2012-02-20 17:46:45 +01:00
|
|
|
|
2015-02-17 20:07:44 +01:00
|
|
|
|
2015-02-12 22:42:54 +01:00
|
|
|
class APIView(_APIView):
|
|
|
|
"""
|
|
|
|
The Django Rest framework APIView with improvements for OpenSlides.
|
|
|
|
"""
|
|
|
|
|
2018-08-22 22:00:08 +02:00
|
|
|
http_method_names: List[str] = []
|
2015-02-12 22:42:54 +01:00
|
|
|
"""
|
|
|
|
The allowed actions have to be explicitly defined.
|
|
|
|
|
|
|
|
Django allowes the following:
|
|
|
|
http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
|
|
|
|
"""
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def get_context_data(self, **context: Any) -> Dict[str, Any]:
|
2015-02-12 22:42:54 +01:00
|
|
|
"""
|
|
|
|
Returns the context for the response.
|
|
|
|
"""
|
|
|
|
return context
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def method_call(self, request: Any, *args: Any, **kwargs: Any) -> Any:
|
2015-02-12 22:42:54 +01:00
|
|
|
"""
|
|
|
|
Http method that returns the response object with the context data.
|
|
|
|
"""
|
|
|
|
return Response(self.get_context_data())
|
|
|
|
|
|
|
|
# Add the http-methods and delete the method "method_call"
|
|
|
|
get = post = put = patch = delete = head = options = trace = method_call
|
|
|
|
del method_call
|