mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
fec1189d27
commit
9f0a12731a
|
@ -17,101 +17,101 @@ from webapp_utils import html_footer
|
||||||
|
|
||||||
|
|
||||||
def load_access_keys_for_accounts(base_dir: str, key_shortcuts: {},
|
def load_access_keys_for_accounts(base_dir: str, key_shortcuts: {},
|
||||||
access_keysTemplate: {}) -> None:
|
access_keys_template: {}) -> None:
|
||||||
"""Loads key shortcuts for each account
|
"""Loads key shortcuts for each account
|
||||||
"""
|
"""
|
||||||
for subdir, dirs, files in os.walk(base_dir + '/accounts'):
|
for _, dirs, _ in os.walk(base_dir + '/accounts'):
|
||||||
for acct in dirs:
|
for acct in dirs:
|
||||||
if not is_account_dir(acct):
|
if not is_account_dir(acct):
|
||||||
continue
|
continue
|
||||||
accountDir = os.path.join(base_dir + '/accounts', acct)
|
account_dir = os.path.join(base_dir + '/accounts', acct)
|
||||||
access_keysFilename = accountDir + '/access_keys.json'
|
access_keys_filename = account_dir + '/access_keys.json'
|
||||||
if not os.path.isfile(access_keysFilename):
|
if not os.path.isfile(access_keys_filename):
|
||||||
continue
|
continue
|
||||||
nickname = acct.split('@')[0]
|
nickname = acct.split('@')[0]
|
||||||
access_keys = load_json(access_keysFilename)
|
access_keys = load_json(access_keys_filename)
|
||||||
if access_keys:
|
if access_keys:
|
||||||
key_shortcuts[nickname] = access_keysTemplate.copy()
|
key_shortcuts[nickname] = access_keys_template.copy()
|
||||||
for variableName, key in access_keysTemplate.items():
|
for variable_name, _ in access_keys_template.items():
|
||||||
if access_keys.get(variableName):
|
if access_keys.get(variable_name):
|
||||||
key_shortcuts[nickname][variableName] = \
|
key_shortcuts[nickname][variable_name] = \
|
||||||
access_keys[variableName]
|
access_keys[variable_name]
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def html_access_keys(css_cache: {}, base_dir: str,
|
def html_access_keys(css_cache: {}, base_dir: str,
|
||||||
nickname: str, domain: str,
|
nickname: str, domain: str,
|
||||||
translate: {}, access_keys: {},
|
translate: {}, access_keys: {},
|
||||||
defaultAccessKeys: {},
|
default_access_keys: {},
|
||||||
default_timeline: str) -> str:
|
default_timeline: str) -> str:
|
||||||
"""Show and edit key shortcuts
|
"""Show and edit key shortcuts
|
||||||
"""
|
"""
|
||||||
access_keysFilename = \
|
access_keys_filename = \
|
||||||
acct_dir(base_dir, nickname, domain) + '/access_keys.json'
|
acct_dir(base_dir, nickname, domain) + '/access_keys.json'
|
||||||
if os.path.isfile(access_keysFilename):
|
if os.path.isfile(access_keys_filename):
|
||||||
access_keysFromFile = load_json(access_keysFilename)
|
access_keys_from_file = load_json(access_keys_filename)
|
||||||
if access_keysFromFile:
|
if access_keys_from_file:
|
||||||
access_keys = access_keysFromFile
|
access_keys = access_keys_from_file
|
||||||
|
|
||||||
access_keysForm = ''
|
access_keys_form = ''
|
||||||
css_filename = base_dir + '/epicyon-profile.css'
|
css_filename = base_dir + '/epicyon-profile.css'
|
||||||
if os.path.isfile(base_dir + '/epicyon.css'):
|
if os.path.isfile(base_dir + '/epicyon.css'):
|
||||||
css_filename = base_dir + '/epicyon.css'
|
css_filename = base_dir + '/epicyon.css'
|
||||||
|
|
||||||
instanceTitle = \
|
instance_title = \
|
||||||
get_config_param(base_dir, 'instanceTitle')
|
get_config_param(base_dir, 'instanceTitle')
|
||||||
access_keysForm = \
|
access_keys_form = \
|
||||||
html_header_with_external_style(css_filename, instanceTitle, None)
|
html_header_with_external_style(css_filename, instance_title, None)
|
||||||
access_keysForm += '<div class="container">\n'
|
access_keys_form += '<div class="container">\n'
|
||||||
|
|
||||||
access_keysForm += \
|
access_keys_form += \
|
||||||
' <h1>' + translate['Key Shortcuts'] + '</h1>\n'
|
' <h1>' + translate['Key Shortcuts'] + '</h1>\n'
|
||||||
access_keysForm += \
|
access_keys_form += \
|
||||||
'<p>' + translate['These access keys may be used'] + \
|
'<p>' + translate['These access keys may be used'] + \
|
||||||
'<label class="labels"></label></p>'
|
'<label class="labels"></label></p>'
|
||||||
|
|
||||||
access_keysForm += ' <form method="POST" action="' + \
|
access_keys_form += ' <form method="POST" action="' + \
|
||||||
'/users/' + nickname + '/changeAccessKeys">\n'
|
'/users/' + nickname + '/changeAccessKeys">\n'
|
||||||
|
|
||||||
timelineKey = access_keys['menuTimeline']
|
timeline_key = access_keys['menuTimeline']
|
||||||
submitKey = access_keys['submitButton']
|
submit_key = access_keys['submitButton']
|
||||||
access_keysForm += \
|
access_keys_form += \
|
||||||
' <center>\n' + \
|
' <center>\n' + \
|
||||||
' <button type="submit" class="button" ' + \
|
' <button type="submit" class="button" ' + \
|
||||||
'name="submitAccessKeysCancel" accesskey="' + timelineKey + '">' + \
|
'name="submitAccessKeysCancel" accesskey="' + timeline_key + '">' + \
|
||||||
translate['Go Back'] + '</button>\n' + \
|
translate['Go Back'] + '</button>\n' + \
|
||||||
' <button type="submit" class="button" ' + \
|
' <button type="submit" class="button" ' + \
|
||||||
'name="submitAccessKeys" accesskey="' + submitKey + '">' + \
|
'name="submitAccessKeys" accesskey="' + submit_key + '">' + \
|
||||||
translate['Submit'] + '</button>\n </center>\n'
|
translate['Submit'] + '</button>\n </center>\n'
|
||||||
|
|
||||||
access_keysForm += ' <table class="accesskeys">\n'
|
access_keys_form += ' <table class="accesskeys">\n'
|
||||||
access_keysForm += ' <colgroup>\n'
|
access_keys_form += ' <colgroup>\n'
|
||||||
access_keysForm += ' <col span="1" class="accesskeys-left">\n'
|
access_keys_form += ' <col span="1" class="accesskeys-left">\n'
|
||||||
access_keysForm += ' <col span="1" class="accesskeys-center">\n'
|
access_keys_form += ' <col span="1" class="accesskeys-center">\n'
|
||||||
access_keysForm += ' </colgroup>\n'
|
access_keys_form += ' </colgroup>\n'
|
||||||
access_keysForm += ' <tbody>\n'
|
access_keys_form += ' <tbody>\n'
|
||||||
|
|
||||||
for variableName, key in defaultAccessKeys.items():
|
for variable_name, key in default_access_keys.items():
|
||||||
if not translate.get(variableName):
|
if not translate.get(variable_name):
|
||||||
continue
|
continue
|
||||||
keyStr = '<tr>'
|
key_str = '<tr>'
|
||||||
keyStr += \
|
key_str += \
|
||||||
'<td><label class="labels">' + \
|
'<td><label class="labels">' + \
|
||||||
translate[variableName] + '</label></td>'
|
translate[variable_name] + '</label></td>'
|
||||||
if access_keys.get(variableName):
|
if access_keys.get(variable_name):
|
||||||
key = access_keys[variableName]
|
key = access_keys[variable_name]
|
||||||
if len(key) > 1:
|
if len(key) > 1:
|
||||||
key = key[0]
|
key = key[0]
|
||||||
keyStr += \
|
key_str += \
|
||||||
'<td><input type="text" ' + \
|
'<td><input type="text" ' + \
|
||||||
'name="' + variableName.replace(' ', '_') + '" ' + \
|
'name="' + variable_name.replace(' ', '_') + '" ' + \
|
||||||
'value="' + key + '">'
|
'value="' + key + '">'
|
||||||
keyStr += '</td></tr>\n'
|
key_str += '</td></tr>\n'
|
||||||
access_keysForm += keyStr
|
access_keys_form += key_str
|
||||||
|
|
||||||
access_keysForm += ' </tbody>\n'
|
access_keys_form += ' </tbody>\n'
|
||||||
access_keysForm += ' </table>\n'
|
access_keys_form += ' </table>\n'
|
||||||
access_keysForm += ' </form>\n'
|
access_keys_form += ' </form>\n'
|
||||||
access_keysForm += '</div>\n'
|
access_keys_form += '</div>\n'
|
||||||
access_keysForm += html_footer()
|
access_keys_form += html_footer()
|
||||||
return access_keysForm
|
return access_keys_form
|
||||||
|
|
|
@ -33,17 +33,18 @@ from webapp_utils import html_keyboard_navigation
|
||||||
|
|
||||||
def html_calendar_delete_confirm(css_cache: {}, translate: {}, base_dir: str,
|
def html_calendar_delete_confirm(css_cache: {}, translate: {}, base_dir: str,
|
||||||
path: str, http_prefix: str,
|
path: str, http_prefix: str,
|
||||||
domain_full: str, post_id: str, postTime: str,
|
domain_full: str, post_id: str,
|
||||||
year: int, monthNumber: int,
|
post_time: str,
|
||||||
dayNumber: int, calling_domain: str) -> str:
|
year: int, month_number: int,
|
||||||
|
day_number: int, calling_domain: str) -> str:
|
||||||
"""Shows a screen asking to confirm the deletion of a calendar event
|
"""Shows a screen asking to confirm the deletion of a calendar event
|
||||||
"""
|
"""
|
||||||
nickname = get_nickname_from_actor(path)
|
nickname = get_nickname_from_actor(path)
|
||||||
actor = local_actor_url(http_prefix, nickname, domain_full)
|
actor = local_actor_url(http_prefix, nickname, domain_full)
|
||||||
domain, port = get_domain_from_actor(actor)
|
domain, _ = get_domain_from_actor(actor)
|
||||||
messageId = actor + '/statuses/' + post_id
|
message_id = actor + '/statuses/' + post_id
|
||||||
|
|
||||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
post_filename = locate_post(base_dir, nickname, domain, message_id)
|
||||||
if not post_filename:
|
if not post_filename:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -51,199 +52,200 @@ def html_calendar_delete_confirm(css_cache: {}, translate: {}, base_dir: str,
|
||||||
if not post_json_object:
|
if not post_json_object:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
delete_postStr = None
|
delete_post_str = None
|
||||||
css_filename = base_dir + '/epicyon-profile.css'
|
css_filename = base_dir + '/epicyon-profile.css'
|
||||||
if os.path.isfile(base_dir + '/epicyon.css'):
|
if os.path.isfile(base_dir + '/epicyon.css'):
|
||||||
css_filename = base_dir + '/epicyon.css'
|
css_filename = base_dir + '/epicyon.css'
|
||||||
|
|
||||||
instanceTitle = \
|
instance_title = \
|
||||||
get_config_param(base_dir, 'instanceTitle')
|
get_config_param(base_dir, 'instanceTitle')
|
||||||
delete_postStr = \
|
delete_post_str = \
|
||||||
html_header_with_external_style(css_filename, instanceTitle, None)
|
html_header_with_external_style(css_filename, instance_title, None)
|
||||||
delete_postStr += \
|
delete_post_str += \
|
||||||
'<center><h1>' + postTime + ' ' + str(year) + '/' + \
|
'<center><h1>' + post_time + ' ' + str(year) + '/' + \
|
||||||
str(monthNumber) + \
|
str(month_number) + \
|
||||||
'/' + str(dayNumber) + '</h1></center>'
|
'/' + str(day_number) + '</h1></center>'
|
||||||
delete_postStr += '<center>'
|
delete_post_str += '<center>'
|
||||||
delete_postStr += ' <p class="followText">' + \
|
delete_post_str += ' <p class="followText">' + \
|
||||||
translate['Delete this event'] + '</p>'
|
translate['Delete this event'] + '</p>'
|
||||||
|
|
||||||
postActor = get_alt_path(actor, domain_full, calling_domain)
|
post_actor = get_alt_path(actor, domain_full, calling_domain)
|
||||||
delete_postStr += \
|
delete_post_str += \
|
||||||
' <form method="POST" action="' + postActor + '/rmpost">\n'
|
' <form method="POST" action="' + post_actor + '/rmpost">\n'
|
||||||
delete_postStr += ' <input type="hidden" name="year" value="' + \
|
delete_post_str += ' <input type="hidden" name="year" value="' + \
|
||||||
str(year) + '">\n'
|
str(year) + '">\n'
|
||||||
delete_postStr += ' <input type="hidden" name="month" value="' + \
|
delete_post_str += ' <input type="hidden" name="month" value="' + \
|
||||||
str(monthNumber) + '">\n'
|
str(month_number) + '">\n'
|
||||||
delete_postStr += ' <input type="hidden" name="day" value="' + \
|
delete_post_str += ' <input type="hidden" name="day" value="' + \
|
||||||
str(dayNumber) + '">\n'
|
str(day_number) + '">\n'
|
||||||
delete_postStr += \
|
delete_post_str += \
|
||||||
' <input type="hidden" name="pageNumber" value="1">\n'
|
' <input type="hidden" name="pageNumber" value="1">\n'
|
||||||
delete_postStr += \
|
delete_post_str += \
|
||||||
' <input type="hidden" name="messageId" value="' + \
|
' <input type="hidden" name="messageId" value="' + \
|
||||||
messageId + '">\n'
|
message_id + '">\n'
|
||||||
delete_postStr += \
|
delete_post_str += \
|
||||||
' <button type="submit" class="button" name="submitYes">' + \
|
' <button type="submit" class="button" name="submitYes">' + \
|
||||||
translate['Yes'] + '</button>\n'
|
translate['Yes'] + '</button>\n'
|
||||||
delete_postStr += \
|
delete_post_str += \
|
||||||
' <a href="' + actor + '/calendar?year=' + \
|
' <a href="' + actor + '/calendar?year=' + \
|
||||||
str(year) + '?month=' + \
|
str(year) + '?month=' + \
|
||||||
str(monthNumber) + '"><button class="button">' + \
|
str(month_number) + '"><button class="button">' + \
|
||||||
translate['No'] + '</button></a>\n'
|
translate['No'] + '</button></a>\n'
|
||||||
delete_postStr += ' </form>\n'
|
delete_post_str += ' </form>\n'
|
||||||
delete_postStr += '</center>\n'
|
delete_post_str += '</center>\n'
|
||||||
delete_postStr += html_footer()
|
delete_post_str += html_footer()
|
||||||
return delete_postStr
|
return delete_post_str
|
||||||
|
|
||||||
|
|
||||||
def _html_calendar_day(person_cache: {}, css_cache: {}, translate: {},
|
def _html_calendar_day(person_cache: {}, css_cache: {}, translate: {},
|
||||||
base_dir: str, path: str,
|
base_dir: str, path: str,
|
||||||
year: int, monthNumber: int, dayNumber: int,
|
year: int, month_number: int, day_number: int,
|
||||||
nickname: str, domain: str, dayEvents: [],
|
nickname: str, domain: str, day_events: [],
|
||||||
monthName: str, actor: str) -> str:
|
month_name: str, actor: str) -> str:
|
||||||
"""Show a day within the calendar
|
"""Show a day within the calendar
|
||||||
"""
|
"""
|
||||||
accountDir = acct_dir(base_dir, nickname, domain)
|
account_dir = acct_dir(base_dir, nickname, domain)
|
||||||
calendarFile = accountDir + '/.newCalendar'
|
calendar_file = account_dir + '/.newCalendar'
|
||||||
if os.path.isfile(calendarFile):
|
if os.path.isfile(calendar_file):
|
||||||
try:
|
try:
|
||||||
os.remove(calendarFile)
|
os.remove(calendar_file)
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: _html_calendar_day unable to delete ' + calendarFile)
|
print('EX: _html_calendar_day unable to delete ' + calendar_file)
|
||||||
|
|
||||||
css_filename = base_dir + '/epicyon-calendar.css'
|
css_filename = base_dir + '/epicyon-calendar.css'
|
||||||
if os.path.isfile(base_dir + '/calendar.css'):
|
if os.path.isfile(base_dir + '/calendar.css'):
|
||||||
css_filename = base_dir + '/calendar.css'
|
css_filename = base_dir + '/calendar.css'
|
||||||
|
|
||||||
calActor = actor
|
cal_actor = actor
|
||||||
if '/users/' in actor:
|
if '/users/' in actor:
|
||||||
calActor = '/users/' + actor.split('/users/')[1]
|
cal_actor = '/users/' + actor.split('/users/')[1]
|
||||||
|
|
||||||
instanceTitle = get_config_param(base_dir, 'instanceTitle')
|
instance_title = get_config_param(base_dir, 'instanceTitle')
|
||||||
calendarStr = \
|
calendar_str = \
|
||||||
html_header_with_external_style(css_filename, instanceTitle, None)
|
html_header_with_external_style(css_filename, instance_title, None)
|
||||||
calendarStr += '<main><table class="calendar">\n'
|
calendar_str += '<main><table class="calendar">\n'
|
||||||
calendarStr += '<caption class="calendar__banner--month">\n'
|
calendar_str += '<caption class="calendar__banner--month">\n'
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <a href="' + calActor + '/calendar?year=' + str(year) + \
|
' <a href="' + cal_actor + '/calendar?year=' + str(year) + \
|
||||||
'?month=' + str(monthNumber) + '">\n'
|
'?month=' + str(month_number) + '">\n'
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <h1>' + str(dayNumber) + ' ' + monthName + \
|
' <h1>' + str(day_number) + ' ' + month_name + \
|
||||||
'</h1></a><br><span class="year">' + str(year) + '</span>\n'
|
'</h1></a><br><span class="year">' + str(year) + '</span>\n'
|
||||||
calendarStr += '</caption>\n'
|
calendar_str += '</caption>\n'
|
||||||
calendarStr += '<tbody>\n'
|
calendar_str += '<tbody>\n'
|
||||||
|
|
||||||
if dayEvents:
|
if day_events:
|
||||||
for eventPost in dayEvents:
|
for event_post in day_events:
|
||||||
eventTime = None
|
event_time = None
|
||||||
eventDescription = None
|
event_description = None
|
||||||
eventPlace = None
|
event_place = None
|
||||||
post_id = None
|
post_id = None
|
||||||
senderName = ''
|
sender_name = ''
|
||||||
senderActor = None
|
sender_actor = None
|
||||||
eventIsPublic = False
|
event_is_public = False
|
||||||
# get the time place and description
|
# get the time place and description
|
||||||
for ev in eventPost:
|
for evnt in event_post:
|
||||||
if ev['type'] == 'Event':
|
if evnt['type'] == 'Event':
|
||||||
if ev.get('post_id'):
|
if evnt.get('post_id'):
|
||||||
post_id = ev['post_id']
|
post_id = evnt['post_id']
|
||||||
if ev.get('startTime'):
|
if evnt.get('startTime'):
|
||||||
eventDate = \
|
event_date = \
|
||||||
datetime.strptime(ev['startTime'],
|
datetime.strptime(evnt['startTime'],
|
||||||
"%Y-%m-%dT%H:%M:%S%z")
|
"%Y-%m-%dT%H:%M:%S%z")
|
||||||
eventTime = eventDate.strftime("%H:%M").strip()
|
event_time = event_date.strftime("%H:%M").strip()
|
||||||
if 'public' in ev:
|
if 'public' in evnt:
|
||||||
if ev['public'] is True:
|
if evnt['public'] is True:
|
||||||
eventIsPublic = True
|
event_is_public = True
|
||||||
if ev.get('sender'):
|
if evnt.get('sender'):
|
||||||
# get display name from sending actor
|
# get display name from sending actor
|
||||||
if ev.get('sender'):
|
if evnt.get('sender'):
|
||||||
senderActor = ev['sender']
|
sender_actor = evnt['sender']
|
||||||
dispName = \
|
disp_name = \
|
||||||
get_display_name(base_dir, senderActor,
|
get_display_name(base_dir, sender_actor,
|
||||||
person_cache)
|
person_cache)
|
||||||
if dispName:
|
if disp_name:
|
||||||
senderName = \
|
sender_name = \
|
||||||
'<a href="' + senderActor + '">' + \
|
'<a href="' + sender_actor + '">' + \
|
||||||
dispName + '</a>: '
|
disp_name + '</a>: '
|
||||||
if ev.get('name'):
|
if evnt.get('name'):
|
||||||
eventDescription = ev['name'].strip()
|
event_description = evnt['name'].strip()
|
||||||
elif ev['type'] == 'Place':
|
elif evnt['type'] == 'Place':
|
||||||
if ev.get('name'):
|
if evnt.get('name'):
|
||||||
eventPlace = ev['name']
|
event_place = evnt['name']
|
||||||
|
|
||||||
# prepend a link to the sender of the calendar item
|
# prepend a link to the sender of the calendar item
|
||||||
if senderName and eventDescription:
|
if sender_name and event_description:
|
||||||
# if the sender is also mentioned within the event
|
# if the sender is also mentioned within the event
|
||||||
# description then this is a reminder
|
# description then this is a reminder
|
||||||
senderActor2 = replace_users_with_at(senderActor)
|
sender_actor2 = replace_users_with_at(sender_actor)
|
||||||
if senderActor not in eventDescription and \
|
if sender_actor not in event_description and \
|
||||||
senderActor2 not in eventDescription:
|
sender_actor2 not in event_description:
|
||||||
eventDescription = senderName + eventDescription
|
event_description = sender_name + event_description
|
||||||
else:
|
else:
|
||||||
eventDescription = \
|
event_description = \
|
||||||
translate['Reminder'] + ': ' + eventDescription
|
translate['Reminder'] + ': ' + event_description
|
||||||
|
|
||||||
deleteButtonStr = ''
|
delete_button_str = ''
|
||||||
if post_id:
|
if post_id:
|
||||||
deleteButtonStr = \
|
delete_button_str = \
|
||||||
'<td class="calendar__day__icons"><a href="' + calActor + \
|
'<td class="calendar__day__icons"><a href="' + \
|
||||||
|
cal_actor + \
|
||||||
'/eventdelete?eventid=' + post_id + \
|
'/eventdelete?eventid=' + post_id + \
|
||||||
'?year=' + str(year) + \
|
'?year=' + str(year) + \
|
||||||
'?month=' + str(monthNumber) + \
|
'?month=' + str(month_number) + \
|
||||||
'?day=' + str(dayNumber) + \
|
'?day=' + str(day_number) + \
|
||||||
'?time=' + eventTime + \
|
'?time=' + event_time + \
|
||||||
'">\n<img class="calendardayicon" loading="lazy" alt="' + \
|
'">\n<img class="calendardayicon" loading="lazy" alt="' + \
|
||||||
translate['Delete this event'] + ' |" title="' + \
|
translate['Delete this event'] + ' |" title="' + \
|
||||||
translate['Delete this event'] + '" src="/' + \
|
translate['Delete this event'] + '" src="/' + \
|
||||||
'icons/delete.png" /></a></td>\n'
|
'icons/delete.png" /></a></td>\n'
|
||||||
|
|
||||||
eventClass = 'calendar__day__event'
|
event_class = 'calendar__day__event'
|
||||||
calItemClass = 'calItem'
|
cal_item_class = 'calItem'
|
||||||
if eventIsPublic:
|
if event_is_public:
|
||||||
eventClass = 'calendar__day__event__public'
|
event_class = 'calendar__day__event__public'
|
||||||
calItemClass = 'calItemPublic'
|
cal_item_class = 'calItemPublic'
|
||||||
if eventTime and eventDescription and eventPlace:
|
if event_time and event_description and event_place:
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
'<tr class="' + calItemClass + '">' + \
|
'<tr class="' + cal_item_class + '">' + \
|
||||||
'<td class="calendar__day__time"><b>' + eventTime + \
|
'<td class="calendar__day__time"><b>' + event_time + \
|
||||||
'</b></td><td class="' + eventClass + '">' + \
|
'</b></td><td class="' + event_class + '">' + \
|
||||||
'<span class="place">' + \
|
'<span class="place">' + \
|
||||||
eventPlace + '</span><br>' + eventDescription + \
|
event_place + '</span><br>' + event_description + \
|
||||||
'</td>' + deleteButtonStr + '</tr>\n'
|
'</td>' + delete_button_str + '</tr>\n'
|
||||||
elif eventTime and eventDescription and not eventPlace:
|
elif event_time and event_description and not event_place:
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
'<tr class="' + calItemClass + '">' + \
|
'<tr class="' + cal_item_class + '">' + \
|
||||||
'<td class="calendar__day__time"><b>' + eventTime + \
|
'<td class="calendar__day__time"><b>' + event_time + \
|
||||||
'</b></td><td class="' + eventClass + '">' + \
|
'</b></td><td class="' + event_class + '">' + \
|
||||||
eventDescription + '</td>' + deleteButtonStr + '</tr>\n'
|
event_description + '</td>' + delete_button_str + '</tr>\n'
|
||||||
elif not eventTime and eventDescription and not eventPlace:
|
elif not event_time and event_description and not event_place:
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
'<tr class="' + calItemClass + '">' + \
|
'<tr class="' + cal_item_class + '">' + \
|
||||||
'<td class="calendar__day__time">' + \
|
'<td class="calendar__day__time">' + \
|
||||||
'</td><td class="' + eventClass + '">' + \
|
'</td><td class="' + event_class + '">' + \
|
||||||
eventDescription + '</td>' + deleteButtonStr + '</tr>\n'
|
event_description + '</td>' + delete_button_str + '</tr>\n'
|
||||||
elif not eventTime and eventDescription and eventPlace:
|
elif not event_time and event_description and event_place:
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
'<tr class="' + calItemClass + '">' + \
|
'<tr class="' + cal_item_class + '">' + \
|
||||||
'<td class="calendar__day__time"></td>' + \
|
'<td class="calendar__day__time"></td>' + \
|
||||||
'<td class="' + eventClass + '"><span class="place">' + \
|
'<td class="' + event_class + '"><span class="place">' + \
|
||||||
eventPlace + '</span><br>' + eventDescription + \
|
event_place + '</span><br>' + event_description + \
|
||||||
'</td>' + deleteButtonStr + '</tr>\n'
|
'</td>' + delete_button_str + '</tr>\n'
|
||||||
elif eventTime and not eventDescription and eventPlace:
|
elif event_time and not event_description and event_place:
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
'<tr class="' + calItemClass + '">' + \
|
'<tr class="' + cal_item_class + '">' + \
|
||||||
'<td class="calendar__day__time"><b>' + eventTime + \
|
'<td class="calendar__day__time"><b>' + event_time + \
|
||||||
'</b></td><td class="' + eventClass + '">' + \
|
'</b></td><td class="' + event_class + '">' + \
|
||||||
'<span class="place">' + \
|
'<span class="place">' + \
|
||||||
eventPlace + '</span></td>' + \
|
event_place + '</span></td>' + \
|
||||||
deleteButtonStr + '</tr>\n'
|
delete_button_str + '</tr>\n'
|
||||||
|
|
||||||
calendarStr += '</tbody>\n'
|
calendar_str += '</tbody>\n'
|
||||||
calendarStr += '</table></main>\n'
|
calendar_str += '</table></main>\n'
|
||||||
calendarStr += html_footer()
|
calendar_str += html_footer()
|
||||||
|
|
||||||
return calendarStr
|
return calendar_str
|
||||||
|
|
||||||
|
|
||||||
def html_calendar(person_cache: {}, css_cache: {}, translate: {},
|
def html_calendar(person_cache: {}, css_cache: {}, translate: {},
|
||||||
|
@ -254,34 +256,34 @@ def html_calendar(person_cache: {}, css_cache: {}, translate: {},
|
||||||
"""
|
"""
|
||||||
domain = remove_domain_port(domain_full)
|
domain = remove_domain_port(domain_full)
|
||||||
|
|
||||||
monthNumber = 0
|
month_number = 0
|
||||||
dayNumber = None
|
day_number = None
|
||||||
year = 1970
|
year = 1970
|
||||||
actor = http_prefix + '://' + domain_full + path.replace('/calendar', '')
|
actor = http_prefix + '://' + domain_full + path.replace('/calendar', '')
|
||||||
if '?' in actor:
|
if '?' in actor:
|
||||||
first = True
|
first = True
|
||||||
for p in actor.split('?'):
|
for part in actor.split('?'):
|
||||||
if not first:
|
if not first:
|
||||||
if '=' in p:
|
if '=' in part:
|
||||||
if p.split('=')[0] == 'year':
|
if part.split('=')[0] == 'year':
|
||||||
numStr = p.split('=')[1]
|
num_str = part.split('=')[1]
|
||||||
if numStr.isdigit():
|
if num_str.isdigit():
|
||||||
year = int(numStr)
|
year = int(num_str)
|
||||||
elif p.split('=')[0] == 'month':
|
elif part.split('=')[0] == 'month':
|
||||||
numStr = p.split('=')[1]
|
num_str = part.split('=')[1]
|
||||||
if numStr.isdigit():
|
if num_str.isdigit():
|
||||||
monthNumber = int(numStr)
|
month_number = int(num_str)
|
||||||
elif p.split('=')[0] == 'day':
|
elif part.split('=')[0] == 'day':
|
||||||
numStr = p.split('=')[1]
|
num_str = part.split('=')[1]
|
||||||
if numStr.isdigit():
|
if num_str.isdigit():
|
||||||
dayNumber = int(numStr)
|
day_number = int(num_str)
|
||||||
first = False
|
first = False
|
||||||
actor = actor.split('?')[0]
|
actor = actor.split('?')[0]
|
||||||
|
|
||||||
currDate = datetime.now()
|
curr_date = datetime.now()
|
||||||
if year == 1970 and monthNumber == 0:
|
if year == 1970 and month_number == 0:
|
||||||
year = currDate.year
|
year = curr_date.year
|
||||||
monthNumber = currDate.month
|
month_number = curr_date.month
|
||||||
|
|
||||||
nickname = get_nickname_from_actor(actor)
|
nickname = get_nickname_from_actor(actor)
|
||||||
|
|
||||||
|
@ -292,179 +294,183 @@ def html_calendar(person_cache: {}, css_cache: {}, translate: {},
|
||||||
'January', 'February', 'March', 'April', 'May', 'June',
|
'January', 'February', 'March', 'April', 'May', 'June',
|
||||||
'July', 'August', 'September', 'October', 'November', 'December'
|
'July', 'August', 'September', 'October', 'November', 'December'
|
||||||
)
|
)
|
||||||
monthName = translate[months[monthNumber - 1]]
|
month_name = translate[months[month_number - 1]]
|
||||||
|
|
||||||
if dayNumber:
|
if day_number:
|
||||||
dayEvents = None
|
day_events = None
|
||||||
events = \
|
events = \
|
||||||
get_todays_events(base_dir, nickname, domain,
|
get_todays_events(base_dir, nickname, domain,
|
||||||
year, monthNumber, dayNumber)
|
year, month_number, day_number)
|
||||||
if events:
|
if events:
|
||||||
if events.get(str(dayNumber)):
|
if events.get(str(day_number)):
|
||||||
dayEvents = events[str(dayNumber)]
|
day_events = events[str(day_number)]
|
||||||
return _html_calendar_day(person_cache, css_cache,
|
return _html_calendar_day(person_cache, css_cache,
|
||||||
translate, base_dir, path,
|
translate, base_dir, path,
|
||||||
year, monthNumber, dayNumber,
|
year, month_number, day_number,
|
||||||
nickname, domain, dayEvents,
|
nickname, domain, day_events,
|
||||||
monthName, actor)
|
month_name, actor)
|
||||||
|
|
||||||
events = \
|
events = \
|
||||||
get_calendar_events(base_dir, nickname, domain, year, monthNumber)
|
get_calendar_events(base_dir, nickname, domain, year, month_number)
|
||||||
|
|
||||||
prevYear = year
|
prev_year = year
|
||||||
prevMonthNumber = monthNumber - 1
|
prev_month_number = month_number - 1
|
||||||
if prevMonthNumber < 1:
|
if prev_month_number < 1:
|
||||||
prevMonthNumber = 12
|
prev_month_number = 12
|
||||||
prevYear = year - 1
|
prev_year = year - 1
|
||||||
|
|
||||||
nextYear = year
|
next_year = year
|
||||||
nextMonthNumber = monthNumber + 1
|
next_month_number = month_number + 1
|
||||||
if nextMonthNumber > 12:
|
if next_month_number > 12:
|
||||||
nextMonthNumber = 1
|
next_month_number = 1
|
||||||
nextYear = year + 1
|
next_year = year + 1
|
||||||
|
|
||||||
print('Calendar year=' + str(year) + ' month=' + str(monthNumber) +
|
print('Calendar year=' + str(year) + ' month=' + str(month_number) +
|
||||||
' ' + str(week_day_of_month_start(monthNumber, year)))
|
' ' + str(week_day_of_month_start(month_number, year)))
|
||||||
|
|
||||||
if monthNumber < 12:
|
if month_number < 12:
|
||||||
daysInMonth = \
|
days_in_month = \
|
||||||
(date(year, monthNumber + 1, 1) - date(year, monthNumber, 1)).days
|
(date(year, month_number + 1, 1) -
|
||||||
|
date(year, month_number, 1)).days
|
||||||
else:
|
else:
|
||||||
daysInMonth = \
|
days_in_month = \
|
||||||
(date(year + 1, 1, 1) - date(year, monthNumber, 1)).days
|
(date(year + 1, 1, 1) - date(year, month_number, 1)).days
|
||||||
# print('daysInMonth ' + str(monthNumber) + ': ' + str(daysInMonth))
|
# print('days_in_month ' + str(month_number) + ': ' + str(days_in_month))
|
||||||
|
|
||||||
css_filename = base_dir + '/epicyon-calendar.css'
|
css_filename = base_dir + '/epicyon-calendar.css'
|
||||||
if os.path.isfile(base_dir + '/calendar.css'):
|
if os.path.isfile(base_dir + '/calendar.css'):
|
||||||
css_filename = base_dir + '/calendar.css'
|
css_filename = base_dir + '/calendar.css'
|
||||||
|
|
||||||
calActor = actor
|
cal_actor = actor
|
||||||
if '/users/' in actor:
|
if '/users/' in actor:
|
||||||
calActor = '/users/' + actor.split('/users/')[1]
|
cal_actor = '/users/' + actor.split('/users/')[1]
|
||||||
|
|
||||||
instanceTitle = \
|
instance_title = \
|
||||||
get_config_param(base_dir, 'instanceTitle')
|
get_config_param(base_dir, 'instanceTitle')
|
||||||
headerStr = \
|
header_str = \
|
||||||
html_header_with_external_style(css_filename, instanceTitle, None)
|
html_header_with_external_style(css_filename, instance_title, None)
|
||||||
|
|
||||||
# the main graphical calendar as a table
|
# the main graphical calendar as a table
|
||||||
calendarStr = '<main><table class="calendar">\n'
|
calendar_str = '<main><table class="calendar">\n'
|
||||||
calendarStr += '<caption class="calendar__banner--month">\n'
|
calendar_str += '<caption class="calendar__banner--month">\n'
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <a href="' + calActor + '/calendar?year=' + str(prevYear) + \
|
' <a href="' + cal_actor + '/calendar?year=' + str(prev_year) + \
|
||||||
'?month=' + str(prevMonthNumber) + '" ' + \
|
'?month=' + str(prev_month_number) + '" ' + \
|
||||||
'accesskey="' + access_keys['Page up'] + '">'
|
'accesskey="' + access_keys['Page up'] + '">'
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <img loading="lazy" alt="' + translate['Previous month'] + \
|
' <img loading="lazy" alt="' + translate['Previous month'] + \
|
||||||
'" title="' + translate['Previous month'] + '" src="/icons' + \
|
'" title="' + translate['Previous month'] + '" src="/icons' + \
|
||||||
'/prev.png" class="buttonprev"/></a>\n'
|
'/prev.png" class="buttonprev"/></a>\n'
|
||||||
calendarStr += ' <a href="' + calActor + '/inbox" title="'
|
calendar_str += ' <a href="' + cal_actor + '/inbox" title="'
|
||||||
calendarStr += translate['Switch to timeline view'] + '" ' + \
|
calendar_str += translate['Switch to timeline view'] + '" ' + \
|
||||||
'accesskey="' + access_keys['menuTimeline'] + '">'
|
'accesskey="' + access_keys['menuTimeline'] + '">'
|
||||||
calendarStr += ' <h1>' + monthName + '</h1></a>\n'
|
calendar_str += ' <h1>' + month_name + '</h1></a>\n'
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <a href="' + calActor + '/calendar?year=' + str(nextYear) + \
|
' <a href="' + cal_actor + '/calendar?year=' + str(next_year) + \
|
||||||
'?month=' + str(nextMonthNumber) + '" ' + \
|
'?month=' + str(next_month_number) + '" ' + \
|
||||||
'accesskey="' + access_keys['Page down'] + '">'
|
'accesskey="' + access_keys['Page down'] + '">'
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <img loading="lazy" alt="' + translate['Next month'] + \
|
' <img loading="lazy" alt="' + translate['Next month'] + \
|
||||||
'" title="' + translate['Next month'] + '" src="/icons' + \
|
'" title="' + translate['Next month'] + '" src="/icons' + \
|
||||||
'/prev.png" class="buttonnext"/></a>\n'
|
'/prev.png" class="buttonnext"/></a>\n'
|
||||||
calendarStr += '</caption>\n'
|
calendar_str += '</caption>\n'
|
||||||
calendarStr += '<thead>\n'
|
calendar_str += '<thead>\n'
|
||||||
calendarStr += '<tr>\n'
|
calendar_str += '<tr>\n'
|
||||||
days = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')
|
days = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')
|
||||||
for d in days:
|
for day in days:
|
||||||
calendarStr += ' <th scope="col" class="calendar__day__header">' + \
|
calendar_str += ' <th scope="col" class="calendar__day__header">' + \
|
||||||
translate[d] + '</th>\n'
|
translate[day] + '</th>\n'
|
||||||
calendarStr += '</tr>\n'
|
calendar_str += '</tr>\n'
|
||||||
calendarStr += '</thead>\n'
|
calendar_str += '</thead>\n'
|
||||||
calendarStr += '<tbody>\n'
|
calendar_str += '<tbody>\n'
|
||||||
|
|
||||||
# beginning of the links used for accessibility
|
# beginning of the links used for accessibility
|
||||||
nav_links = {}
|
nav_links = {}
|
||||||
timelineLinkStr = html_hide_from_screen_reader('🏠') + ' ' + \
|
timeline_link_str = html_hide_from_screen_reader('🏠') + ' ' + \
|
||||||
translate['Switch to timeline view']
|
translate['Switch to timeline view']
|
||||||
nav_links[timelineLinkStr] = calActor + '/inbox'
|
nav_links[timeline_link_str] = cal_actor + '/inbox'
|
||||||
|
|
||||||
dayOfMonth = 0
|
day_of_month = 0
|
||||||
dow = week_day_of_month_start(monthNumber, year)
|
dow = week_day_of_month_start(month_number, year)
|
||||||
for weekOfMonth in range(1, 7):
|
for week_of_month in range(1, 7):
|
||||||
if dayOfMonth == daysInMonth:
|
if day_of_month == days_in_month:
|
||||||
continue
|
continue
|
||||||
calendarStr += ' <tr>\n'
|
calendar_str += ' <tr>\n'
|
||||||
for dayNumber in range(1, 8):
|
for day_number in range(1, 8):
|
||||||
if (weekOfMonth > 1 and dayOfMonth < daysInMonth) or \
|
if (week_of_month > 1 and day_of_month < days_in_month) or \
|
||||||
(weekOfMonth == 1 and dayNumber >= dow):
|
(week_of_month == 1 and day_number >= dow):
|
||||||
dayOfMonth += 1
|
day_of_month += 1
|
||||||
|
|
||||||
isToday = False
|
is_today = False
|
||||||
if year == currDate.year:
|
if year == curr_date.year:
|
||||||
if currDate.month == monthNumber:
|
if curr_date.month == month_number:
|
||||||
if dayOfMonth == currDate.day:
|
if day_of_month == curr_date.day:
|
||||||
isToday = True
|
is_today = True
|
||||||
if events.get(str(dayOfMonth)):
|
if events.get(str(day_of_month)):
|
||||||
url = calActor + '/calendar?year=' + \
|
url = cal_actor + '/calendar?year=' + \
|
||||||
str(year) + '?month=' + \
|
str(year) + '?month=' + \
|
||||||
str(monthNumber) + '?day=' + str(dayOfMonth)
|
str(month_number) + '?day=' + str(day_of_month)
|
||||||
dayDescription = monthName + ' ' + str(dayOfMonth)
|
day_description = month_name + ' ' + str(day_of_month)
|
||||||
dayLink = '<a href="' + url + '" ' + \
|
day_link = '<a href="' + url + '" ' + \
|
||||||
'title="' + dayDescription + '">' + \
|
'title="' + day_description + '">' + \
|
||||||
str(dayOfMonth) + '</a>'
|
str(day_of_month) + '</a>'
|
||||||
# accessibility menu links
|
# accessibility menu links
|
||||||
menuOptionStr = \
|
menu_option_str = \
|
||||||
html_hide_from_screen_reader('📅') + ' ' + \
|
html_hide_from_screen_reader('📅') + ' ' + \
|
||||||
dayDescription
|
day_description
|
||||||
nav_links[menuOptionStr] = url
|
nav_links[menu_option_str] = url
|
||||||
# there are events for this day
|
# there are events for this day
|
||||||
if not isToday:
|
if not is_today:
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <td class="calendar__day__cell" ' + \
|
' <td class="calendar__day__cell" ' + \
|
||||||
'data-event="">' + \
|
'data-event="">' + \
|
||||||
dayLink + '</td>\n'
|
day_link + '</td>\n'
|
||||||
else:
|
else:
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <td class="calendar__day__cell" ' + \
|
' <td class="calendar__day__cell" ' + \
|
||||||
'data-today-event="">' + \
|
'data-today-event="">' + \
|
||||||
dayLink + '</td>\n'
|
day_link + '</td>\n'
|
||||||
else:
|
else:
|
||||||
# No events today
|
# No events today
|
||||||
if not isToday:
|
if not is_today:
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <td class="calendar__day__cell">' + \
|
' <td class="calendar__day__cell">' + \
|
||||||
str(dayOfMonth) + '</td>\n'
|
str(day_of_month) + '</td>\n'
|
||||||
else:
|
else:
|
||||||
calendarStr += \
|
calendar_str += \
|
||||||
' <td class="calendar__day__cell" ' + \
|
' <td class="calendar__day__cell" ' + \
|
||||||
'data-today="">' + str(dayOfMonth) + '</td>\n'
|
'data-today="">' + str(day_of_month) + '</td>\n'
|
||||||
else:
|
else:
|
||||||
calendarStr += ' <td class="calendar__day__cell"></td>\n'
|
calendar_str += ' <td class="calendar__day__cell"></td>\n'
|
||||||
calendarStr += ' </tr>\n'
|
calendar_str += ' </tr>\n'
|
||||||
|
|
||||||
calendarStr += '</tbody>\n'
|
calendar_str += '</tbody>\n'
|
||||||
calendarStr += '</table></main>\n'
|
calendar_str += '</table></main>\n'
|
||||||
|
|
||||||
# end of the links used for accessibility
|
# end of the links used for accessibility
|
||||||
nextMonthStr = \
|
next_month_str = \
|
||||||
html_hide_from_screen_reader('→') + ' ' + translate['Next month']
|
html_hide_from_screen_reader('→') + ' ' + translate['Next month']
|
||||||
nav_links[nextMonthStr] = calActor + '/calendar?year=' + str(nextYear) + \
|
nav_links[next_month_str] = \
|
||||||
'?month=' + str(nextMonthNumber)
|
cal_actor + '/calendar?year=' + str(next_year) + \
|
||||||
prevMonthStr = \
|
'?month=' + str(next_month_number)
|
||||||
|
prev_month_str = \
|
||||||
html_hide_from_screen_reader('←') + ' ' + translate['Previous month']
|
html_hide_from_screen_reader('←') + ' ' + translate['Previous month']
|
||||||
nav_links[prevMonthStr] = calActor + '/calendar?year=' + str(prevYear) + \
|
nav_links[prev_month_str] = \
|
||||||
'?month=' + str(prevMonthNumber)
|
cal_actor + '/calendar?year=' + str(prev_year) + \
|
||||||
|
'?month=' + str(prev_month_number)
|
||||||
nav_access_keys = {
|
nav_access_keys = {
|
||||||
}
|
}
|
||||||
screenReaderCal = \
|
screen_reader_cal = \
|
||||||
html_keyboard_navigation(text_mode_banner, nav_links, nav_access_keys,
|
html_keyboard_navigation(text_mode_banner, nav_links, nav_access_keys,
|
||||||
monthName)
|
month_name)
|
||||||
|
|
||||||
newEventStr = \
|
new_event_str = \
|
||||||
'<br><center>\n<p>\n' + \
|
'<br><center>\n<p>\n' + \
|
||||||
'<a href="' + calActor + '/newreminder">➕ ' + \
|
'<a href="' + cal_actor + '/newreminder">➕ ' + \
|
||||||
translate['Add to the calendar'] + '</a>\n</p>\n</center>\n'
|
translate['Add to the calendar'] + '</a>\n</p>\n</center>\n'
|
||||||
|
|
||||||
calStr = \
|
cal_str = \
|
||||||
headerStr + screenReaderCal + calendarStr + newEventStr + html_footer()
|
header_str + screen_reader_cal + calendar_str + \
|
||||||
|
new_event_str + html_footer()
|
||||||
|
|
||||||
return calStr
|
return cal_str
|
||||||
|
|
Loading…
Reference in New Issue