Commit 763b0b12 authored by Tom Kunze's avatar Tom Kunze
Browse files

server: Store the room for each host

The CipMap can display in which room a user is sitting.

This uses a command to parse the map and store the room in the database.
parent 60672585
import json
from django.conf import settings
from django.core.management.base import BaseCommand
from server.models import Host, Room
class Command(BaseCommand):
help = 'Parses the map data and extracts the room for each host'
def handle(self, *args, **kwargs):
map_file = open(settings.MAP_PATH).read()
map_json = json.loads(map_file)
for map_room in map_json:
room_filtered = Room.objects.filter(name=map_room)
if len(room_filtered) == 1:
room = room_filtered[0]
else:
continue
for computer in map_json[map_room]['computer']:
host_filtered = Host.objects.filter(host_name=computer['id'])
if len(host_filtered) == 1:
host = host_filtered[0]
else:
continue
host.room = room
host.save()
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2019-06-05 13:32
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('server', '0024_room_temp_hosts'),
]
operations = [
migrations.AddField(
model_name='host',
name='room',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='server.Room'),
),
]
from django.db import models
class Room(models.Model):
name = models.CharField(max_length=255, primary_key=True) # e.g. cip2
name_long = models.CharField(max_length=255) # e.g. CIP2
name_number = models.CharField(max_length=255) # e.g. 02.151
numbers = models.CharField(max_length=255) # from UnivIS
temp_hosts = models.CharField(max_length=255, blank=True) # temperature
order = models.IntegerField()
class Meta:
ordering = ['order']
def __str__(self):
return self.name
class Host(models.Model):
'''
Current state of a CIP host.
'''
host_name = models.CharField(max_length=64, primary_key=True)
room = models.ForeignKey(Room, models.SET_NULL, null=True, blank=True)
last_update = models.DateTimeField(auto_now=True)
user_name = models.CharField(max_length=255, blank=True)
......@@ -22,21 +38,6 @@ class Host(models.Model):
self.user_idle)
class Room(models.Model):
name = models.CharField(max_length=255, primary_key=True) # e.g. cip2
name_long = models.CharField(max_length=255) # e.g. CIP2
name_number = models.CharField(max_length=255) # e.g. 02.151
numbers = models.CharField(max_length=255) # from UnivIS
temp_hosts = models.CharField(max_length=255, blank=True) # temperature
order = models.IntegerField()
class Meta:
ordering = ['order']
def __str__(self):
return self.name
class Exercise(models.Model):
name = models.CharField(max_length=255)
start = models.TimeField() # from univis
......
......@@ -371,7 +371,7 @@ table.privacyoverview td:first-child {
*/
.hidden {
display: none;
display: none !important;
}
.e-mail:before {
......
......@@ -114,6 +114,12 @@ function markCurrentMachine(hostname){
}
}
function markCurrentRoom(roomname) {
$('a.btn-room > i.material-icons').addClass('hidden');
$('a.btn-room[data-cip="' + roomname + '"] > i.material-icons')
.removeClass('hidden');
}
function isBarCollapsed(name) {
var collapsed = Cookies.get(name + '-collapsed');
if (collapsed === undefined) {
......@@ -239,11 +245,11 @@ function updateRoomNames() {
colloquial = colloquial == 'true';
}
if (colloquial) {
$('.colloquial').each(function(i, e) {
$('.colloquial > span').each(function(i, e) {
$(e).text($(e).data('long'));
});
} else {
$('.colloquial').each(function(i, e) {
$('.colloquial > span').each(function(i, e) {
$(e).text($(e).data('number'));
});
}
......@@ -558,7 +564,8 @@ function decorate(data){
setHostnameCookie(data.hostname);
//only set when hostname is known, otherwise an empty query breaks cipmap in vpn
}
markCurrentMachine(data.hostname)
markCurrentRoom(data.roomname);
markCurrentMachine(data.hostname);
}
......@@ -650,7 +657,8 @@ function decorateTutorData(data){
setLecture($(e.target).data('id'), $(e.target).text());
});
// Highlight current machine
// Highlight current room and machine
markCurrentRoom(data.roomname);
markCurrentMachine(data.hostname);
// Check lecture
......
{% for r in rooms %}
<li class="{% if room.name == r.name %}active{% endif %}">
<a class="colloquial btn-room" href="{% url 'index-room' r.name %}" data-cip="{{ r.name }}" data-long="{{ r.name_long }}" data-number="{{ r.name_number }}">
{{ r.name_number }}
<i class="material-icons left{% if ownroomname != r.name %} hidden{% endif %}">computer</i>
<span>{{ r.name_number }}</span>
</a>
</li>
{% endfor %}
......
......@@ -45,6 +45,21 @@ def remote_cip_hostname(request):
return ""
def remote_cip_roomname(request):
# stfucip for faui0dd
hostname = remote_cip_hostname(request)
host = None
roomname = None
try:
host = Host.objects.get(host_name=hostname)
roomname = None if host.room is None else host.room.name
except ObjectDoesNotExist:
pass
return roomname
def _get_rooms(public=True):
if public:
rooms = Room.objects.filter(order__gte=0)
......@@ -60,24 +75,40 @@ def index(request, room):
room = room_filtered[0]
else:
return redirect('index')
return render(request, 'server/index.html', {'room': room, 'rooms': _get_rooms()})
return render(request, 'server/index.html', {
'ownroomname': remote_cip_roomname(request),
'room': room,
'rooms': _get_rooms(),
})
@ensure_csrf_cookie
def optin(request):
return render(request, 'server/optin.html', {'rooms': _get_rooms()})
return render(request, 'server/optin.html', {
'ownroomname': remote_cip_roomname(request),
'rooms': _get_rooms(),
})
def faq(request):
return render(request, 'server/faq.html', {'rooms': _get_rooms()})
return render(request, 'server/faq.html', {
'ownroomname': remote_cip_roomname(request),
'rooms': _get_rooms(),
})
def privacypolicy(request):
return render(request, 'server/privacypolicy.html', {'rooms': _get_rooms()})
return render(request, 'server/privacypolicy.html', {
'ownroomname': remote_cip_roomname(request),
'rooms': _get_rooms(),
})
def legalnotice(request):
return render(request, 'server/legalnotice.html', {'rooms': _get_rooms()})
return render(request, 'server/legalnotice.html', {
'ownroomname': remote_cip_roomname(request),
'rooms': _get_rooms(),
})
def cipmap_beamer_user(request):
......@@ -92,9 +123,11 @@ def hosts(request):
if request.method == 'GET':
hostname = remote_cip_hostname(request)
roomname = remote_cip_roomname(request)
result = {
'hostname': hostname,
'roomname': roomname,
}
for host in Host.objects.all():
......
Supports Markdown
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