expose weather report as an rpc view
This commit is contained in:
parent
56d0e26c6d
commit
c0c0306419
@ -19,6 +19,7 @@ urlpatterns = [
|
||||
url(r'^karma/', include('karma.urls')),
|
||||
url(r'^markov/', include('markov.urls')),
|
||||
url(r'^races/', include('races.urls')),
|
||||
url(r'^weather/', include('weather.urls')),
|
||||
|
||||
url(r'^accounts/', include('registration.backends.default.urls')),
|
||||
url(r'^admin/', admin.site.urls),
|
||||
|
8
weather/urls.py
Normal file
8
weather/urls.py
Normal file
@ -0,0 +1,8 @@
|
||||
"""URL patterns for markov stuff."""
|
||||
from django.urls import path
|
||||
|
||||
from weather.views import rpc_weather_report
|
||||
|
||||
urlpatterns = [
|
||||
path('rpc/<query>/', rpc_weather_report, name='weather_rpc_query'),
|
||||
]
|
23
weather/views.py
Normal file
23
weather/views.py
Normal file
@ -0,0 +1,23 @@
|
||||
"""Manipulate Markov data via the Django site."""
|
||||
import logging
|
||||
|
||||
from rest_framework.authentication import BasicAuthentication
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import api_view, authentication_classes, permission_classes
|
||||
|
||||
from weather.lib import weather_summary
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@authentication_classes((BasicAuthentication, ))
|
||||
@permission_classes((IsAuthenticated, ))
|
||||
def rpc_weather_report(request, query):
|
||||
"""Provide the weather report for a given query."""
|
||||
if request.method != 'GET':
|
||||
return Response({'detail': "Supported method: GET."}, status=405)
|
||||
|
||||
report = weather_summary(query)
|
||||
return Response(report)
|
Loading…
Reference in New Issue
Block a user