Skip to content

Commit

Permalink
Display version
Browse files Browse the repository at this point in the history
And some linter fixes
  • Loading branch information
n8henrie committed Sep 9, 2022
1 parent b1268d4 commit 2737ae2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
15 changes: 8 additions & 7 deletions src/icw/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
{{ super() }}
<link type="text/css" rel="stylesheet" href="{{ url_for('.static', filename='css/style.css') }}" />
{% endblock %}

{% block metas %}
{{ super() }}
{% endblock %}
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="shortcut icon" href="{{ url_for('.static', filename='favicon.ico') }}">
{% endblock %}


Expand All @@ -30,20 +30,21 @@

<div id="icw-header">
<h1>icsConverterWebapp</h1>
<p>by <a href="http://n8henrie.com">n8henrie.com</a></p>
<p>version {{ version }}</p>
<p>by <a href="https://n8henrie.com">n8henrie.com</a></p>
</div>

<div id="center_content">
{% with messages = get_flashed_messages(with_categories=True) %}
{% if messages %}
{% if messages %}
<div id="messages">
{{ utils.flashed_messages(messages=messages, container=False) }}
</div>
{% endif %}
{% endwith %}

{% block content %}{% endblock %}

{% if links %}
<div id="links" class="links">
<p class="lead">{{ links_title }}</p>
Expand All @@ -55,7 +56,7 @@ <h1>icsConverterWebapp</h1>
</ul>
</div>
</div>
{% endif %}
{% endif %}
</div>
</div>

Expand Down
33 changes: 21 additions & 12 deletions src/icw/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
url_for,
)

import icw
from icw import app

from .converter import ContentError, convert, DatetimeFormatError, HeadersError
Expand All @@ -26,7 +27,7 @@
"description": "icw source code at GitHub",
},
]
links_title = "A few helpful links"
LINKS_TITLE = "A few helpful links"


@app.route("/", methods=["GET", "POST"])
Expand All @@ -45,12 +46,13 @@ def index():
except (ContentError, HeadersError, DatetimeFormatError) as error:
app.logger.info("Error in file conversion: ")
app.logger.info(error)
flash(error, "danger")
flash(str(error), "danger")
return render_template(
"index.html",
form=form,
links=base_links,
links_title=links_title,
links_title=LINKS_TITLE,
version=icw.__version__,
)

else:
Expand All @@ -60,12 +62,16 @@ def index():
session["key"] = key
return redirect(url_for("success"))

for field, errors in form.errors.items():
for _, errors in form.errors.items():
for error in errors:
msg = "Whups! {}".format(error)
flash(msg)
return render_template(
"index.html", form=form, links=base_links, links_title=links_title
"index.html",
form=form,
links=base_links,
links_title=LINKS_TITLE,
version=icw.__version__,
)


Expand All @@ -82,7 +88,10 @@ def success():
links.extend(base_links)

return render_template(
"success.html", links=links, links_title="Where to next?"
"success.html",
links=links,
links_title="Where to next?",
version=icw.__version__,
)


Expand All @@ -96,14 +105,14 @@ def download():

response = make_response(downfile)
response.headers["Content-Type"] = mtype
response.headers["Content-Disposition"] = (
"attachment; " "filename=converted.ics"
)
response.headers[
"Content-Disposition"
] = "attachment; filename=converted.ics"
return response


@app.errorhandler(404)
def error_404(e):
def error_404(_):
"""Return a custom 404 error."""
return "Sorry, Nothing at this URL.", 404

Expand All @@ -115,10 +124,10 @@ def error_500(e):
app.logger.warning(repr(e))
app.logger.warning(e)
msg = (
"Sorry, unexpected error: {}<br/><br/>"
f"Sorry, unexpected error: {e}<br/><br/>"
"This shouldn't have happened. Would you mind "
'<a href="https://n8henrie.com/contact">sending me</a> '
"a message regarding what caused this (and the file if "
"possible)? Thanks -Nate".format(e)
"possible)? Thanks -Nate"
)
return msg, 500

0 comments on commit 2737ae2

Please sign in to comment.