~kvikshaug/kvikshaug.no

2cda737ccb21470a792a99c07271e978b5e6395f — Ali Kaafarani 2 years ago c72b34a
Add guestbook moderation
1 files changed, 9 insertions(+), 6 deletions(-)

M src/kvikshaug/app.py
M src/kvikshaug/app.py => src/kvikshaug/app.py +9 -6
@@ 25,7 25,7 @@ if not os.path.exists("data/guestbook.json"):
@app.route("/")
def home():
    with open("data/guestbook.json") as file_:
        guestbook = json.load(file_)
        guestbook = [c for c in json.load(file_) if c["published"]]
    for message in guestbook:
        message["datetime"] = datetime.strptime(message["datetime"], "%Y-%m-%d %H:%M")
    guestbook = sorted(guestbook, key=lambda m: m["datetime"], reverse=True)


@@ 40,10 40,13 @@ def guestbook():
    with open("data/guestbook.json") as file_:
        guestbook = json.load(file_)
    with open("data/guestbook.json", "w") as file_:
        guestbook.append({
            "message": message,
            "ip": request.remote_addr,
            "datetime": datetime.now().strftime("%Y-%m-%d %H:%M")
        })
        guestbook.append(
            {
                "message": message,
                "ip": request.remote_addr,
                "datetime": datetime.now().strftime("%Y-%m-%d %H:%M"),
                "published": False,
            }
        )
        json.dump(guestbook, file_)
    return redirect("/#guestbook")