Removing calendar events

main
Bob Mottram 2022-12-17 17:49:54 +00:00
parent 4106000065
commit 6ed1c77158
3 changed files with 30 additions and 9 deletions

View File

@ -5064,8 +5064,17 @@ class PubServer(BaseHTTPRequestHandler):
if '&submitYes=' in remove_post_confirm_params:
remove_post_confirm_params = \
urllib.parse.unquote_plus(remove_post_confirm_params)
remove_message_id = \
remove_post_confirm_params.split('messageId=')[1]
if 'messageId=' in remove_post_confirm_params:
remove_message_id = \
remove_post_confirm_params.split('messageId=')[1]
elif 'eventid=' in remove_post_confirm_params:
remove_message_id = \
remove_post_confirm_params.split('eventid=')[1]
else:
self.send_response(400)
self.end_headers()
self.server.postreq_busy = False
return
if '&' in remove_message_id:
remove_message_id = remove_message_id.split('&')[0]
print('remove_message_id: ' + remove_message_id)

View File

@ -762,17 +762,26 @@ def remove_calendar_event(base_dir: str, nickname: str, domain: str,
if '/' in message_id:
message_id = message_id.replace('/', '#')
if not text_in_file(message_id, calendar_filename):
message_id = message_id.replace('#', '/')
if not text_in_file(message_id, calendar_filename):
return
lines_str = ''
try:
with open(calendar_filename, 'r', encoding='utf-8') as fp_cal:
lines_str = fp_cal.read()
except OSError:
print('EX: unable to read calendar file ' +
calendar_filename)
if not lines_str:
return
lines = None
with open(calendar_filename, 'r', encoding='utf-8') as fp_cal:
lines = fp_cal.readlines()
if not lines:
return
lines = lines_str.split('\n')
print('Removing calendar event: ' + message_id)
try:
with open(calendar_filename, 'w+', encoding='utf-8') as fp_cal:
for line in lines:
if message_id not in line:
fp_cal.write(line)
if message_id in line:
continue
fp_cal.write(line + '\n')
except OSError:
print('EX: unable to remove calendar event ' +
calendar_filename)

View File

@ -85,6 +85,9 @@ def html_calendar_delete_confirm(translate: {}, base_dir: str,
str(month_number) + '">\n'
delete_post_str += ' <input type="hidden" name="day" value="' + \
str(day_number) + '">\n'
if post_time:
delete_post_str += ' <input type="hidden" name="time" value="' + \
post_time + '">\n'
delete_post_str += \
' <input type="hidden" name="pageNumber" value="1">\n'
delete_post_str += \