@@ -39,22 +39,40 @@ def is_treasurer(self) -> bool:
39
39
40
40
41
41
class Board (BaseModel ):
42
- start_on : date
42
+ start_on : date | None = None
43
43
members : list [BoardMember ]
44
44
45
45
model_config = {"extra" : "forbid" , "frozen" : True }
46
46
47
47
@property
48
- def years (self ) -> tuple [int , int ]:
48
+ def years (self ) -> tuple [int , int ] | tuple [None , None ]:
49
+ if self .start_on is None :
50
+ return None , None
49
51
start_year = self .start_on .year
50
52
return (start_year , start_year + BOARDS_MANDATE_LENGTH )
51
53
54
+ @property
55
+ def sort_key (self ):
56
+ # Boards without a start date sort as starting in the future
57
+ if self .start_on is None :
58
+ return (1 , None )
59
+ return (0 , self .start_on )
60
+
52
61
53
62
@cache
54
63
def load_boards (path : Path | str = BOARDS_CONFIG_PATH ) -> list [Board ]:
64
+ """Load all boards, including inactive ones"""
55
65
data = tomllib .loads (Path (path ).read_text ())
56
66
return sorted (
57
67
(Board (** board ) for board in data ["board" ]),
58
- key = attrgetter ("start_on" ),
68
+ key = attrgetter ('sort_key' ),
59
69
reverse = True ,
60
70
)
71
+
72
+ @cache
73
+ def load_current_board (path : Path | str = BOARDS_CONFIG_PATH ) -> Board :
74
+ """Load the board that is currently in power"""
75
+ return [
76
+ board for board in load_boards (path )
77
+ if board .start_on is not None
78
+ ][0 ]
0 commit comments