@@ -33,15 +33,23 @@ async def connect(self):
3333 return
3434 async with self .close_on_error ():
3535 site_id = int (self .scope ["url_route" ]["kwargs" ]["site_id" ])
36- site = await find_site (site_id , user )
36+ self . site : Site = await find_site (site_id , user )
3737
3838 # Listen for events for this site
3939 await self .channel_layer .group_add (
40- site .channels_group_name (),
40+ self . site .channels_group_name (),
4141 self .channel_name ,
4242 )
4343
4444 await self .accept ()
45+ await self .send_site_info (self .site )
46+
47+ async def operation_updated (self , event : dict [str , Any ]) -> None :
48+ """Handle an operation update event."""
49+ await self .send_site_info (self .site )
50+
51+ async def send_site_info (self , site : Site ) -> None :
52+ """Send the site information to the client."""
4553 info = await self .gather_site_info (site )
4654 await self .send (text_data = f"<code id='site-info'>\n { json .dumps (info , indent = 4 )} </code>" )
4755
@@ -74,21 +82,18 @@ def gather_site_info(self, site: Site) -> dict[str, Any]:
7482 "actions" : [],
7583 }
7684 for action in op .list_actions_in_order ():
77- operation_info ["actions" ].append (
78- {
79- "slug" : action .slug ,
80- "name" : action .name ,
81- "started_time" : (
82- action .started_time .isoformat ()
83- if action .started_time is not None
84- else None
85- ),
86- "result" : action .result ,
87- "user_message" : action .user_message ,
88- }
89- )
85+ action_info = {
86+ "slug" : action .slug ,
87+ "name" : action .name ,
88+ "started_time" : (
89+ action .started_time .isoformat () if action .started_time is not None else None
90+ ),
91+ "result" : action .result ,
92+ "user_message" : action .user_message ,
93+ }
9094 if self .scope ["user" ].is_superuser :
91- operation_info ["actions" ][- 1 ]["message" ] = action .message
95+ action_info ["message" ] = action .message
96+ operation_info ["actions" ].append (action_info )
9297
9398 info ["operation" ] = operation_info
9499
0 commit comments