src: cleanup

master
tiyn 2 years ago
parent b4609b88c6
commit b693bcdabc

@ -32,34 +32,38 @@ REGISTER = config.REGISTER
@app.errorhandler(404) @app.errorhandler(404)
def page_not_found(e): def page_not_found(e):
return render_template("error.html", title=TITLE, errorcode="404", style=STYLE), 404 return render_template("error.html", title=TITLE, errorcode="404",
style=STYLE), 404
@app.route("/") @app.route("/")
@app.route("/index.html") @app.route("/index.html")
def index(): def index():
content = con_gen.gen_index_string() content = con_gen.gen_index_string()
return render_template("index.html", title=TITLE, content_string=content, style=STYLE) return render_template("index.html", title=TITLE, content_string=content,
style=STYLE)
@app.route("/archive") @app.route("/archive")
@app.route("/archive.html") @app.route("/archive.html")
def archive(): def archive():
content = con_gen.gen_arch_string() content = con_gen.gen_arch_string()
return render_template("archive.html", title=TITLE, content_string=content, style=STYLE) return render_template("archive.html", title=TITLE, content_string=content,
style=STYLE)
@app.route("/entry/<ident>") @app.route("/entry/<ident>")
def entry(ident): def entry(ident):
content = con_gen.gen_stand_string(ident) content = con_gen.gen_stand_string(ident)
if content != "": if content != "":
return render_template("standalone.html", title=TITLE, content_string=content, style=STYLE) return render_template("standalone.html", title=TITLE,
content_string=content, style=STYLE)
abort(404) abort(404)
@app.route("/feed") @app.route("/feed")
@app.route("/rss")
@app.route("/feed.xml") @app.route("/feed.xml")
@app.route("/rss")
@app.route("/rss.xml") @app.route("/rss.xml")
def feed(): def feed():
content = con_gen.get_rss_string() content = con_gen.get_rss_string()

@ -35,6 +35,7 @@ def gen_arch_string():
if entries is None: if entries is None:
return "" return ""
entries.sort(key=lambda y: y[2]) entries.sort(key=lambda y: y[2])
entries.reverse()
for entry in entries: for entry in entries:
ident = entry[0] ident = entry[0]
title = entry[1] title = entry[1]
@ -47,9 +48,9 @@ def gen_arch_string():
content_string += "<ul>\n" content_string += "<ul>\n"
last_year = year last_year = year
content_string += "<li>" content_string += "<li>"
content_string += "[<a href=\"" + url_for("index", _anchor=str(ident)) + \ content_string += "[<a href=\"" + \
"\">link</a> - <a href=\"" + url_for("entry", ident=str(ident)) + \ url_for("index", _anchor=str(ident)) + "\">link</a> - <a href=\"" \
"\">standalone</a>] " + url_for("entry", ident=str(ident)) + "\">standalone</a>] "
content_string += title + " " + rating_to_star(rating) content_string += title + " " + rating_to_star(rating)
content_string += "<br></li>\n" content_string += "<br></li>\n"

@ -69,7 +69,8 @@ class Database:
if self.check_user_name(user.name) and user.pass_hash is not None: if self.check_user_name(user.name) and user.pass_hash is not None:
db = self.connect() db = self.connect()
crs = db.cursor() crs = db.cursor()
query = "INSERT INTO " + self.USER_TABLE_FILE + "(`name`,`password`)" + \ query = "INSERT INTO " + self.USER_TABLE_FILE + \
"(`name`,`password`)" + \
"VALUES (?, ?) ON CONFLICT DO NOTHING" "VALUES (?, ?) ON CONFLICT DO NOTHING"
crs.execute(query, (user.name, user.pass_hash)) crs.execute(query, (user.name, user.pass_hash))
db.commit() db.commit()
@ -82,8 +83,9 @@ class Database:
db = self.connect() db = self.connect()
crs = db.cursor() crs = db.cursor()
reviewed = dt.today().strftime('%Y-%m-%d') reviewed = dt.today().strftime('%Y-%m-%d')
query = "INSERT INTO " + self.ENTRY_TABLE_FILE + "(`name`,`date`, `text`, `rating`, `user_id`, `reviewed`)" + \ query = "INSERT INTO " + self.ENTRY_TABLE_FILE + \
"VALUES (?, ?, ?, ?, ?, ?)" "(`name`,`date`, `text`, `rating`, `user_id`, `reviewed`)" + \
"VALUES (?, ?, ?, ?, ?, ?)"
crs.execute(query, (name, date, text, rating, user_id, reviewed)) crs.execute(query, (name, date, text, rating, user_id, reviewed))
db.commit() db.commit()
return crs.lastrowid return crs.lastrowid
@ -125,9 +127,3 @@ class Database:
user = User(name, pass_hash) user = User(name, pass_hash)
user.set_id(ident) user.set_id(ident)
return user return user
#db = Database()
#db.insert_entry("name", "2020", "text", 50, 1)
#res = db.get_entries()
# print(res)

@ -38,6 +38,21 @@ footer .center {
text-align: center; text-align: center;
} }
li:not(:last-child) {
margin-bottom: 5px;
}
ol {
margin: 10px 0;
padding-left: 20;
}
ul {
margin: 10px 0;
padding-left: 20;
}
.container { .container {
min-height: 100%; min-height: 100%;
padding-bottom: 50px; padding-bottom: 50px;
@ -162,8 +177,3 @@ footer .center {
.entry h2 { .entry h2 {
margin: 5px auto 2px auto; margin: 5px auto 2px auto;
} }
.entry ul {
padding-left: 20;
}

@ -1,4 +1,5 @@
{% extends "template.html" %} {% extends "template.html" %}
{% block content %} {% block content %}
<div class="container"> <div class="container">
<div class="blogarchive"> <div class="blogarchive">

@ -1,4 +1,5 @@
{% extends "template.html" %} {% extends "template.html" %}
{% block content %} {% block content %}
<div class="container"> <div class="container">
<div class="important"> <div class="important">

@ -1,4 +1,5 @@
{% extends "template.html" %} {% extends "template.html" %}
{% block content %} {% block content %}
<div class="container"> <div class="container">
<div class="blog"> <div class="blog">

@ -1,4 +1,5 @@
{% extends "template.html" %} {% extends "template.html" %}
{% block content %} {% block content %}
<div class="container"> <div class="container">
<div class="standalone"> <div class="standalone">

@ -1,3 +1,8 @@
{% set navigation_bar = [
(url_for("index"), 'index', 'Blog'),
(url_for("archive"), 'archive', 'Archive')
] -%}
<html> <html>
<head> <head>
<title>{{ title }}</title> <title>{{ title }}</title>
@ -13,8 +18,9 @@
<input type="checkbox" id="main-menu-check"> <input type="checkbox" id="main-menu-check">
<label for="main-menu-check" class="show-menu">&#9776;</label> <label for="main-menu-check" class="show-menu">&#9776;</label>
<div class="main-menu"> <div class="main-menu">
<a href="{{ url_for('index') }}">Blog</a> {% for href, id, caption in navigation_bar %}
<a href="{{ url_for('archive') }}">Archive</a> <a href="{{ href|e }}">{{ caption|e }}</a>
{% endfor %}
<label for="main-menu-check" class="hide-menu">X</label> <label for="main-menu-check" class="hide-menu">X</label>
</div> </div>
</div> </div>

Loading…
Cancel
Save