From 9e6178b16f0e1944734b7ba15b05dd4a4f2a557d Mon Sep 17 00:00:00 2001
From: Tom Teichler <tom.teichler@teckids.org>
Date: Sat, 17 Dec 2022 12:37:25 +0000
Subject: [PATCH] Fix dashboard if user is connected to a DummyPerson

---
 aleksis/core/views.py | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/aleksis/core/views.py b/aleksis/core/views.py
index bbbe7cc18..ff4648c65 100644
--- a/aleksis/core/views.py
+++ b/aleksis/core/views.py
@@ -96,7 +96,6 @@ from .models import (
     DashboardWidget,
     DashboardWidgetOrder,
     DataCheckResult,
-    DummyPerson,
     Group,
     GroupType,
     OAuthApplication,
@@ -213,23 +212,27 @@ def index(request: HttpRequest) -> HttpResponse:
     if has_person(request.user):
         person = request.user.person
         widgets = person.dashboard_widgets
+        activities = person.activities.all().order_by("-created")[:5]
+        notifications = person.notifications.filter(send_at__lte=timezone.now()).order_by(
+            "-created"
+        )[:5]
+        unread_notifications = person.notifications.filter(
+            send_at__lte=timezone.now(), read=False
+        ).order_by("-created")
+        announcements = Announcement.objects.at_time().for_person(person)
+
     else:
-        person = DummyPerson()
+        person = None
+        activities = []
+        notifications = []
+        unread_notifications = []
         widgets = []
-
-    activities = person.activities.all().order_by("-created")[:5]
-    notifications = person.notifications.filter(send_at__lte=timezone.now()).order_by("-created")[
-        :5
-    ]
-    unread_notifications = person.notifications.filter(
-        send_at__lte=timezone.now(), read=False
-    ).order_by("-created")
+        announcements = []
 
     context["activities"] = activities
     context["notifications"] = notifications
     context["unread_notifications"] = unread_notifications
 
-    announcements = Announcement.objects.at_time().for_person(person)
     context["announcements"] = announcements
 
     if len(widgets) == 0:
-- 
GitLab