From 4c809b44fbeae1bb33a8d230067081da840a6716 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Tue, 9 Mar 2021 09:46:08 +0100
Subject: [PATCH] Fix action form usage

---
 aleksis/apps/alsijil/forms.py                    | 16 ++++++++--------
 .../templates/alsijil/class_register/person.html |  8 ++++----
 aleksis/apps/alsijil/views.py                    |  5 +++--
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/aleksis/apps/alsijil/forms.py b/aleksis/apps/alsijil/forms.py
index b529f99b2..4482d663d 100644
--- a/aleksis/apps/alsijil/forms.py
+++ b/aleksis/apps/alsijil/forms.py
@@ -173,6 +173,13 @@ class ExcuseTypeForm(forms.ModelForm):
         fields = ["short_name", "name"]
 
 
+class PersonOverviewForm(ActionForm):
+    def get_actions(self):
+        return [mark_as_excused, delete_personal_note] + [
+            mark_as_excuse_type_generator(excuse_type) for excuse_type in ExcuseType.objects.all()
+        ]
+
+
 class GroupRoleForm(forms.ModelForm):
     layout = Layout("name", "icon", "colour")
 
@@ -257,11 +264,4 @@ class GroupRoleAssignmentEditForm(forms.ModelForm):
     class Meta:
         model = GroupRoleAssignment
         fields = ["date_start", "date_end"]
-class PersonOverviewForm(ActionForm):
-    def get_actions(self):
-        return [
-            mark_as_excused,
-            delete_personal_note
-        ] + [
-            mark_as_excuse_type_generator(excuse_type) for excuse_type in ExcuseType.models.all()
-        ]
+
diff --git a/aleksis/apps/alsijil/templates/alsijil/class_register/person.html b/aleksis/apps/alsijil/templates/alsijil/class_register/person.html
index 30a08ac0c..a0041c196 100644
--- a/aleksis/apps/alsijil/templates/alsijil/class_register/person.html
+++ b/aleksis/apps/alsijil/templates/alsijil/class_register/person.html
@@ -148,10 +148,10 @@
     <h5>{% trans "Relevant personal notes" %}</h5>
   <form action="" method="post">
       {% csrf_token %}
-  {%  form form=action_form %}{% endform %}
-  <button type="submit">Enter</button>
-  </form>
-    {% render_table personal_notes_table %}
+      {% form form=action_form %}{% endform %}
+      <button type="submit" class="btn waves-effect waves-light">Enter</button>
+      {% render_table personal_notes_table %}
+    </form>
     <ul class="collapsible">
       <li>
         <div>
diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py
index d25c08336..19c0f19de 100644
--- a/aleksis/apps/alsijil/views.py
+++ b/aleksis/apps/alsijil/views.py
@@ -787,13 +787,14 @@ def overview_person(request: HttpRequest, id_: Optional[int] = None) -> HttpResp
     context["personal_notes"] = personal_notes
     context["excuse_types"] = ExcuseType.objects.all()
 
-    form = PersonOverviewForm(request, request.POST or None, queryset=personal_notes)
+    form = PersonOverviewForm(request, request.POST or None, queryset=PersonalNote.objects.all())
     if request.method == "POST":
         if form.is_valid():
             with reversion.create_revision():
                 reversion.set_user(request.user)
+                # FIXME CHECK PERMISSION
                 form.execute()
-        person.refresh_from_db()
+            person.refresh_from_db()
     context["action_form"] = form
     table = PersonalNoteTable(personal_notes)
     RequestConfig(request, paginate={"per_page": 20}).configure(table)
-- 
GitLab