Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
fd48ca3a
Verified
Commit
fd48ca3a
authored
Apr 30, 2017
by
Sébastiaan Versteeg
Browse files
Change uniqueness of boards to no overlap in period
parent
3164fc5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
website/activemembers/models.py
View file @
fd48ca3a
...
...
@@ -148,19 +148,20 @@ class Board(Committee):
def
validate_unique
(
self
,
*
args
,
**
kwargs
):
""" Check uniqueness"""
super
().
validate_unique
(
*
args
,
**
kwargs
)
if
self
.
since
is
not
None
and
self
.
until
is
not
None
:
for
board
in
Board
.
objects
.
filter
(
since__year
=
self
.
since
.
year
,
until__year
=
self
.
until
.
year
):
if
board
!=
self
:
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'
)})
elif
self
.
since
is
not
None
:
for
board
in
Board
.
objects
.
filter
(
since__lte
=
self
.
since
,
until__gte
=
self
.
since
):
if
board
!=
self
:
raise
ValidationError
({
'since'
:
_
(
'A board already exists for those years'
)})
class
ActiveMembershipManager
(
models
.
Manager
):
...
...
website/activemembers/tests.py
View file @
fd48ca3a
...
...
@@ -168,27 +168,52 @@ class BoardTest(TestCase):
self
.
testboard
.
since
=
None
self
.
testboard
.
validate_unique
()
def
test_unique_periods
(
self
):
Board
.
objects
.
create
(
name_nl
=
"testbe1"
,
name_en
=
"testbo1"
,
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
=
9
,
day
=
1
),
.
replace
(
year
=
1990
,
month
=
2
,
day
=
1
),
until
=
timezone
.
now
().
date
()
.
replace
(
year
=
199
1
,
month
=
9
,
day
=
1
)
.
replace
(
year
=
199
0
,
month
=
9
,
day
=
1
)
)
with
self
.
assertRaises
(
ValidationError
):
self
.
testboard
.
validate_unique
()
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
)
)
self
.
testboard
.
until
=
None
with
self
.
assertRaises
(
ValidationError
):
self
.
testboard
.
validate_unique
()
b
.
full_clean
()
self
.
testboard
.
since
=
None
self
.
testboard
.
validate_unique
()
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
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment