Link events to SchedulerComponent
This commit is contained in:
@@ -4,6 +4,7 @@ from models import Event, EventMedia, EventType
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
import random
|
||||
|
||||
# .env laden
|
||||
load_dotenv()
|
||||
@@ -24,9 +25,11 @@ created_by = 1 # ID eines existierenden Users
|
||||
|
||||
# --- Alte Testdaten löschen ---
|
||||
# Zuerst alle EventMedia zu den Events dieses Clients löschen
|
||||
event_ids = [e.id for e in session.query(Event.id).filter_by(client_uuid=client_uuid).all()]
|
||||
event_ids = [e.id for e in session.query(
|
||||
Event.id).filter_by(client_uuid=client_uuid).all()]
|
||||
if event_ids:
|
||||
session.query(EventMedia).filter(EventMedia.event_id.in_(event_ids)).delete(synchronize_session=False)
|
||||
session.query(EventMedia).filter(EventMedia.event_id.in_(
|
||||
event_ids)).delete(synchronize_session=False)
|
||||
# Dann alle Events dieses Clients löschen
|
||||
session.query(Event).filter_by(client_uuid=client_uuid).delete()
|
||||
session.commit()
|
||||
@@ -34,13 +37,23 @@ session.commit()
|
||||
|
||||
now = datetime.now()
|
||||
|
||||
|
||||
def random_time_on_day(day_offset: int, duration_hours: int = 1):
|
||||
"""Erzeugt eine zufällige Start- und Endzeit zwischen 8 und 16 Uhr für einen Tag."""
|
||||
start_hour = random.randint(8, 15 - duration_hours + 1)
|
||||
start = (now + timedelta(days=day_offset)).replace(hour=start_hour,
|
||||
minute=0, second=0, microsecond=0)
|
||||
end = start + timedelta(hours=duration_hours)
|
||||
return start, end
|
||||
|
||||
|
||||
events = [
|
||||
Event(
|
||||
client_uuid=client_uuid,
|
||||
title="Mathe Präsentation",
|
||||
description="Präsentation zum Thema Algebra.",
|
||||
start=now + timedelta(days=1, hours=8),
|
||||
end=now + timedelta(days=1, hours=9),
|
||||
start=random_time_on_day(1)[0],
|
||||
end=random_time_on_day(1)[1],
|
||||
event_type=EventType.presentation,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -50,8 +63,8 @@ events = [
|
||||
client_uuid=client_uuid,
|
||||
title="Schulwebsite Update",
|
||||
description="Neue Inhalte auf der Schulwebsite.",
|
||||
start=now + timedelta(days=2, hours=10),
|
||||
end=now + timedelta(days=2, hours=11),
|
||||
start=random_time_on_day(2)[0],
|
||||
end=random_time_on_day(2)[1],
|
||||
event_type=EventType.website,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -61,8 +74,8 @@ events = [
|
||||
client_uuid=client_uuid,
|
||||
title="Lehrvideo ansehen",
|
||||
description="Video zum Thema Photosynthese.",
|
||||
start=now + timedelta(days=3, hours=9),
|
||||
end=now + timedelta(days=3, hours=10),
|
||||
start=random_time_on_day(3)[0],
|
||||
end=random_time_on_day(3)[1],
|
||||
event_type=EventType.video,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -72,8 +85,8 @@ events = [
|
||||
client_uuid=client_uuid,
|
||||
title="Nachricht vom Lehrer",
|
||||
description="Wichtige Mitteilung zum Unterricht.",
|
||||
start=now + timedelta(days=4, hours=13),
|
||||
end=now + timedelta(days=4, hours=14),
|
||||
start=random_time_on_day(4)[0],
|
||||
end=random_time_on_day(4)[1],
|
||||
event_type=EventType.message,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -83,8 +96,8 @@ events = [
|
||||
client_uuid=client_uuid,
|
||||
title="Sonstiges Event",
|
||||
description="Allgemeines Event ohne Kategorie.",
|
||||
start=now + timedelta(days=5, hours=11),
|
||||
end=now + timedelta(days=5, hours=12),
|
||||
start=random_time_on_day(5)[0],
|
||||
end=random_time_on_day(5)[1],
|
||||
event_type=EventType.other,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -94,8 +107,8 @@ events = [
|
||||
client_uuid=client_uuid,
|
||||
title="WebUntis Termin",
|
||||
description="Termin aus WebUntis importiert.",
|
||||
start=now + timedelta(days=6, hours=8),
|
||||
end=now + timedelta(days=6, hours=9),
|
||||
start=random_time_on_day(6)[0],
|
||||
end=random_time_on_day(6)[1],
|
||||
event_type=EventType.webuntis,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -105,8 +118,8 @@ events = [
|
||||
client_uuid=client_uuid,
|
||||
title="Englisch Präsentation",
|
||||
description="Präsentation zu Shakespeare.",
|
||||
start=now + timedelta(days=8, hours=10),
|
||||
end=now + timedelta(days=8, hours=11),
|
||||
start=random_time_on_day(8)[0],
|
||||
end=random_time_on_day(8)[1],
|
||||
event_type=EventType.presentation,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -116,8 +129,8 @@ events = [
|
||||
client_uuid=client_uuid,
|
||||
title="Website Relaunch",
|
||||
description="Vorstellung der neuen Schulwebsite.",
|
||||
start=now + timedelta(days=10, hours=9),
|
||||
end=now + timedelta(days=10, hours=10),
|
||||
start=random_time_on_day(10)[0],
|
||||
end=random_time_on_day(10)[1],
|
||||
event_type=EventType.website,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -127,8 +140,8 @@ events = [
|
||||
client_uuid=client_uuid,
|
||||
title="Videoanalyse",
|
||||
description="Analyse eines Lehrvideos.",
|
||||
start=now + timedelta(days=12, hours=14),
|
||||
end=now + timedelta(days=12, hours=15),
|
||||
start=random_time_on_day(12)[0],
|
||||
end=random_time_on_day(12)[1],
|
||||
event_type=EventType.video,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -138,8 +151,8 @@ events = [
|
||||
client_uuid=client_uuid,
|
||||
title="WebUntis Info",
|
||||
description="Weitere Termine aus WebUntis.",
|
||||
start=now + timedelta(days=14, hours=8),
|
||||
end=now + timedelta(days=14, hours=9),
|
||||
start=random_time_on_day(14)[0],
|
||||
end=random_time_on_day(14)[1],
|
||||
event_type=EventType.webuntis,
|
||||
created_by=created_by,
|
||||
updated_by=None,
|
||||
@@ -219,4 +232,4 @@ event_media = [
|
||||
for media in event_media:
|
||||
session.add(media)
|
||||
session.commit()
|
||||
print("Test-Events und EventMedia wurden angelegt.")
|
||||
print("Test-Events und EventMedia wurden angelegt.")
|
||||
|
||||
Reference in New Issue
Block a user