test commit
This commit is contained in:
parent
cba26dec5e
commit
ed30556bd3
36
.gitignore
vendored
36
.gitignore
vendored
@ -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
|
||||
|
||||
|
||||
23
app/__init__.py
Normal file
23
app/__init__.py
Normal file
@ -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()
|
||||
BIN
app/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/models.cpython-310.pyc
Normal file
BIN
app/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/views.cpython-310.pyc
Normal file
BIN
app/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
16
app/models.py
Normal file
16
app/models.py
Normal file
@ -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 '<Day: {}>'.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"))
|
||||
|
||||
BIN
app/sqlite.db
Normal file
BIN
app/sqlite.db
Normal file
Binary file not shown.
35
app/static/ltx.css
Normal file
35
app/static/ltx.css
Normal file
@ -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;
|
||||
}
|
||||
45
app/templates/index.html
Normal file
45
app/templates/index.html
Normal file
@ -0,0 +1,45 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Life Tracker Expanded</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
|
||||
<!-- HTMX -->
|
||||
<script src="https://unpkg.com/htmx.org@1.5.0"></script>
|
||||
<link rel="stylesheet" href="/static/ltx.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Life Tracker, Expanded</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Date</th>
|
||||
<th scope="col">Day</th>
|
||||
{% for m in ["am", "pm"]%}
|
||||
<th scope="col">12 {{m}}</th>
|
||||
{% for t in range(1,12) %}
|
||||
<th scope="col">{{t}} {{m}}</th>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="new-book" hx-target="closest tr" hx-swap="outerHTML swap:0.5s">
|
||||
{%for book in books%}
|
||||
<tr>
|
||||
<td>{{book.Book.title}}</td>
|
||||
<td>{{book.Author.name}}</td>
|
||||
<td>
|
||||
<button class="btn btn-primary"
|
||||
hx-get="/get-edit-form/{{book.Book.book_id}}">
|
||||
Edit Title
|
||||
</button>
|
||||
</td>
|
||||
<td>
|
||||
<button hx-delete="/delete/{{book.Book.book_id}}" class="btn btn-primary">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
{%endfor%}
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
54
app/views.py
Normal file
54
app/views.py
Normal file
@ -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"""
|
||||
<tr>
|
||||
<td>{title}</td>
|
||||
<td>{author_name}</td>
|
||||
<td>
|
||||
<button class="btn btn-primary"
|
||||
hx-get="/get-edit-form/{global_book_object.book_id}">
|
||||
Edit Title
|
||||
</button>
|
||||
</td>
|
||||
<td>
|
||||
<button hx-delete="/delete/{global_book_object.book_id}"
|
||||
class="btn btn-primary">
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
"""
|
||||
return response
|
||||
Loading…
Reference in New Issue
Block a user