use election role name for membership description

This commit is contained in:
imperosol
2026-06-19 14:06:52 +02:00
parent 0ba001ccda
commit 8f15facd8f
2 changed files with 18 additions and 0 deletions
+4
View File
@@ -251,8 +251,12 @@ class ApplyElectionResultForm(forms.Form):
user_id=c.user_id,
club_id=c.role.club_role.club_id,
role=c.role.club_role,
description=(
c.role.title if c.role.title != c.role.club_role.name else ""
),
)
for c in candidates
]
Membership.objects.bulk_create(memberships)
Membership._add_club_groups(memberships)
return memberships
+14
View File
@@ -13,6 +13,7 @@ from pytest_django.asserts import assertRedirects
from club.models import Club, ClubRole, Membership
from core.baker_recipes import subscriber_user
from core.models import Group, User
from election.forms import ApplyElectionResultForm
from election.models import Candidature, Election, ElectionList, Role, Vote
@@ -155,6 +156,19 @@ class TestApplyResult(TestCase):
response = self.client.post(self.url, data={"candidates": ids})
assert response.status_code == 403
def test_membership_description(self):
"""Test that if club role name and election role name are different,
then the election role name is used as membership description.
"""
form = ApplyElectionResultForm(
election=self.election, data={"candidates": [self.candidatures[0].id]}
)
assert form.is_valid()
memberships = form.save()
assert len(memberships) == 1
assert memberships[0].role == self.club_roles[0]
assert memberships[0].description == "election role 1"
def test_no_result_to_apply(self):
self.election.roles.update(club_role=None)
user = baker.make(