diff options
author | dk-15 | 2017-05-26 03:06:14 +0530 |
---|---|---|
committer | dk-15 | 2017-05-26 03:09:12 +0530 |
commit | 909763c658b4fff1f7a1697669aa381197f3daee (patch) | |
tree | 2b7805b3815c2ee07f286900bf58663f81129603 | |
parent | af581060fcb22ea5aa664e11f942e3fb108ed182 (diff) | |
download | SBHS-2018-Rpi-909763c658b4fff1f7a1697669aa381197f3daee.tar.gz SBHS-2018-Rpi-909763c658b4fff1f7a1697669aa381197f3daee.tar.bz2 SBHS-2018-Rpi-909763c658b4fff1f7a1697669aa381197f3daee.zip |
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
-rw-r--r-- | myadmin/views.py | 21 | ||||
-rw-r--r-- | slot/views.py | 2 | ||||
-rw-r--r-- | 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 %} +<style type="text/css"> + .highlight { + background-color: lightblue; + } + #test-device, #monitor-logs { + position: fixed; + right: 10%; + border: 1px slategray solid; + padding: 15px; + display: none; + } +</style> <div class="container"> <div class="row"> {% include "account/sub_nav.html" %} @@ -15,6 +27,7 @@ <tr> <th>Board MID</th> <th>Status</th> + <th>Occupied</th> </tr> </thead> <tbody> @@ -22,12 +35,13 @@ <tr> <td>{{ b.mid }}</td> <td><span class="label label-{% if b.online %}success{% else %}important{% endif %}">{% if b.online %}Online{% else %}Offline{% endif %}</span></td> + <td><span class="label label-{% if b.mid in mids %}important{% else %}success{% endif %}">{% if b.mid in mids %}Ongoing{% else %}Vacant{% endif %}</span></td> </tr> {% endfor %} </tbody> </table> </div> - <div class="span5" style="position: fixed;right: 10%; border: 1px slategray solid; padding: 15px;"> + <div id="test-device" class="span5"> <div> <input type="text" id="temp" disabled="true"><br/> <button class="btn btn-primary" onclick="getTemp()">Get Temperature</button> @@ -48,18 +62,29 @@ </div> + <div class="span5" id="monitor-logs"> + <span>chal raha hain bhai</span> + </div> + </div> </div> -<style type="text/css"> - .highlight { - background-color: lightblue; - } -</style> <script> var BASE_URL = window.location.origin; $("#tableId").on("click", "tr", function(e) { $("#tableId").find("tr.highlight").removeClass("highlight"); $(this).addClass("highlight"); + + columns = e.currentTarget.getElementsByTagName("td"); + isSelectedMachineVacant = columns[columns.length-1].childNodes[0].className.indexOf("label-success") > -1 + + if (isSelectedMachineVacant) { + $("#test-device").show(); + $("#monitor-logs").hide(); + } + else { + $("#monitor-logs").show(); + $("#test-device").hide(); + } }); function resetParams() { |