implement data structures for fallback, remove incompatible code

pull/1/head
Florian Sorg 2 years ago
parent eb681d31b0
commit 1cbaf07cae

@ -0,0 +1,23 @@
# Generated by Django 4.0.4 on 2023-05-07 16:00
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('app', '0011_room_description'),
('fallback', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='FallbackAssignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('shift', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.shift')),
('team_member', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fallback.teammember')),
],
),
]

@ -1,4 +1,3 @@
from django.db import models
from shiftregister.app.models import * from shiftregister.app.models import *
@ -7,3 +6,11 @@ class TeamMember(models.Model):
def __str__(self): def __str__(self):
return f"{self.name}" return f"{self.name}"
class FallbackAssignment(models.Model):
shift = models.ForeignKey(Shift, on_delete=models.CASCADE)
team_member = models.ForeignKey(TeamMember, on_delete=models.CASCADE)
def __str__(self):
return f"{self.shift} {self.team_member.name}"

@ -0,0 +1,18 @@
# Generated by Django 4.0.4 on 2023-05-07 16:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('importer', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='calendar',
name='needs_fallback',
field=models.BooleanField(default=False),
),
]

@ -4,6 +4,7 @@ from shiftregister.app.models import *
class Calendar(models.Model): class Calendar(models.Model):
url = models.URLField(primary_key=True) url = models.URLField(primary_key=True)
needs_fallback = models.BooleanField(default=False, editable=True)
has_errors = models.BooleanField(default=False, editable=False) has_errors = models.BooleanField(default=False, editable=False)

@ -1,4 +1 @@
from django.contrib import admin from django.contrib import admin
from .models import TeamBackup
admin.site.register(TeamBackup)

@ -0,0 +1,16 @@
# Generated by Django 4.0.4 on 2023-05-07 16:00
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('signage', '0001_initial'),
]
operations = [
migrations.DeleteModel(
name='TeamBackup',
),
]

@ -1,10 +1,2 @@
from django.db import models from django.db import models
from shiftregister.app.models import * from shiftregister.app.models import *
class TeamBackup(models.Model):
shift = models.ForeignKey(Shift, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
def __str__(self):
return f"{self.shift} {self.name}"

@ -3,9 +3,4 @@ from django.urls import path
from . import views from . import views
app_name = "signage" app_name = "signage"
urlpatterns = [ urlpatterns = []
path("worklist", views.worklist, name="worklist"),
path("worklist/add/<int:shiftid>", views.add_teammember, name="work_add"),
path("worklist/remove/<int:pk>", views.remove_teammember, name="work_remove"),
path("terminal", views.terminal, name="terminal"),
]

@ -1,90 +1 @@
from django.shortcuts import render
from django.db.models import F, Count, Q, ExpressionWrapper
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from django.utils import timezone
from .models import TeamBackup
from .models import Shift
from .forms import TeamBackupForm
from datetime import timedelta
from django.db.models import DateTimeField
from datetime import date, datetime, time
# Create your views here.
@login_required
def worklist(request):
help_wanted = Q(required_helpers__gt=F("reg_count")) | Q(required_helpers=0) & Q(
room__required_helpers__gt=F("reg_count")
)
shifts = (
Shift.with_reg_count()
.annotate(
end_at=ExpressionWrapper(
F("start_at") + F("duration"),
output_field=DateTimeField(),
)
)
.filter(
help_wanted,
end_at__gte=timezone.now(),
deleted=False,
)
.order_by("start_at", "room_id")
)
context = {}
context["shifts"] = shifts
context["form"] = TeamBackupForm()
return render(request, "worklist.html", context)
@login_required
def add_teammember(request, shiftid):
if request.method != "POST":
return redirect("signage:worklist")
form = TeamBackupForm(request.POST)
if not form.is_valid():
return redirect("signage:worklist")
shift = get_object_or_404(Shift, pk=shiftid)
o = TeamBackup(shift=shift, name=form.cleaned_data["name"])
o.save()
p = request.GET.get("redir", None)
if p:
return redirect(p)
return redirect("signage:worklist")
@login_required
def remove_teammember(request, pk):
obj = get_object_or_404(TeamBackup, pk=pk)
sid = obj.shift.pk
obj.delete()
return redirect("team:shift", sid)
def terminal(request):
help_wanted = Q(required_helpers__gt=F("reg_count")) | Q(required_helpers=0) & Q(
room__required_helpers__gt=F("reg_count")
)
day = timezone.now() - timedelta(hours=6)
day = datetime.combine(day, time.min)
shifts = (
Shift.with_reg_count()
.annotate(
end_at=ExpressionWrapper(
F("start_at") + F("duration"),
output_field=DateTimeField(),
)
)
.filter(
help_wanted,
start_at__gte=day + timedelta(hours=5),
start_at__lte=day + timedelta(hours=29),
end_at__gte=timezone.now(),
deleted=False,
)
.order_by("start_at", "room_id")
)
context = {}
context["shifts"] = shifts
return render(request, "terminal.html", context)

Loading…
Cancel
Save