Skip to content

Commit

Permalink
Fixes #85
Browse files Browse the repository at this point in the history
  • Loading branch information
weaversam8 committed Feb 21, 2024
1 parent 2383437 commit 8304302
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 138 deletions.
2 changes: 1 addition & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ for EV in READ_ACCESS WRITE_ACCESS ATTACHMENT_ACCESS; do
echo "${EV} = '${!EV}'" >> ${OTTERWIKI_SETTINGS}
fi
done
for EV in AUTO_APPROVAL EMAIL_NEEDS_CONFIRMATION; do
for EV in AUTO_APPROVAL EMAIL_NEEDS_CONFIRMATION RAW_PAGE_NAMES; do
if [ ! -z "${!EV}" ]; then
sed -i "/^${EV}.*/d" ${OTTERWIKI_SETTINGS}
echo "${EV} = ${!EV}" >> ${OTTERWIKI_SETTINGS}
Expand Down
25 changes: 18 additions & 7 deletions otterwiki/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,30 @@ def health_check():
return True, ["ok"]
return False, msg

def auto_url(filename, revision=None):

def auto_url(filename, revision=None, raw_page_names=False):
# handle attachments and pages
arr = split_path(filename)
if filename.endswith(".md"):
# page
return (get_pagename(filename, full=True),
url_for(
"view", path=get_pagename(filename, full=True),
revision=revision
))
return (
get_pagename(filename, full=True, raw_page_names=raw_page_names),
url_for(
"view",
path=get_pagename(
filename, full=True, raw_page_names=raw_page_names
),
revision=revision,
),
)
else:
# attachment
pagename, attached_filename = get_pagename(join_path(arr[:-1]), full=True), arr[-1]
pagename, attached_filename = (
get_pagename(
join_path(arr[:-1]), full=True, raw_page_names=raw_page_names
),
arr[-1],
)
return (filename,
url_for('get_attachment',
pagepath=pagename,
Expand Down
9 changes: 7 additions & 2 deletions otterwiki/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ def handle_app_preferences(form):
_update_preference(name.upper(),form.get(name, ""))
for name in ["READ_access", "WRITE_access", "ATTACHMENT_access"]:
_update_preference(name.upper(),form.get(name, "ANONYMOUS"))
for checkbox in ["auto_approval", "email_needs_confirmation",
"notify_admins_on_register", "notify_user_on_approval"]:
for checkbox in [
"auto_approval",
"email_needs_confirmation",
"notify_admins_on_register",
"notify_user_on_approval",
"raw_page_names",
]:
_update_preference(checkbox.upper(),form.get(checkbox, "False"))
# commit changes to the database
db.session.commit()
Expand Down
13 changes: 10 additions & 3 deletions otterwiki/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
EMAIL_NEEDS_CONFIRMATION=True,
NOTIFY_ADMINS_ON_REGISTER=False,
NOTIFY_USER_ON_APPROVAL=False,
RAW_PAGE_NAMES=False,
SQLALCHEMY_DATABASE_URI="sqlite:///:memory:",
MAIL_DEFAULT_SENDER="[email protected]",
MAIL_SERVER="",
Expand Down Expand Up @@ -100,9 +101,15 @@ def update_app_config():
global mail
with app.app_context():
for item in Preferences.query:
if item.name.upper() in ["MAIL_USE_TLS", "MAIL_USE_SSL", "AUTO_APPROVAL",
"EMAIL_NEEDS_CONFIRMATION", "NOTIFY_ADMINS_ON_REGISTER",
"NOTIFY_USER_ON_APPROVAL"]:
if item.name.upper() in [
"MAIL_USE_TLS",
"MAIL_USE_SSL",
"AUTO_APPROVAL",
"EMAIL_NEEDS_CONFIRMATION",
"NOTIFY_ADMINS_ON_REGISTER",
"NOTIFY_USER_ON_APPROVAL",
"RAW_PAGE_NAMES",
]:
item.value = item.value.lower() in ["true","yes"]
if item.name.upper() in ["MAIL_PORT"]:
try:
Expand Down
8 changes: 8 additions & 0 deletions otterwiki/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ <h3 class="card-title" id="sidebar">Content and Editing Preferences</h3>
{% endfor %}
</select>
</div>
{##}
<div class="form-group">
<div class="custom-checkbox">
<input {%if config.RAW_PAGE_NAMES %}checked{% endif %} type="checkbox" id="raw_page_names" name="raw_page_names"
value="True">
<label for="raw_page_names">Preserve "raw" page names when saving and displaying markdown files</label>
</div>
</div>
{##}
<div class="mt-10">
<input class="btn btn-primary" name="update_preferences" type="submit" value="Save Preferences">
Expand Down
13 changes: 7 additions & 6 deletions otterwiki/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ def split_path(path):
return split_path(head) + [tail]


def get_filename(pagepath):
def get_filename(pagepath, raw_page_names=False):
'''This is the actual filepath on disk (not via URL) relative to the repository root
This function will attempt to determine if this is a 'folder' or a 'page'.
'''

p = pagepath.lower()
p = pagepath if raw_page_names else pagepath.lower()
p = clean_slashes(p)

if not p.endswith(".md"):
Expand All @@ -107,12 +107,13 @@ def get_filename(pagepath):
return p


def get_attachment_directoryname(filename):
filename = filename.lower()
def get_attachment_directoryname(filename, raw_page_names=False):
filename = filename if raw_page_names else filename.lower()
if filename[-3:] != ".md":
raise ValueError
return filename[:-3]


def titleSs(s):
"""
This function is a workaround for str.title() not knowing upercase 'ß'.
Expand All @@ -127,7 +128,7 @@ def titleSs(s):
return s.replace(magicword,'ß')


def get_pagename(filepath, full=False, header=None):
def get_pagename(filepath, full=False, header=None, raw_page_names=False):
'''This will derive the page name (displayed on the web page) from the url requested'''
# remove trailing slashes from filepath
filepath=filepath.rstrip("/")
Expand All @@ -145,7 +146,7 @@ def get_pagename(filepath, full=False, header=None):
or (hint == part and hint != part.lower()):
arr[i] = hint
else:
arr[i] = titleSs(part)
arr[i] = part if raw_page_names else titleSs(part)

if not full:
return arr[-1]
Expand Down
Loading

0 comments on commit 8304302

Please sign in to comment.