From 19d9c25cb4f2ddce8e1029b4462eb3b64a0d1a99 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Sat, 5 Oct 2024 01:56:57 -0400 Subject: [PATCH] refactor: better errors and subscriber sticking --- intranet/apps/announcements/tests.py | 12 ++++++++++++ intranet/apps/eighth/views/admin/activities.py | 1 + intranet/apps/eighth/views/signup.py | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/intranet/apps/announcements/tests.py b/intranet/apps/announcements/tests.py index f49d5871d05..64e81702c31 100644 --- a/intranet/apps/announcements/tests.py +++ b/intranet/apps/announcements/tests.py @@ -6,6 +6,7 @@ from ...test.ion_test import IonTestCase from ...utils.date import get_senior_graduation_year +from ..eighth.models import EighthActivity from ..users.models import Group from .models import Announcement, AnnouncementRequest @@ -443,6 +444,17 @@ def test_hide_announcement_view(self): response = self.client.get(reverse("hide_announcement")) self.assertEqual(405, response.status_code) + def test_modify_club_announcement(self): + self.make_admin() + act = EighthActivity.objects.get_or_create(name="test")[0] + announce = Announcement.objects.get_or_create(title="test9", content="test9", activity=act)[0] + self.client.post( + reverse("modify_club_announcement", args=[announce.id]), + {"title": "hi", "content": "bye", "expiration_date": "3000-01-01"}, + ) + announce.refresh_from_db() + self.assertEqual(act, announce.activity) + class ApiTest(IonTestCase): def test_api_announcements_list(self): diff --git a/intranet/apps/eighth/views/admin/activities.py b/intranet/apps/eighth/views/admin/activities.py index d1fe7a6cf25..704bbcf5e39 100644 --- a/intranet/apps/eighth/views/admin/activities.py +++ b/intranet/apps/eighth/views/admin/activities.py @@ -150,6 +150,7 @@ def edit_activity_view(request, activity_id): activity = form.save() activity.subscribers.add(*[sponsor.user for sponsor in form.cleaned_data["sponsors"]]) + activity.subscribers.add(*form.cleaned_data["club_sponsors"], *form.cleaned_data["officers"]) activity.save() except forms.ValidationError as error: diff --git a/intranet/apps/eighth/views/signup.py b/intranet/apps/eighth/views/signup.py index 7b68adf8543..00e9cd35846 100644 --- a/intranet/apps/eighth/views/signup.py +++ b/intranet/apps/eighth/views/signup.py @@ -405,7 +405,8 @@ def unsubscribe_from_club(request, activity_id): activity = get_object_or_404(EighthActivity, id=activity_id) if activity.sponsors.filter(user=request.user).exists() or request.user in activity.club_sponsors.all(): - raise http.Http404 + messages.error(request, "You cannot unsubscribe from an activity you sponsor.") + return redirect("club_announcements") if request.user in activity.subscribers.all(): activity.subscribers.remove(request.user)