Skip to content
Merged

Rooms #787

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def class_detail_list(request):
"timeslot": clazz.timeslot,
"code": clazz.code,
"subject_abbr": clazz.subject.abbr,
"room": clazz.room.code if clazz.room else None,
"csv_link": reverse("download_csv_per_class", kwargs={"class_id": clazz.pk}),
"assignments": assignments,
"quizzes": quizzes,
Expand Down
15 changes: 15 additions & 0 deletions common/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
Expand Down Expand Up @@ -138,6 +139,20 @@ class SubmitAdmin(admin.ModelAdmin):
autocomplete_fields = ["assignment"]


class RoomForm(forms.ModelForm):
class Meta:
model = models.Room
fields = "__all__"
labels = {
"inbus_room_id": "INBUS room_id",
}


@admin.register(models.Room)
class RoomAdmin(admin.ModelAdmin):
form = RoomForm


admin.site.register(models.Task, TaskAdmin)
admin.site.register(models.Class, ClassAdmin)
admin.site.register(models.Submit, SubmitAdmin)
Expand Down
28 changes: 28 additions & 0 deletions common/migrations/0031_room_class_room.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.16 on 2025-12-09 12:45

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('common', '0030_llmreviewprompt_suggestedcomment'),
]

operations = [
migrations.CreateModel(
name='Room',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=30)),
('inbus_room_id', models.IntegerField()),
('capacity', models.IntegerField()),
],
),
migrations.AddField(
model_name='class',
name='room',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.room'),
),
]
15 changes: 15 additions & 0 deletions common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ def markdown(self):
return ""


class Room(models.Model):
code = models.CharField(
max_length=30
) # This is actually a string rather than a strict number itself
inbus_room_id = models.IntegerField()
capacity = models.IntegerField()

def __str__(self):
return f"{self.code} - {self.capacity} seats"


class Class(models.Model):
class Day(models.TextChoices):
MONDAY = "PO", "Monday"
Expand Down Expand Up @@ -153,6 +164,10 @@ class Day(models.TextChoices):
day = models.CharField(max_length=5, choices=Day.choices)
time = models.TimeField()

# Use SET_NULL so that if a room is deleted, the class remains but its room assignment is cleared.
# This is preferred over CASCADE or PROTECT since room assignments may change or be removed.
room = models.ForeignKey(Room, on_delete=models.SET_NULL, null=True, blank=True)

objects = ClassManager()

def __str__(self):
Expand Down
1 change: 1 addition & 0 deletions frontend/src/ClassDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ let showSummary = false;
</div>
<button class="float-start btn" on:click={() => (showStudentsList = !showStudentsList)}>
{clazz.subject_abbr}
{#if clazz.room}{clazz.room}{/if}
{clazz.timeslot}
{clazz.code}
{clazz.teacher_username}
Expand Down
5 changes: 4 additions & 1 deletion templates/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
</p>
{% endif %}

<!--OSY C/02/460-2016/05 PO 10:45 Olivka-->

{% for node in classes %}
<div class="card mb-2">
<div class="card-header"><h5 class="mb-0">{{ node.class }}</h5></div>
<div class="card-header"><h5 class="mb-0">{{ node.class.subject.abbr }} {{node.class.day }} {{node.class.time|date:"H:i" }},
{% if node.class.teacher %}{{ node.class.teacher.get_full_name }}{% else %}No teacher{% endif %}{% if node.class.room %}, Room: {{node.class.room.code }}{% endif %} ({{node.class.code }})</h5></div>
<div class="card-body">
{% if node.summary %}
<button class="btn btn-outline-info mb-1" data-bs-toggle="collapse"
Expand Down
Loading