updated README to reflect next steps (will use flask-wtf and flask-boostrap), but proof-of-concept author/<id> works to save to database with a form / POST
This commit is contained in:
6
README
6
README
@@ -16,7 +16,7 @@ python3 main.py
|
||||
|
||||
|
||||
### TODO:
|
||||
- book subbook link will be next real challenge (with raw sql for now)
|
||||
- then next challenge will be to make single book page an edit / save
|
||||
- then its just finish this off :)
|
||||
- fix up lame book linkages to tabels that are so not 3nf, *_LST tables, etc.
|
||||
- use flask-wtf and flask-bootstrap, see this: https://medium.com/better-programming/how-to-use-flask-wtforms-faab71d5a034 for author/<id>
|
||||
- consider getting rest of Book class connected, e.g. series, loan, etc.
|
||||
- see if we can break this out of main.py -- can't recall what was circular about this, but at least the wtf bits seem to be able to be moved out, so why not do that
|
||||
|
||||
19
main.py
19
main.py
@@ -167,9 +167,24 @@ def book(id):
|
||||
return render_template("books.html", books=book_s, subs=sub_book )
|
||||
|
||||
@app.route("/authors", methods=["GET"])
|
||||
def author():
|
||||
def authors():
|
||||
authors = Author.query.all()
|
||||
return render_template("author.html", authors=authors)
|
||||
return render_template("authors.html", authors=authors)
|
||||
|
||||
@app.route("/author/<id>", methods=["GET", "POST"])
|
||||
def author(id):
|
||||
if request.method == 'POST':
|
||||
id = request.form['author.id']
|
||||
author = Author.query.get(id)
|
||||
author.firstnames = request.form['author.firstnames']
|
||||
author.surname = request.form['author.surname']
|
||||
db.session.commit()
|
||||
message="Successfully Updated Author (id={})".format(id)
|
||||
else:
|
||||
author = Author.query.get(id)
|
||||
message=""
|
||||
return render_template("author.html", author=author, message=message)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", debug=True)
|
||||
|
||||
@@ -1,9 +1,44 @@
|
||||
<html>
|
||||
<body>
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<h1>authors</h1>
|
||||
{% for author in authors %}
|
||||
<p>{{author.surname}}, {{author.firstnames}}</p>
|
||||
{% endfor %}
|
||||
</body>
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
|
||||
<script src="https://kit.fontawesome.com/9b4c7cf470.js" crossorigin="anonymous"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h3><center>Author</center></h3>
|
||||
<div class="container">
|
||||
{% if message|length %}
|
||||
<div class="row alert alert-success">
|
||||
{{message}}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row with-margin">
|
||||
<form class="form col-lg-12" action="" method="POST">
|
||||
<input type="hidden" name="author.id" id="author.id" value="{{author.id}}">
|
||||
<div class="input-group input-group-lg">
|
||||
<label for="{{author.firstnames}}" class="col-lg-2 col-form-label">Firstnames:</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control input-lg" name="author.firstnames" id="author.firstnames" value="{{author.firstnames}}">
|
||||
</div class="col-lg-10">
|
||||
</div class="input-group">
|
||||
<div class="input-group input-group-lg">
|
||||
<label for="{{author.surname}}" class="col-lg-2 col-form-label">Surname:</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="author.surname" id="author.surname" value="{{author.surname}}">
|
||||
</div class="col-lg-10">
|
||||
</div class="input-group">
|
||||
<div class="input-group input-group-lg">
|
||||
<div class="col-lg-2">
|
||||
<input class="btn btn-primary" type="submit" id="save" value="Save">
|
||||
</div class="col-lg-2">
|
||||
</div class="input-group input-group-lg">
|
||||
</form>
|
||||
</div class="row">
|
||||
</div class="container">
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
</form>
|
||||
</div class="row">
|
||||
</div class="container">
|
||||
{% if books.sub_book is defined %}
|
||||
{% if books.sub_book|length %}
|
||||
<p>sub_book is defined: {{books.sub_book}}</p>
|
||||
{% endif %}
|
||||
{{ books.subs }}
|
||||
|
||||
Reference in New Issue
Block a user