66
77from couchers import urls
88from couchers .config import config
9+ from couchers .context import CouchersContext
910from couchers .email .rendering import get_emails_i18next
10- from couchers .i18n import LocalizationContext
1111from couchers .proto .internal .jobs_pb2 import EmailAttachment
1212from couchers .proto .requests_pb2 import HostRequest
1313
1414HOST_REQUEST_ICS_FILENAME = "host_request.ics"
1515
1616
1717def create_host_request_attachment (
18- host_request : HostRequest , other_name : str , hosting : bool , loc_context : LocalizationContext
18+ host_request : HostRequest , other_name : str , hosting : bool , context : CouchersContext
1919) -> EmailAttachment :
20- ics = create_host_request_ics (host_request , other_name , hosting , loc_context )
20+ ics = create_host_request_ics (host_request , other_name , hosting , context )
2121 return ics_to_attachment (ics , HOST_REQUEST_ICS_FILENAME )
2222
2323
24- def create_host_request_ics (
25- host_request : HostRequest , other_name : str , hosting : bool , loc_context : LocalizationContext
26- ) -> str :
27- event = create_host_request_event (host_request , other_name , hosting , loc_context )
24+ def create_host_request_ics (host_request : HostRequest , other_name : str , hosting : bool , context : CouchersContext ) -> str :
25+ event = create_host_request_event (host_request , other_name , hosting , context )
2826
2927 # METHOD:PUBLISH means this is part of a stream of calendar event information.
3028 # It allows for later cancellation, and doesn't expose accept/decline functionality.
31- return event_to_ics (event , "PUBLISH" , loc_context )
29+ return event_to_ics (event , "PUBLISH" , context )
3230
3331
3432def create_host_request_event (
35- host_request : HostRequest , other_name : str , hosting : bool , loc_context : LocalizationContext , sequence : int = 0
33+ host_request : HostRequest , other_name : str , hosting : bool , context : CouchersContext , sequence : int = 0
3634) -> Event :
3735 """Creates an ics event for a host request."""
3836
@@ -44,11 +42,11 @@ def create_host_request_event(
4442
4543 if hosting :
4644 event .name = get_emails_i18next ().localize (
47- "calendar_events.host_requests.title_host" , loc_context .locale , {"name" : other_name }
45+ "calendar_events.host_requests.title_host" , context . localization .locale , {"name" : other_name }
4846 )
4947 else :
5048 event .name = get_emails_i18next ().localize (
51- "calendar_events.host_requests.title_surfer" , loc_context .locale , {"name" : other_name }
49+ "calendar_events.host_requests.title_surfer" , context . localization .locale , {"name" : other_name }
5250 )
5351
5452 # Our to_date is inclusive, iCalendar's DTEND is exclusive (for full-day events)
@@ -58,7 +56,7 @@ def create_host_request_event(
5856 event .make_all_day ()
5957
6058 event .location = host_request .hosting_city
61- event .url = urls .host_request (host_request_id = str (host_request .host_request_id ))
59+ event .url = urls .host_request (context , host_request_id = str (host_request .host_request_id ))
6260
6361 # Google Calendar™ will hide the URL if there is a location, so also include it in the description
6462 event .description = event .url
@@ -67,30 +65,30 @@ def create_host_request_event(
6765
6866
6967def create_host_request_cancellation_attachment (
70- host_request : HostRequest , other_name : str , hosting : bool , loc_context : LocalizationContext
68+ host_request : HostRequest , other_name : str , hosting : bool , context : CouchersContext
7169) -> EmailAttachment :
72- ics = create_host_request_cancellation_ics (host_request , other_name , hosting , loc_context )
70+ ics = create_host_request_cancellation_ics (host_request , other_name , hosting , context )
7371 return ics_to_attachment (ics , HOST_REQUEST_ICS_FILENAME )
7472
7573
7674def create_host_request_cancellation_ics (
77- host_request : HostRequest , other_name : str , hosting : bool , loc_context : LocalizationContext
75+ host_request : HostRequest , other_name : str , hosting : bool , context : CouchersContext
7876) -> str :
79- event = create_host_request_event (host_request , other_name , hosting , loc_context , sequence = 1 )
77+ event = create_host_request_event (host_request , other_name , hosting , context , sequence = 1 )
8078 event .name = get_emails_i18next ().localize (
81- "calendar_events.title_cancelled" , loc_context .locale , {"title" : event .name }
79+ "calendar_events.title_cancelled" , context . localization .locale , {"title" : event .name }
8280 )
8381 event .status = "CANCELLED"
8482
8583 # METHOD:PUBLISH means this is part of a stream of calendar event information.
8684 # Gmail™ will immediately remove the event from the user's calendar.
8785 # METHOD:CANCEL might leave the event in cancelled state or not work.
88- return event_to_ics (event , "PUBLISH" , loc_context )
86+ return event_to_ics (event , "PUBLISH" , context )
8987
9088
91- def event_to_ics (event : Event , method : str | None , loc_context : LocalizationContext ) -> str :
89+ def event_to_ics (event : Event , method : str | None , context : CouchersContext ) -> str :
9290 # PRODID is mandatory and generally follows "-//[Organization]//[Product Name]//[Language]"
93- calendar = Calendar (creator = f"-//Couchers.org//Couchers//{ loc_context .locale .upper ()} " )
91+ calendar = Calendar (creator = f"-//Couchers.org//Couchers//{ context . localization .locale .upper ()} " )
9492 if method :
9593 calendar .method = method
9694 calendar .events .add (event )
0 commit comments