From 871956714286528f0f13bbe5803a39a15ef9b10b Mon Sep 17 00:00:00 2001 From: kukemuna Date: Sun, 21 Apr 2024 22:57:52 +0300 Subject: [PATCH] automated commit by submit50 --- app.py | 75 ++++++++++++++++++++++++++++++++++++++ birthdays.db | Bin 0 -> 8192 bytes static/styles.css | 83 +++++++++++++++++++++++++++++++++++++++++++ templates/index.html | 60 +++++++++++++++++++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 app.py create mode 100644 birthdays.db create mode 100644 static/styles.css create mode 100644 templates/index.html diff --git a/app.py b/app.py new file mode 100644 index 0000000..c831c05 --- /dev/null +++ b/app.py @@ -0,0 +1,75 @@ +import os + +from cs50 import SQL +from flask import Flask, flash, jsonify, redirect, render_template, request, session + +# Configure application +app = Flask(__name__) + +# Ensure templates are auto-reloaded +app.config["TEMPLATES_AUTO_RELOAD"] = True + +# Configure CS50 Library to use SQLite database +db = SQL("sqlite:///birthdays.db") + + +@app.after_request +def after_request(response): + """Ensure responses aren't cached""" + response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" + response.headers["Expires"] = 0 + response.headers["Pragma"] = "no-cache" + return response + + +@app.route("/", methods=["GET", "POST"]) +def index(): + if request.method == "POST": + + # Add the user's entry into the database + name = request.form.get("name") + if not name: + return redirect("/") + + day = request.form.get("day") + if not day: + return redirect("/") + try: + day = int(day) + except ValueError: + return redirect("/") + if day < 1 or day > 31: + return redirect("/") + + month = request.form.get("month") + if not month: + return redirect("/") + try: + month = int(month) + except ValueError: + return redirect("/") + if month < 1 or month > 12: + return redirect("/") + + db.execute("INSERT INTO birthdays(name, day, month) VALUES(?, ?, ?)", name, day ,month) + + return redirect("/") + + else: + + # Display the entries in the database on index.html + bdays = db.execute("SELECT * FROM birthdays") + return render_template("index.html", bdays=bdays) + +# Remove single entry +@app.route("/remove", methods=["POST"]) +def remove(): + bday_id = request.form.get("id") + db.execute("DELETE FROM birthdays WHERE ID=?", bday_id) + return redirect("/") + +# Remove all entries +@app.route("/remove_all", methods=["POST"]) +def remove_all(): + db.execute("DELETE FROM birthdays") + return redirect("/") diff --git a/birthdays.db b/birthdays.db new file mode 100644 index 0000000000000000000000000000000000000000..18d658ee80c601f27486f9398d6a3157f6d0e290 GIT binary patch literal 8192 zcmeI#K?{N~6bJB4f+hTd(sz6{zzpH2NQ7MqrX!d0SG_<0uX=z R1Rwwb2tWV=5P(3B1>Qp`Fkt`y literal 0 HcmV?d00001 diff --git a/static/styles.css b/static/styles.css new file mode 100644 index 0000000..cbb9897 --- /dev/null +++ b/static/styles.css @@ -0,0 +1,83 @@ +body { + background-color: #fff; + color: #212529; + font-size: 1rem; + font-weight: 400; + line-height: 1.5; + margin: 0; + text-align: left; +} + +.container { + margin-left: auto; + margin-right: auto; + padding-left: 15px; + padding-right: 15px; + text-align: center; + width: 90%; +} + +.header { + background-color: #477bff; + color: #fff; + margin-bottom: 2rem; + padding: 2rem 1rem; + text-align: center; +} + +.section { + padding-bottom: 1rem; + padding-left: 2rem; + padding-right: 2rem; + padding-top: 0.5rem; +} + +.section:hover { + background-color: #f5f5f5; + transition: color 2s ease-in-out, background-color 0.15s ease-in-out; +} + +h1 { + font-family: 'Montserrat', sans-serif; + font-size: 48px; +} + +button, input[type="submit"] { + background-color: #d9edff; + border: 1px solid transparent; + border-radius: 0.25rem; + font-size: 0.95rem; + font-weight: 400; + line-height: 1.5; + padding: 0.375rem 0.75rem; + text-align: center; + transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; + vertical-align: middle; +} + +input[type="text"], input[type="number"] { + line-height: 1.8; + width: 25%; +} + +input[type="text"]:hover, input[type="number"]:hover { + background-color: #f5f5f5; + transition: color 2s ease-in-out, background-color 0.15s ease-in-out; +} + +table { + background-color: transparent; + margin-bottom: 1rem; + width: 100%; +} + +table th, +table td { + padding: 0.75rem; + vertical-align: middle; +} + +tbody tr:nth-of-type(odd) { + background-color: rgb(179, 208, 255, 0.3) +} + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..42d09a7 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,60 @@ + + + + + + + Birthdays + + +
+

Birthdays

+
+
+
+ +

Add a Birthday

+ +
+ + + + +
+
+ +
+ +

All Birthdays

+ + + + + + + + + + + {% for bday in bdays %} + + + + + + {% endfor %} + +
NameBirthday +
+ +
+
{{ bday.name }}{{ bday.day }}.{{ bday.month }} +
+ + +
+
+
+
+ +