diff --git a/.gitignore b/.gitignore index 4b11ede..f54df6c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,36 +1,2 @@ -# ---> Elixir -/_build -/cover -/deps -/doc -/.fetch -erl_crash.dump -*.ez -*.beam -/config/*.secret.exs -.elixir_ls/ - -# ---> Phoenix -# gitignore template for Phoenix projects -# website: http://www.phoenixframework.org/ -# -# Recommended template: Elixir.gitignore - -# Temporary files -/tmp - -# Static artifacts -/node_modules -/assets/node_modules - -# Since we are building assets from web/static, -# we ignore priv/static. You may want to comment -# this depending on your deployment strategy. -/priv/static/ - -# Installer-related files -/installer/_build -/installer/tmp -/installer/doc -/installer/deps +/env diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..7be15bf --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,23 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os + +persistent_path = os.getenv("PERSISTENT_STORAGE_DIR", os.path.dirname(os.path.realpath(__file__))) + +app = Flask(__name__) + +db_path = os.path.join(persistent_path, "sqlite.db") + +app.config["SQLALCHEMY_DATABASE_URI"] = f'sqlite:///{db_path}' +app.config["SQLALCHEMY_ECHO"] = False +app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + +db = SQLAlchemy() + +from app import views +from app import models + +db.init_app(app) + +with app.app_context(): + db.create_all() \ No newline at end of file diff --git a/app/__pycache__/__init__.cpython-310.pyc b/app/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..c06de74 Binary files /dev/null and b/app/__pycache__/__init__.cpython-310.pyc differ diff --git a/app/__pycache__/models.cpython-310.pyc b/app/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..fab97f4 Binary files /dev/null and b/app/__pycache__/models.cpython-310.pyc differ diff --git a/app/__pycache__/views.cpython-310.pyc b/app/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..0a8646a Binary files /dev/null and b/app/__pycache__/views.cpython-310.pyc differ diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..d9c41e2 --- /dev/null +++ b/app/models.py @@ -0,0 +1,16 @@ +from app import db + +class Day(db.Model): + day_id = db.Column(db.Integer, primary_key=True) + note = db.Column(db.String) + books = db.relationship("Hour", backref="day") + + def __repr__(self): + return ''.format(self.hours) + + +class Hour(db.Model): + hour_id = db.Column(db.Integer, primary_key=True) + time = db.Column(db.Integer) + day_id = db.Column(db.Integer, db.ForeignKey("author.author_id")) + diff --git a/app/sqlite.db b/app/sqlite.db new file mode 100644 index 0000000..820c49b Binary files /dev/null and b/app/sqlite.db differ diff --git a/app/static/ltx.css b/app/static/ltx.css new file mode 100644 index 0000000..ff5e826 --- /dev/null +++ b/app/static/ltx.css @@ -0,0 +1,35 @@ +/* Variables */ +:root{ + --bg: #273036; + --fg: #ffffff; +} + +body{ + padding: 20px; + background: var(--bg); + color: var(--fg); +} +table { + font-family: "Monospace"; + border-collapse: collapse; + width: 100%; +} + +th{ + text-transform: uppercase; +} + +tr.htmx-swapping td { + opacity: 0; + transition: opacity 0.5s ease-out; +} + +td, th { + border: 1px solid #383737; + text-align: left; + padding: 8px; +} + +tr:nth-child(even) { + background-color: #dddddd; +} diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..2b44b9c --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,45 @@ + + + + Life Tracker Expanded + + + + + + +

Life Tracker, Expanded

+ + + + + + {% for m in ["am", "pm"]%} + + {% for t in range(1,12) %} + + {% endfor %} + {% endfor %} + + + + {%for book in books%} + + + + + + + {%endfor%} + +
DateDay12 {{m}}{{t}} {{m}}
{{book.Book.title}}{{book.Author.name}} + + + +
+ + \ No newline at end of file diff --git a/app/views.py b/app/views.py new file mode 100644 index 0000000..7ee7ae2 --- /dev/null +++ b/app/views.py @@ -0,0 +1,54 @@ +from app import app, db +from flask import render_template, request, jsonify +from app.models import Author, Book + +@app.route("/", methods=["GET"]) +def home(): + books = db.session.query(Book, Author).filter(Book.author_id == Author.author_id).all() + return render_template("index.html", books=books) +@app.route("/submit", methods=["POST"]) + +def submit(): + global_book_object = Book() + + title = request.form["title"] + author_name = request.form["author"] + + author_exists = db.session.query(Author).filter(Author.name == author_name).first() + print(author_exists) + # check if author already exists in db + if author_exists: + author_id = author_exists.author_id + book = Book(author_id=author_id, title=title) + db.session.add(book) + db.session.commit() + global_book_object = book + else: + author = Author(name=author_name) + db.session.add(author) + db.session.commit() + + book = Book(author_id=author.author_id, title=title) + db.session.add(book) + db.session.commit() + global_book_object = book + + response = f""" + + {title} + {author_name} + + + + + + + + """ + return response \ No newline at end of file diff --git a/ltx.py b/ltx.py new file mode 100644 index 0000000..e69de29 diff --git a/run.py b/run.py new file mode 100644 index 0000000..6b03f79 --- /dev/null +++ b/run.py @@ -0,0 +1,4 @@ +from app import app + +if __name__ == "__main__": + app.run(debug=True)