Use contentMap in calendar events

main
Bob Mottram 2022-04-13 16:06:03 +01:00
parent cd02056588
commit 4d088eca0f
3 changed files with 36 additions and 19 deletions

View File

@ -16911,7 +16911,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain_full, self.server.domain_full,
self.server.text_mode_banner, self.server.text_mode_banner,
access_keys, access_keys,
False) False, self.server.system_language)
if msg: if msg:
msg = msg.encode('utf-8') msg = msg.encode('utf-8')
msglen = len(msg) msglen = len(msg)
@ -16952,12 +16952,17 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain_full, self.server.domain_full,
self.server.text_mode_banner, self.server.text_mode_banner,
access_keys, access_keys,
True).encode('utf-8') True,
msglen = len(msg) self.server.system_language)
self._set_headers('text/calendar', if msg:
msglen, cookie, calling_domain, msg = msg.encode('utf-8')
False) msglen = len(msg)
self._write(msg) self._set_headers('text/calendar',
msglen, cookie, calling_domain,
False)
self._write(msg)
else:
self._404()
fitness_performance(getreq_start_time, self.server.fitness, fitness_performance(getreq_start_time, self.server.fitness,
'_GET', 'icalendar shown', '_GET', 'icalendar shown',
self.server.debug) self.server.debug)
@ -18362,7 +18367,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.http_prefix, self.server.http_prefix,
curr_etag, curr_etag,
self.server.recent_dav_etags, self.server.recent_dav_etags,
self.server.domain_full) self.server.domain_full,
self.server.system_language)
elif endpoint_type == 'delete': elif endpoint_type == 'delete':
response_str = \ response_str = \
dav_delete_response(self.server.base_dir, dav_delete_response(self.server.base_dir,

View File

@ -228,7 +228,7 @@ def _event_text_match(content: str, text_match: str) -> bool:
def get_todays_events(base_dir: str, nickname: str, domain: str, def get_todays_events(base_dir: str, nickname: str, domain: str,
curr_year: int, curr_month_number: int, curr_year: int, curr_month_number: int,
curr_day_of_month: int, curr_day_of_month: int,
text_match: str) -> {}: text_match: str, system_language: str) -> {}:
"""Retrieves calendar events for today """Retrieves calendar events for today
Returns a dictionary of lists containing Event and Place activities Returns a dictionary of lists containing Event and Place activities
""" """
@ -268,8 +268,16 @@ def get_todays_events(base_dir: str, nickname: str, domain: str,
continue continue
if post_json_object.get('object'): if post_json_object.get('object'):
if post_json_object['object'].get('content'): content = None
content = post_json_object['object']['content'] if post_json_object['object'].get('contentMap'):
sys_lang = system_language
if post_json_object['object']['contentMap'].get(sys_lang):
content = \
post_json_object['object']['contentMap'][sys_lang]
if not content:
if post_json_object['object'].get('content'):
content = post_json_object['object']['content']
if content:
if not _event_text_match(content, text_match): if not _event_text_match(content, text_match):
continue continue
@ -465,14 +473,14 @@ def get_todays_events_icalendar(base_dir: str, nickname: str, domain: str,
year: int, month_number: int, year: int, month_number: int,
day_number: int, person_cache: {}, day_number: int, person_cache: {},
http_prefix: str, http_prefix: str,
text_match: str) -> str: text_match: str, system_language: str) -> str:
"""Returns today's events in icalendar format """Returns today's events in icalendar format
""" """
day_events = None day_events = None
events = \ events = \
get_todays_events(base_dir, nickname, domain, get_todays_events(base_dir, nickname, domain,
year, month_number, day_number, year, month_number, day_number,
text_match) text_match, system_language)
if events: if events:
if events.get(str(day_number)): if events.get(str(day_number)):
day_events = events[str(day_number)] day_events = events[str(day_number)]
@ -1010,7 +1018,7 @@ def dav_report_response(base_dir: str, nickname: str, domain: str,
depth: int, xml_str: str, depth: int, xml_str: str,
person_cache: {}, http_prefix: str, person_cache: {}, http_prefix: str,
curr_etag: str, recent_dav_etags: {}, curr_etag: str, recent_dav_etags: {},
domain_full: str) -> str: domain_full: str, system_language: str) -> str:
"""Returns the response to caldav REPORT """Returns the response to caldav REPORT
""" """
if '<c:calendar-query' not in xml_str or \ if '<c:calendar-query' not in xml_str or \
@ -1083,7 +1091,8 @@ def dav_report_response(base_dir: str, nickname: str, domain: str,
search_date.year, search_date.year,
search_date.month, search_date.month,
search_date.day, person_cache, search_date.day, person_cache,
http_prefix, text_match) http_prefix, text_match,
system_language)
events_href = \ events_href = \
http_prefix + '://' + domain_full + '/users/' + \ http_prefix + '://' + domain_full + '/users/' + \
nickname + '/calendar?year=' + \ nickname + '/calendar?year=' + \
@ -1201,7 +1210,8 @@ def dav_report_response(base_dir: str, nickname: str, domain: str,
get_todays_events_icalendar(base_dir, nickname, domain, get_todays_events_icalendar(base_dir, nickname, domain,
search_date.year, search_date.month, search_date.year, search_date.month,
search_date.day, person_cache, search_date.day, person_cache,
http_prefix, text_match) http_prefix, text_match,
system_language)
events_href = \ events_href = \
http_prefix + '://' + domain_full + '/users/' + \ http_prefix + '://' + domain_full + '/users/' + \
nickname + '/calendar?year=' + \ nickname + '/calendar?year=' + \

View File

@ -265,7 +265,7 @@ def html_calendar(person_cache: {}, css_cache: {}, translate: {},
base_dir: str, path: str, base_dir: str, path: str,
http_prefix: str, domain_full: str, http_prefix: str, domain_full: str,
text_mode_banner: str, access_keys: {}, text_mode_banner: str, access_keys: {},
icalendar: bool) -> str: icalendar: bool, system_language: str) -> str:
"""Show the calendar for a person """Show the calendar for a person
""" """
domain = remove_domain_port(domain_full) domain = remove_domain_port(domain_full)
@ -327,12 +327,13 @@ def html_calendar(person_cache: {}, css_cache: {}, translate: {},
day_number, day_number,
person_cache, person_cache,
http_prefix, http_prefix,
text_match) text_match,
system_language)
day_events = None day_events = None
events = \ events = \
get_todays_events(base_dir, nickname, domain, get_todays_events(base_dir, nickname, domain,
year, month_number, day_number, year, month_number, day_number,
text_match) text_match, system_language)
if events: if events:
if events.get(str(day_number)): if events.get(str(day_number)):
day_events = events[str(day_number)] day_events = events[str(day_number)]