Skip to content

Commit 5c50bac

Browse files
committed
Make dates non-optional; add has_started
1 parent 92fdc6b commit 5c50bac

File tree

6 files changed

+47
-41
lines changed

6 files changed

+47
-41
lines changed

docs/operations/boards.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Nově zvolený výbor
3737
* `@JakubDotPy <https://github.com/JakubDotPy>`_
3838
*
3939

40-
Výbor od 9.4.2022
40+
Výbor od 1.9.2022
4141
-------------------------------------------------
4242

4343
.. list-table::
@@ -62,7 +62,7 @@ Výbor od 9.4.2022
6262
* `@sairon <https://github.com/sairon>`_
6363
* |:moneybag:|
6464

65-
Výbor od 8.4.2019
65+
Výbor od 4.5.2019
6666
-------------------------------------------------
6767

6868
.. list-table::

docs/operations/boards.rst.jinja

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ Kanonickým zdrojem pravdy je ale `výpis na justice.cz <https://or.justice.cz/i
1212

1313

1414
{% for board in boards %}
15-
{%- if board.start_on == None %}
16-
Nově zvolený výbor
17-
------------------
18-
{%- else %}
15+
{%- if board.has_started %}
1916
Výbor od {{ board.start_on.strftime("%-d.%-m.%Y") }}
2017
-------------------------------------------------
18+
{%- else %}
19+
Nově zvolený výbor
20+
------------------
2121
{%- endif %}
2222

2323
.. list-table::

src/pyvec_docs/boards.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,47 +39,44 @@ def is_treasurer(self) -> bool:
3939

4040

4141
class Board(BaseModel):
42-
start_on: date | None = None
42+
start_on: date
4343
voted_on: date
44+
has_started: bool
4445
members: list[BoardMember]
4546

4647
model_config = {"extra": "forbid", "frozen": True}
4748

4849
@classmethod
49-
def make(cls, voted_on=None, start_on=None, **kwargs):
50-
if voted_on is None:
51-
voted_on = start_on
52-
return cls(voted_on=voted_on, start_on=start_on, **kwargs)
50+
def create(cls, voted_on=None, start_on=None, **kwargs):
51+
if start_on is None:
52+
start_on = voted_on
53+
has_started = False
54+
else:
55+
has_started = True
56+
return cls(
57+
voted_on=voted_on,
58+
start_on=start_on,
59+
has_started=has_started,
60+
**kwargs,
61+
)
5362

5463
@property
55-
def years(self) -> tuple[int, int] | tuple[None, None]:
56-
if self.start_on is None:
57-
return None, None
64+
def years(self) -> tuple[int, int]:
5865
start_year = self.start_on.year
5966
return (start_year, start_year + BOARDS_MANDATE_LENGTH)
6067

61-
@property
62-
def sort_key(self):
63-
# Boards without a start date sort as starting in the future
64-
if self.start_on is None:
65-
return (1, None)
66-
return (0, self.start_on)
67-
6868

6969
@cache
7070
def load_boards(path: Path | str = BOARDS_CONFIG_PATH) -> list[Board]:
7171
"""Load all boards, including inactive ones"""
7272
data = tomllib.loads(Path(path).read_text())
7373
return sorted(
74-
(Board.make(**board) for board in data["board"]),
75-
key=attrgetter('sort_key'),
74+
(Board.create(**board) for board in data["board"]),
75+
key=attrgetter('start_on'),
7676
reverse=True,
7777
)
7878

7979
@cache
8080
def load_current_board(path: Path | str = BOARDS_CONFIG_PATH) -> Board:
8181
"""Load the board that is currently in power"""
82-
return [
83-
board for board in load_boards(path)
84-
if board.start_on is not None
85-
][0]
82+
return next(board for board in load_boards(path) if board.has_started)

src/pyvec_docs/boards.toml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# The most recent board is first, previous boards are listed in descending order
33
# Each member has a `name`, `github`, and optionally a `roles` array
44
#
5-
# "start_on" should ideally be the date from justice.cz. If missing, the board
6-
# doesn't officially have power yet.
5+
# "voted_on" is the day when we voted for the board. It's approximate, since
6+
# votes can take longer than a day.
77
#
8-
# "voted_on" is the day when we voted for the board. If missing, defaults to
9-
# "start_on" as an approximation.
8+
# "start_on" should ideally be the date from justice.cz.
9+
# If the board doesn't officially have power yet, leave it out; "voted_on` will
10+
# be used as default.
1011

1112

1213
[[board]]
@@ -36,7 +37,8 @@ github = "JakubDotPy"
3637

3738

3839
[[board]]
39-
start_on = "2022-04-09"
40+
start_on = "2022-09-01"
41+
voted_on = "2022-04-09"
4042

4143
[[board.members]]
4244
name = "Barbora Drbohlavová"
@@ -63,7 +65,8 @@ roles = ["treasurer"]
6365

6466

6567
[[board]]
66-
start_on = "2019-04-08"
68+
start_on = "2019-05-04"
69+
voted_on = "2019-04-08"
6770

6871
[[board.members]]
6972
name = "Martin Bílek"
@@ -90,6 +93,7 @@ github = "whiskybar"
9093

9194
[[board]]
9295
start_on = "2012-03-27"
96+
voted_on = "2012-03-27" # approximation
9397

9498
[[board.members]]
9599
name = "Martin Bílek"

src/pyvec_docs/grants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def remove_comments(html):
1818

1919
def get_board_member_name(username, voted_at, boards: list[Board]):
2020
for board in boards: # sorted from the most recent
21-
if board.start_on is None:
21+
if not board.has_started:
2222
continue
2323
if voted_at > board.start_on:
2424
for member in board.members:

tests/test_scripts_generate_grants.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@pytest.fixture
1515
def boards():
1616
return [ # sorted!
17-
Board.make(
17+
Board.create(
1818
**{
1919
# No start_on; votes don't count
2020
"voted_on": date(2023, 1, 1),
@@ -23,16 +23,17 @@ def boards():
2323
],
2424
}
2525
),
26-
Board.make(
26+
Board.create(
2727
**{
2828
"start_on": date(2020, 1, 1),
29+
"voted_on": date(2019, 12, 1),
2930
"members": [
3031
{"name": "Alice", "github": "alice"},
3132
{"name": "Doubravka", "github": "doubravka"},
3233
],
3334
}
3435
),
35-
Board.make(
36+
Board.create(
3637
**{
3738
"start_on": date(2019, 1, 1),
3839
"voted_on": date(2018, 12, 1),
@@ -48,14 +49,18 @@ def assert_boards_sorted(boards):
4849
assert boards == sorted(boards)
4950

5051

51-
def assert_voted_on_defaults(boards):
52-
assert [b.voted_on for b in boards] == [
53-
date(2023, 1, 1), # explicit
54-
date(2020, 1, 1), # from start_on
52+
def assert_start_on_defaults(boards):
53+
assert [b.start_on for b in boards] == [
54+
date(2023, 1, 1), # from voted_on
55+
date(2020, 1, 1), # explicit
5556
date(2018, 12, 1), # explicit
5657
]
5758

5859

60+
def assert_started_values(boards):
61+
assert [b.start_on for b in boards] == [False, True, True]
62+
63+
5964
def test_to_date():
6065
assert to_date("2020-02-12T13:22:01Z") == date(2020, 2, 12)
6166

0 commit comments

Comments
 (0)