mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 07:41:14 +00:00
Added counters in api
This commit is contained in:
parent
feb7b4689b
commit
c2ccf63021
@ -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'),
|
||||
|
||||
]
|
||||
]
|
||||
|
@ -1,7 +1,13 @@
|
||||
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)
|
||||
|
@ -1 +1,11 @@
|
||||
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!!!
|
||||
|
Loading…
Reference in New Issue
Block a user