1212from couchers .proto .requests_pb2 import HostRequest
1313
1414
15+ HOST_REQUEST_ICS_FILENAME = "host_request.ics"
16+
17+
1518def create_host_request_attachment (
1619 host_request : HostRequest , other_name : str , hosting : bool , loc_context : LocalizationContext
1720) -> EmailAttachment :
1821 ics = create_host_request_ics (host_request , other_name , hosting , loc_context )
19- return ics_to_attachment (ics )
22+ return ics_to_attachment (ics , HOST_REQUEST_ICS_FILENAME )
2023
2124
2225def create_host_request_ics (
@@ -43,9 +46,11 @@ def create_host_request_event(
4346 "calendar_events.host_requests.title_surfer" , loc_context .locale , {"name" : other_name }
4447 )
4548
49+ # Our to_date is inclusive, iCalendar's DTEND is exclusive (for full-day events)
50+ # make_all_day will adjust the end date by one day accordingly.
4651 event .begin = host_request .from_date
4752 event .end = host_request .to_date
48- event .make_all_day () # Shifts the end date by one day
53+ event .make_all_day ()
4954
5055 event .location = host_request .hosting_city
5156 event .url = urls .host_request (host_request_id = str (host_request .host_request_id ))
@@ -60,7 +65,7 @@ def create_host_request_cancellation_attachment(
6065 host_request : HostRequest , other_name : str , hosting : bool , loc_context : LocalizationContext
6166) -> EmailAttachment :
6267 ics = create_host_request_cancellation_ics (host_request , other_name , hosting , loc_context )
63- return ics_to_attachment (ics )
68+ return ics_to_attachment (ics , HOST_REQUEST_ICS_FILENAME )
6469
6570
6671def create_host_request_cancellation_ics (
@@ -87,9 +92,9 @@ def event_to_ics(event: Event, loc_context: LocalizationContext) -> str:
8792 return cast (str , calendar .serialize ())
8893
8994
90- def ics_to_attachment (ics : str ) -> EmailAttachment :
95+ def ics_to_attachment (ics : str , filename : str ) -> EmailAttachment :
9196 return EmailAttachment (
92- filename = "host_request.ics" ,
97+ filename = filename ,
9398 mime_type = "text/calendar" ,
9499 data = ics .encode ("utf-8" ),
95100 )
0 commit comments