clean url = clean database
This commit is contained in:
parent
6f09338ccf
commit
e19324c220
15
octomode.py
15
octomode.py
|
|
@ -4,6 +4,7 @@ from flask import Flask, request, render_template, redirect, url_for
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import html
|
import html
|
||||||
|
import re
|
||||||
|
|
||||||
# To sanitize Flask input fields
|
# To sanitize Flask input fields
|
||||||
from markupsafe import Markup, escape
|
from markupsafe import Markup, escape
|
||||||
|
|
@ -173,6 +174,16 @@ def render_markdown_error(name, error):
|
||||||
title="Markdown error"
|
title="Markdown error"
|
||||||
), 400
|
), 400
|
||||||
|
|
||||||
|
|
||||||
|
def clean_string(input_string):
|
||||||
|
input_string = input_string.lower()
|
||||||
|
snake_case_string = re.sub(r'[\s!]+', '_', input_string)
|
||||||
|
return snake_case_string.strip('_')
|
||||||
|
|
||||||
|
def prettify_string(input_string):
|
||||||
|
space_string = input_string.replace("_", " ")
|
||||||
|
return space_string.title()
|
||||||
|
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
@APP.route('/', methods=['GET', 'POST'])
|
@APP.route('/', methods=['GET', 'POST'])
|
||||||
|
|
@ -184,12 +195,14 @@ def index():
|
||||||
# This is when the environment is "created"
|
# This is when the environment is "created"
|
||||||
# The pads are filled with the default templates (pad, stylesheet, template)
|
# The pads are filled with the default templates (pad, stylesheet, template)
|
||||||
exts = ['.md', '.css']
|
exts = ['.md', '.css']
|
||||||
|
# clean up the name so we dont get x number of different publications when people mistype
|
||||||
|
name = clean_string(name)
|
||||||
for ext in exts:
|
for ext in exts:
|
||||||
create_pad_on_first_run(name, ext)
|
create_pad_on_first_run(name, ext)
|
||||||
return redirect(url_for("pad", name=name))
|
return redirect(url_for("pad", name=name))
|
||||||
else:
|
else:
|
||||||
pubs = all_publications()
|
pubs = all_publications()
|
||||||
return render_template('start.html', pubs = pubs, home_pad_url=APP.config['HOME_PAD_URL'])
|
return render_template('start.html', pubs = pubs, home_pad_url=APP.config['HOME_PAD_URL'], prettify_string=prettify_string)
|
||||||
|
|
||||||
@APP.route('/<name>/')
|
@APP.route('/<name>/')
|
||||||
def main(name):
|
def main(name):
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
<p>Below a list of the publications on the server.</p>
|
<p>Below a list of the publications on the server.</p>
|
||||||
<ul>
|
<ul>
|
||||||
{% for pub in pubs %}
|
{% for pub in pubs %}
|
||||||
<li><a href="{{ url_for('pdf',name=pub)}}">{{pub}}</a></li>
|
<li><a href="{{ url_for('pdf',name=pub)}}">{{prettify_string(pub)}}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue