From 909763c658b4fff1f7a1697669aa381197f3daee Mon Sep 17 00:00:00 2001 From: dk-15 Date: Fri, 26 May 2017 03:06:14 +0530 Subject: Add features and fix bugs - Fix sorting bug in bookings - Prevent admin access during ongoing experiment - Fix trashable bug in slot deletion - Show only online machines in test boards --- myadmin/views.py | 21 ++++++++++++++++----- slot/views.py | 2 +- templates/admin/testexp.html | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/myadmin/views.py b/myadmin/views.py index a15770b..9e9c314 100644 --- a/myadmin/views.py +++ b/myadmin/views.py @@ -2,9 +2,9 @@ from django.shortcuts import render, redirect from django.http import Http404,HttpResponse from django.contrib.auth.decorators import login_required from django.views.decorators.csrf import csrf_exempt -from sbhs_server.tables.models import Board, Booking +from sbhs_server.tables.models import Board, Booking, Slot from sbhs_server import settings,sbhs -import subprocess,json,serial,os +import subprocess,json,serial,os, datetime # Create your views here. def checkadmin(req): @@ -27,7 +27,7 @@ def toggle_allotment_mode(req): @login_required(redirect_field_name=None) def booking_index(req): checkadmin(req) - bookings = Booking.objects.order_by('-booking_date').select_related()[:50] + bookings = Booking.objects.order_by('-booking_date','-slot_id').filter(trashed_at__isnull=True).select_related()[:50] return render(req, 'admin/booking_index.html', {"bookings": bookings}) @login_required(redirect_field_name=None) @@ -78,9 +78,20 @@ def profile(req, mid): @login_required(redirect_field_name=None) def testing(req): checkadmin(req) - boards = Board.objects.order_by('online').all() + now = datetime.datetime.now() + current_slot_id = Slot.objects.filter(start_hour=now.hour, + start_minute__lt=now.minute, + end_minute__gt=now.minute) + + current_slot_id = -1 if not current_slot_id else current_slot_id[0].id + + current_bookings = Booking.objects.filter(slot_id=current_slot_id, + booking_date=datetime.date.today()).select_related() + current_mids = list([-1]) if not current_bookings else [current_booking.account.board.mid for current_booking in current_bookings] + + boards = Board.objects.filter(online=1) allotment_mode = "Random" if Board.can_do_random_allotment() else "Workshop" - return render(req, 'admin/testexp.html', {"boards": boards, "allotment_mode": allotment_mode}) + return render(req, 'admin/testexp.html', {"boards": boards, "allotment_mode": allotment_mode, "mids": current_mids}) @csrf_exempt def reset_device(req): diff --git a/slot/views.py b/slot/views.py index b137f93..5d22ac2 100644 --- a/slot/views.py +++ b/slot/views.py @@ -54,7 +54,7 @@ def create(req): @login_required(redirect_field_name=None) def index(req): - bookings = req.user.booking_set.select_related("slot").order_by("booking_date") + bookings = req.user.booking_set.select_related("slot").filter(trashed_at__isnull=True).order_by("booking_date") return render(req, "slot/index.html", {"bookings": reversed(bookings), "now_time": datetime.datetime.now()}) diff --git a/templates/admin/testexp.html b/templates/admin/testexp.html index 880f081..39291fa 100644 --- a/templates/admin/testexp.html +++ b/templates/admin/testexp.html @@ -2,6 +2,18 @@ {% load staticfiles %} {% block content %} +
{% include "account/sub_nav.html" %} @@ -15,6 +27,7 @@ Board MID Status + Occupied @@ -22,12 +35,13 @@ {{ b.mid }} {% if b.online %}Online{% else %}Offline{% endif %} + {% if b.mid in mids %}Ongoing{% else %}Vacant{% endif %} {% endfor %}
-
+

@@ -48,18 +62,29 @@
+
+ chal raha hain bhai +
+
-