diff --git a/website/orders/api/v1/urls.py b/website/orders/api/v1/urls.py index 11c3a939..830be187 100644 --- a/website/orders/api/v1/urls.py +++ b/website/orders/api/v1/urls.py @@ -8,6 +8,7 @@ ProductListAPIView, ShiftRetrieveUpdateAPIView, OrderVenueListAPIView, + OrderVenueActiveShiftAPIView ) from orders.converters import ShiftConverter, OrderConverter @@ -26,4 +27,5 @@ path("shifts//scanner/", ShiftScannerAPIView.as_view(), name="shifts_scanner"), path("shifts//products/", ProductListAPIView.as_view(), name="product_list"), path("order-venues/", OrderVenueListAPIView.as_view(), name="ordervenues_list"), + path("order-venues//active-shift", OrderVenueActiveShiftAPIView.as_view(), name="ordervenues_activeshift"), ] diff --git a/website/orders/api/v1/views.py b/website/orders/api/v1/views.py index 5046aaea..de6cf4d7 100644 --- a/website/orders/api/v1/views.py +++ b/website/orders/api/v1/views.py @@ -32,6 +32,8 @@ from tosti.api.views import LoggedRetrieveUpdateAPIView, LoggedListCreateAPIView, LoggedRetrieveUpdateDestroyAPIView from tosti.utils import log_action +from orders.templatetags.start_shift import currently_active_shift_for_venue + class OrderListCreateAPIView(ListCreateAPIView): """API View to list and create orders.""" @@ -298,3 +300,16 @@ class OrderVenueListAPIView(ListAPIView): serializer_class = OrderVenueSerializer queryset = OrderVenue.objects.all() + +class OrderVenueActiveShiftAPIView(APIView): + """API View to retrieve the active shift""" + + serializer_class = ShiftSerializer + + def get(self, request, **kwargs): + shift = currently_active_shift_for_venue(kwargs.get("order_venue")) + + if shift: + return Response(status=status.HTTP_200_OK, data=self.serializer_class(shift).data) + else: + return Response(status=status.HTTP_404_NOT_FOUND) diff --git a/website/orders/templatetags/start_shift.py b/website/orders/templatetags/start_shift.py index 9a85309b..bb423df5 100644 --- a/website/orders/templatetags/start_shift.py +++ b/website/orders/templatetags/start_shift.py @@ -27,9 +27,9 @@ def currently_active_shift_for_venue(venue: OrderVenue): today = timezone.localize(datetime.now()) start = timezone.localize(datetime(today.year, today.month, today.day)) - if venue.shifts.filter(start__lte=today, end__gte=today).exists(): - return venue.shifts.filter(start__lte=today, end__gte=today).first() - elif venue.shifts.filter(end__gte=start).exists(): - return venue.shifts.filter(end__gte=start).order_by("-end").first() + if venue.shifts.filter(start__lte=today, end__gte=today, finalized=False).exists(): + return venue.shifts.filter(start__lte=today, end__gte=today, finalized=False).first() + elif venue.shifts.filter(end__gte=start, finalized=False).exists(): + return venue.shifts.filter(end__gte=start, finalized=False).order_by("-end").first() else: return None diff --git a/website/status_screen/static/status_screen/css/status-screen.css b/website/status_screen/static/status_screen/css/status-screen.css index f8816bbe..0ab1aacb 100644 --- a/website/status_screen/static/status_screen/css/status-screen.css +++ b/website/status_screen/static/status_screen/css/status-screen.css @@ -22,6 +22,10 @@ justify-content: center; } +.orders-ready li.user-order-item { + background-color: var(--success); +} + .user-order-list li .order-user-name { margin-right: 20px; } diff --git a/website/status_screen/templates/status_screen/status_screen.html b/website/status_screen/templates/status_screen/status_screen.html index d65879a5..0d036572 100644 --- a/website/status_screen/templates/status_screen/status_screen.html +++ b/website/status_screen/templates/status_screen/status_screen.html @@ -28,7 +28,7 @@

