Commit c2ccf630 authored by Sli's avatar Sli

Added counters in api

parent feb7b468
......@@ -5,6 +5,7 @@ from rest_framework import routers
# Router config
router = routers.DefaultRouter()
router.register(r'counter', CounterViewSet, base_name='api_counter')
urlpatterns = [
......@@ -13,4 +14,4 @@ urlpatterns = [
url(r'^login/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^markdown$', RenderMarkdown, name='api_markdown'),
]
\ No newline at end of file
]
from . import serializers
from rest_framework.response import Response
from rest_framework.decorators import api_view
from rest_framework import viewsets
from rest_framework.decorators import detail_route
from rest_framework.decorators import list_route
from django.shortcuts import get_object_or_404
from core.templatetags.renderer import markdown
from counter.models import Counter
@api_view(['GET'])
......@@ -11,3 +17,30 @@ def RenderMarkdown(request):
"""
if request.method == 'GET':
return Response(markdown(request.GET['text']))
class CounterViewSet(viewsets.ModelViewSet):
"""
Manage Counters (api/v1/counter)
"""
serializer_class = serializers.Counter
queryset = Counter.objects.all()
@list_route()
def bar(self, request):
"""
Return all counters (api/v1/counter/all)
"""
self.queryset = Counter.objects.filter(type="BAR")
serializer = self.get_serializer(self.queryset, many=True)
return Response(serializer.data)
@detail_route(methods=['GET'])
def id(self, request, pk=None):
"""
Get by id (api/v1/{nk}/id)
"""
self.queryset = get_object_or_404(Counter.objects.filter(id=pk))
serializer = self.get_serializer(self.queryset)
return Response(serializer.data)
from rest_framework import serializers
from counter.models import Counter
class Counter(serializers.ModelSerializer):
is_open = serializers.BooleanField(read_only=True)
class Meta:
model = Counter
fields = ('id', 'name', 'is_open')
......@@ -189,6 +189,12 @@ class Counter(models.Model):
bl = Counter.get_barmen_list(counter_id)
return bl[randrange(0, len(bl))]
def is_open(self):
response = False
if len(Counter.get_barmen_list(self.id)) > 0:
response = True
return response
class Refilling(models.Model):
"""
Handle the refilling
......
......@@ -29,6 +29,6 @@ urlpatterns = [
url(r'^accounting/', include('accounting.urls', namespace="accounting", app_name="accounting")),
url(r'^eboutic/', include('eboutic.urls', namespace="eboutic", app_name="eboutic")),
url(r'^launderette/', include('launderette.urls', namespace="launderette", app_name="launderette")),
url(r'^api/', include('api.urls', namespace="api", app_name="api")),
url(r'^api/v1/', include('api.urls', namespace="api", app_name="api")),
url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!!
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment