From 1cbaf07caefe39ce0ad09cd9268dabbe714fa344 Mon Sep 17 00:00:00 2001 From: Florian Sorg Date: Sun, 7 May 2023 18:07:39 +0200 Subject: [PATCH] implement data structures for fallback, remove incompatible code --- .../migrations/0002_fallbackassignment.py | 23 +++++ shiftregister/fallback/models.py | 9 +- .../0002_calendar_needs_fallback.py | 18 ++++ shiftregister/importer/models.py | 1 + shiftregister/signage/admin.py | 3 - .../migrations/0002_delete_teambackup.py | 16 ++++ shiftregister/signage/models.py | 8 -- shiftregister/signage/urls.py | 7 +- shiftregister/signage/views.py | 89 ------------------- 9 files changed, 67 insertions(+), 107 deletions(-) create mode 100644 shiftregister/fallback/migrations/0002_fallbackassignment.py create mode 100644 shiftregister/importer/migrations/0002_calendar_needs_fallback.py create mode 100644 shiftregister/signage/migrations/0002_delete_teambackup.py diff --git a/shiftregister/fallback/migrations/0002_fallbackassignment.py b/shiftregister/fallback/migrations/0002_fallbackassignment.py new file mode 100644 index 0000000..1b69e37 --- /dev/null +++ b/shiftregister/fallback/migrations/0002_fallbackassignment.py @@ -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')), + ], + ), + ] diff --git a/shiftregister/fallback/models.py b/shiftregister/fallback/models.py index 17edcc0..410af37 100644 --- a/shiftregister/fallback/models.py +++ b/shiftregister/fallback/models.py @@ -1,4 +1,3 @@ -from django.db import models from shiftregister.app.models import * @@ -7,3 +6,11 @@ class TeamMember(models.Model): def __str__(self): 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}" diff --git a/shiftregister/importer/migrations/0002_calendar_needs_fallback.py b/shiftregister/importer/migrations/0002_calendar_needs_fallback.py new file mode 100644 index 0000000..516e901 --- /dev/null +++ b/shiftregister/importer/migrations/0002_calendar_needs_fallback.py @@ -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), + ), + ] diff --git a/shiftregister/importer/models.py b/shiftregister/importer/models.py index 46f0294..f2b4e35 100644 --- a/shiftregister/importer/models.py +++ b/shiftregister/importer/models.py @@ -4,6 +4,7 @@ from shiftregister.app.models import * class Calendar(models.Model): url = models.URLField(primary_key=True) + needs_fallback = models.BooleanField(default=False, editable=True) has_errors = models.BooleanField(default=False, editable=False) diff --git a/shiftregister/signage/admin.py b/shiftregister/signage/admin.py index 2ff2f34..694323f 100644 --- a/shiftregister/signage/admin.py +++ b/shiftregister/signage/admin.py @@ -1,4 +1 @@ from django.contrib import admin -from .models import TeamBackup - -admin.site.register(TeamBackup) diff --git a/shiftregister/signage/migrations/0002_delete_teambackup.py b/shiftregister/signage/migrations/0002_delete_teambackup.py new file mode 100644 index 0000000..e5c0f77 --- /dev/null +++ b/shiftregister/signage/migrations/0002_delete_teambackup.py @@ -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', + ), + ] diff --git a/shiftregister/signage/models.py b/shiftregister/signage/models.py index 8f1b2e3..aa53695 100644 --- a/shiftregister/signage/models.py +++ b/shiftregister/signage/models.py @@ -1,10 +1,2 @@ from django.db import models 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}" diff --git a/shiftregister/signage/urls.py b/shiftregister/signage/urls.py index 4796703..9578ebb 100644 --- a/shiftregister/signage/urls.py +++ b/shiftregister/signage/urls.py @@ -3,9 +3,4 @@ from django.urls import path from . import views app_name = "signage" -urlpatterns = [ - path("worklist", views.worklist, name="worklist"), - path("worklist/add/", views.add_teammember, name="work_add"), - path("worklist/remove/", views.remove_teammember, name="work_remove"), - path("terminal", views.terminal, name="terminal"), -] +urlpatterns = [] diff --git a/shiftregister/signage/views.py b/shiftregister/signage/views.py index 755e6fb..8b13789 100644 --- a/shiftregister/signage/views.py +++ b/shiftregister/signage/views.py @@ -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)