In progress

  • -
    ${user_orders_object.user.first_name}$
    +
    ${user_orders_object.user.first_name}$ ${user_orders_object.user.last_name}$
    • @@ -42,7 +42,7 @@

      In progress

      Ready

    • -
      ${user_orders_object.user.first_name}$
      +
      ${user_orders_object.user.first_name}$ ${user_orders_object.user.last_name}$
      • diff --git a/website/status_screen/templates/status_screen/venue_music_screen.html b/website/status_screen/templates/status_screen/venue_music_screen.html new file mode 100644 index 00000000..4a5b5394 --- /dev/null +++ b/website/status_screen/templates/status_screen/venue_music_screen.html @@ -0,0 +1,234 @@ +{% extends 'tosti/base.html' %} +{% load static players %} + +{% block styles %} + + +{% endblock %} + +{% block header %} + +{% endblock %} + +{% block page %} +
        +

        Currently playing:

        +
        + + +
        +{% endblock %} + +{% block footer %} + +{% endblock %} + +{% block js %} + +{% endblock %} \ No newline at end of file diff --git a/website/status_screen/templates/status_screen/venue_status_screen.html b/website/status_screen/templates/status_screen/venue_status_screen.html new file mode 100644 index 00000000..37cd53e5 --- /dev/null +++ b/website/status_screen/templates/status_screen/venue_status_screen.html @@ -0,0 +1,214 @@ +{% extends 'tosti/base.html' %} +{% load static %}#page-container + +{% block styles %} + +{% endblock %} + +{% block header %} + +{% endblock %} + +{% block page %} +
        +
        +
        +

        In progress

        + +
      • +
        ${user_orders_object.user.first_name}$ ${user_orders_object.user.last_name}$
        +
          +
        • + + +
        • +
        +
      • + + +
        +

        Ready

        + +
      • +
        ${user_orders_object.user.first_name}$ ${user_orders_object.user.last_name}$
        +
          +
        • + + +
        • +
        +
      • +
        +
        + + + +{% endblock %} + +{% block footer %} + +{% endblock %} + +{% block js %} + +{% endblock %} \ No newline at end of file diff --git a/website/status_screen/urls.py b/website/status_screen/urls.py index cc8d1313..10a78190 100644 --- a/website/status_screen/urls.py +++ b/website/status_screen/urls.py @@ -5,4 +5,5 @@ urlpatterns = [ path("redirect//", views.VenueRedirectView.as_view(), name="venue-redirect"), path("/", views.StatusScreen.as_view(), name="status"), + path("venue/", views.VenueStatusScreen.as_view(), name="venue-status") ] diff --git a/website/status_screen/views.py b/website/status_screen/views.py index 7196f1d6..75f89305 100644 --- a/website/status_screen/views.py +++ b/website/status_screen/views.py @@ -4,6 +4,8 @@ from django.views import View from django.views.generic import TemplateView +from thaliedje.models import Player + from orders.templatetags.start_shift import currently_active_shift_for_venue @@ -29,3 +31,21 @@ def get(self, request, **kwargs): raise Http404() else: return redirect(reverse("status_screen:status", kwargs={"shift": shift})) + +class VenueStatusScreen(View): + """Show music and active shift status of a venue.""" + + orders_template_name = "status_screen/venue_status_screen.html" + music_template_name = "status_screen/venue_music_screen.html" + + def get(self, request, **kwargs): + """GET request for the status screen of a venue.""" + order_venue = kwargs.get("order_venue") + active_shift = currently_active_shift_for_venue(order_venue) + + player = Player.objects.get(venue=order_venue.venue) + + if active_shift: + return render(request, self.orders_template_name, {"shift": active_shift, "order_venue": order_venue}) + else: + return render(request, self.music_template_name, {"player": player, "order_venue": order_venue})