webpage.py 929 Bytes
Newer Older
Lukas Burgey's avatar
Lukas Burgey committed
1

Lukas Burgey's avatar
Lukas Burgey committed
2
import logging
Lukas Burgey's avatar
Lukas Burgey committed
3

Lukas Burgey's avatar
Lukas Burgey committed
4
from django.urls import path
Lukas Burgey's avatar
Lukas Burgey committed
5
from rest_framework import status, generics
Lukas Burgey's avatar
Lukas Burgey committed
6
7
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
Lukas Burgey's avatar
Lukas Burgey committed
8

Lukas Burgey's avatar
Lukas Burgey committed
9
from feudal.backend.models import serializers
Lukas Burgey's avatar
Lukas Burgey committed
10
11

LOGGER = logging.getLogger(__name__)
Lukas Burgey's avatar
Lukas Burgey committed
12

Lukas Burgey's avatar
Lukas Burgey committed
13

Lukas Burgey's avatar
Lukas Burgey committed
14
15
def _api_error_response(error):
    return Response({'error': error}, status=status.HTTP_400_BAD_REQUEST)
Lukas Burgey's avatar
Lukas Burgey committed
16

Lukas Burgey's avatar
Lukas Burgey committed
17

Lukas Burgey's avatar
Lukas Burgey committed
18
def state_view_data(request):
19
    data = {
Lukas Burgey's avatar
Lukas Burgey committed
20
21
        'user': request.user,
        'session': request.session,
22
    }
Lukas Burgey's avatar
Lukas Burgey committed
23

Lukas Burgey's avatar
Lukas Burgey committed
24
25
    if 'msg' in request.session:
        data['msg'] = request.session.get('msg')
Lukas Burgey's avatar
Lukas Burgey committed
26

Lukas Burgey's avatar
Lukas Burgey committed
27
28
        # we display msg only once
        del request.session['msg']
Lukas Burgey's avatar
Lukas Burgey committed
29
30
    return data

31

32
class StateView(generics.RetrieveAPIView):
Lukas Burgey's avatar
Lukas Burgey committed
33
    permission_classes = (AllowAny,)
34
    serializer_class = serializers.StateSerializer
Lukas Burgey's avatar
Lukas Burgey committed
35

36
37
    def get_object(self):
        return state_view_data(self.request)
Lukas Burgey's avatar
Lukas Burgey committed
38
39


Lukas Burgey's avatar
Lukas Burgey committed
40
URLPATTERNS = [
41
    path('state/', StateView.as_view()),
Lukas Burgey's avatar
Lukas Burgey committed
42
]