2016-08-06 10:37:36 +00:00
|
|
|
from django.shortcuts import get_object_or_404
|
2016-08-04 22:50:48 +00:00
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework.decorators import api_view
|
2016-08-05 18:01:23 +00:00
|
|
|
from rest_framework import viewsets
|
|
|
|
from rest_framework.decorators import detail_route
|
|
|
|
from rest_framework.decorators import list_route
|
2016-08-04 22:50:48 +00:00
|
|
|
|
|
|
|
from core.templatetags.renderer import markdown
|
2016-08-05 18:01:23 +00:00
|
|
|
from counter.models import Counter
|
2016-08-07 18:32:12 +00:00
|
|
|
from core.models import User, Group
|
|
|
|
from club.models import Club
|
2016-08-06 10:37:36 +00:00
|
|
|
from api.views import serializers
|
2016-08-07 18:32:12 +00:00
|
|
|
from api.views import RightManagedModelViewSet
|
2016-08-04 22:50:48 +00:00
|
|
|
|
|
|
|
@api_view(['GET'])
|
|
|
|
def RenderMarkdown(request):
|
|
|
|
"""
|
|
|
|
Render Markdown
|
|
|
|
"""
|
|
|
|
if request.method == 'GET':
|
|
|
|
return Response(markdown(request.GET['text']))
|
2016-08-05 18:01:23 +00:00
|
|
|
|
|
|
|
|
2016-08-07 18:32:12 +00:00
|
|
|
class CounterViewSet(RightManagedModelViewSet):
|
2016-08-05 18:01:23 +00:00
|
|
|
"""
|
2016-08-07 18:32:12 +00:00
|
|
|
Manage Counters (api/v1/counter/)
|
2016-08-05 18:01:23 +00:00
|
|
|
"""
|
|
|
|
|
2016-08-07 18:32:12 +00:00
|
|
|
serializer_class = serializers.CounterRead
|
2016-08-05 18:01:23 +00:00
|
|
|
queryset = Counter.objects.all()
|
|
|
|
|
|
|
|
@list_route()
|
|
|
|
def bar(self, request):
|
|
|
|
"""
|
2016-08-07 18:32:12 +00:00
|
|
|
Return all bars (api/v1/counter/bar/)
|
2016-08-05 18:01:23 +00:00
|
|
|
"""
|
2016-08-07 18:32:12 +00:00
|
|
|
self.queryset = self.queryset.filter(type="BAR")
|
2016-08-05 18:01:23 +00:00
|
|
|
serializer = self.get_serializer(self.queryset, many=True)
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
2016-08-07 18:32:12 +00:00
|
|
|
|
|
|
|
class UserViewSet(RightManagedModelViewSet):
|
|
|
|
"""
|
|
|
|
Manage Users (api/v1/user/)
|
|
|
|
"""
|
|
|
|
|
|
|
|
serializer_class = serializers.UserRead
|
|
|
|
queryset = User.objects.all()
|
|
|
|
|
|
|
|
|
|
|
|
class ClubViewSet(RightManagedModelViewSet):
|
|
|
|
"""
|
|
|
|
Manage Clubs (api/v1/club/)
|
|
|
|
"""
|
|
|
|
|
|
|
|
serializer_class = serializers.ClubRead
|
|
|
|
queryset = Club.objects.all()
|
|
|
|
|
|
|
|
class GroupViewSet(RightManagedModelViewSet):
|
|
|
|
"""
|
|
|
|
Manage Groups (api/v1/group/)
|
|
|
|
"""
|
|
|
|
|
|
|
|
serializer_class = serializers.GroupRead
|
|
|
|
queryset = Group.objects.all()
|