Commit 5a785fa4 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'fix/415-board-no-until' into 'master'

Fix saving board missing 'until' or 'since' values

Closes #415

See merge request !468
parents e3a14e0c fd48ca3a
......@@ -148,12 +148,20 @@ class Board(Committee):
def validate_unique(self, *args, **kwargs):
""" Check uniqueness"""
super().validate_unique(*args, **kwargs)
for board in Board.objects.filter(since__year=self.since.year,
until__year=self.until.year):
if board != self:
raise ValidationError({
'since': _('A board already exists for those years'),
'until': _('A board already exists for those years')})
boards = Board.objects.all()
if self.since is not None:
for board in boards:
if board.pk == self.pk:
continue
if ((board.until is None and (
self.until is None or self.until >= board.since)) or
(self.until is None and self.since <= board.until) or
(self.until and board.until and
self.since <= board.until and
self.until >= board.since)):
raise ValidationError({
'since': _('A board already exists for those years'),
'until': _('A board already exists for those years')})
class ActiveMembershipManager(models.Manager):
......
......@@ -161,5 +161,59 @@ class BoardTest(TestCase):
def setUp(self):
self.testboard = Board.objects.get(pk=3)
def test_validate_unique_works(self):
self.testboard.validate_unique()
self.testboard.until = None
self.testboard.validate_unique()
self.testboard.since = None
self.testboard.validate_unique()
def test_create_unique_period1(self):
""" Check uniqueness with since before period of testboard """
b = Board(
name_nl="testbe",
name_en="testbo",
contact_email="test@test.com",
description_nl="descnl",
description_en="descen",
since=timezone.now().date()
.replace(year=1990, month=2, day=1),
until=timezone.now().date()
.replace(year=1990, month=9, day=1)
)
with self.assertRaises(ValidationError):
b.full_clean()
b.until = b.until.replace(year=1990, month=8, day=31)
b.full_clean()
b.until = None
with self.assertRaises(ValidationError):
b.full_clean()
def test_create_unique_period2(self):
""" Check uniqueness with until after period of testboard """
b = Board(
name_nl="testbe",
name_en="testbo",
contact_email="test@test.com",
description_nl="descnl",
description_en="descen",
since=timezone.now().date()
.replace(year=1991, month=8, day=1),
until=timezone.now().date()
.replace(year=1992, month=9, day=1)
)
with self.assertRaises(ValidationError):
b.full_clean()
b.since = b.since.replace(year=1991, month=9, day=2)
b.full_clean()
b.until = None
b.full_clean()
def test_get_absolute_url(self):
self.testboard.get_absolute_url()
Supports Markdown
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