Unverified Commit 9c7f490b authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Make delete() first deactivate committee memberships

See #11
parent 94d524c1
......@@ -153,6 +153,14 @@ class CommitteeMembership(models.Model):
self.until = None
super().save(*args, **kwargs)
def delete(self, *args, **kwargs):
"""Deactivates active memberships, deletes inactive ones"""
if self.is_active:
self.until = timezone.now().date()
self.save()
else:
super().delete(*args, **kwargs)
def __str__(self):
return "{} membership of {} since {}".format(self.member,
self.committee,
......
......@@ -11,15 +11,14 @@ from members.models import Member
class CommitteeMembersTest(TestCase):
fixtures = ['members.json', 'committees.json']
@classmethod
def setUpTestData(cls):
cls.testcie = Committee.objects.get(name='testcie1')
cls.testuser = Member.objects.get(pk=1)
cls.m = CommitteeMembership(committee=cls.testcie,
member=cls.testuser,
chair=False)
cls.m.save()
def setUp(self):
# Don't use setUpTestData because delete() will cause problems
self.testcie = Committee.objects.get(name='testcie1')
self.testuser = Member.objects.get(pk=1)
self.m = CommitteeMembership(committee=self.testcie,
member=self.testuser,
chair=False)
self.m.save()
def test_unique(self):
with self.assertRaises(IntegrityError):
......@@ -55,6 +54,13 @@ class CommitteeMembersTest(TestCase):
self.m.until = timezone.now().date().replace(year=1900)
self.assertFalse(self.m.is_active)
def test_delete(self):
self.m.delete()
self.assertIsNotNone(self.m.until)
self.assertIsNotNone(self.m.pk)
self.m.delete()
self.assertIsNone(self.m.pk)
class CommitteeMembersChairTest(TestCase):
fixtures = ['members.json', 'committees.json']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment