1
- from attrs import define
1
+ from attrs import define , field
2
2
import cattrs
3
3
4
4
from datetime import datetime
5
5
from typing import Optional , Dict , Any
6
6
7
7
from notubiz .api ._helpers import parse_date , get_attribute , get_title , get_description
8
+ from notubiz .api .document import Document , NotubizDocument
8
9
9
10
@define
10
11
class AgendaItem :
@@ -15,17 +16,28 @@ class AgendaItem:
15
16
start_date : Optional [datetime ]
16
17
end_date : Optional [datetime ]
17
18
is_heading : bool
19
+ documents : list [Document ]
20
+ agenda_items : list ['AgendaItem' ] = field (factory = list )
18
21
19
22
20
23
def get_start_date (attributes ) -> datetime :
21
- return parse_date (get_attribute (attributes , 82 ))
24
+ try :
25
+ return parse_date (get_attribute (attributes , 82 ))
26
+ except Exception : # The nested agenda items seem to have no start dates.
27
+ return None
22
28
23
29
def get_end_date (attributes ) -> datetime :
24
- return parse_date (get_attribute (attributes , 83 ))
25
-
30
+ try :
31
+ return parse_date (get_attribute (attributes , 83 ))
32
+ except Exception : # The nested agenda items seem to have no end dates.
33
+ return None
26
34
27
35
def agenda_item_structure_hook (data : Dict [str , Any ], cls : type ) -> AgendaItem :
28
- attributes = data ["type_data" ]["attributes" ]
36
+ type_data = data .get ("type_data" , {})
37
+ attributes = type_data ["attributes" ]
38
+
39
+ documents = [NotubizDocument .from_json (item ) for item in data ["documents" ]]
40
+ agenda_items = NotubizAgendaItems .from_json (data ["agenda_items" ])
29
41
30
42
return AgendaItem (
31
43
id = data ["id" ],
@@ -34,7 +46,9 @@ def agenda_item_structure_hook(data: Dict[str, Any], cls: type) -> AgendaItem:
34
46
description = get_description (attributes ),
35
47
start_date = get_start_date (attributes ),
36
48
end_date = get_end_date (attributes ),
37
- is_heading = data ["type_data" ]["heading" ]
49
+ is_heading = data ["type_data" ]["heading" ],
50
+ documents = documents ,
51
+ agenda_items = agenda_items
38
52
)
39
53
40
54
@@ -45,7 +59,7 @@ def from_json(json_object : any) -> list[AgendaItem]:
45
59
c .register_structure_hook (datetime , lambda date_string , _ : parse_date (date_string ))
46
60
c .register_structure_hook (AgendaItem , agenda_item_structure_hook )
47
61
48
- agenda_items = [c .structure (item , AgendaItem ) for item in json_object ]
62
+ agenda_items = [c .structure (item , AgendaItem ) for item in json_object ]
49
63
50
64
return agenda_items
51
65
0 commit comments