now create an owned on /owned, rather than /owned/-1 kludge. Also using sequence for creation. All good - made sequences for all relevant tables too. Last question is how to do redirect to /owneds and still show messsage
This commit is contained in:
3
README
3
README
@@ -25,6 +25,8 @@ python3 main.py
|
|||||||
|
|
||||||
|
|
||||||
### TODO:
|
### TODO:
|
||||||
|
-- Without redirects (after creation) the potential for reload's trying to re-add objects may suck...
|
||||||
|
-> see if I can see how to pass alert/message through to /owneds somehow ... if I can even pass a global or some shit then pick it up in the python code?
|
||||||
- need to create all classes (green + button)
|
- need to create all classes (green + button)
|
||||||
- need to delete all classes (and watch for referential integrity)
|
- need to delete all classes (and watch for referential integrity)
|
||||||
- need to add 1 author to book, book to sub_book, series
|
- need to add 1 author to book, book to sub_book, series
|
||||||
@@ -41,4 +43,3 @@ python3 main.py
|
|||||||
when moving a book in a series (which is part of 2 series), do we pop-up
|
when moving a book in a series (which is part of 2 series), do we pop-up
|
||||||
offer to move parent/child series orders as well to match (think Thomas Covenant)
|
offer to move parent/child series orders as well to match (think Thomas Covenant)
|
||||||
|
|
||||||
try to "export" db from sqlalchemy to see what it is doing with sequences / primary key for owned table and maybe "new_id" not needed?
|
|
||||||
|
|||||||
1
main.py
1
main.py
@@ -112,6 +112,7 @@ class Book(db.Model):
|
|||||||
def LastSubBookNum(self):
|
def LastSubBookNum(self):
|
||||||
# need to work out the last sub book and return an id?
|
# need to work out the last sub book and return an id?
|
||||||
if self.IsParent():
|
if self.IsParent():
|
||||||
|
# -1 subscript returns the last one
|
||||||
return self.child_ref[-1].sub_book_num
|
return self.child_ref[-1].sub_book_num
|
||||||
else:
|
else:
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
43
owned.py
43
owned.py
@@ -2,13 +2,14 @@ from wtforms import SubmitField, StringField, HiddenField, SelectField, validato
|
|||||||
from flask import request, render_template
|
from flask import request, render_template
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from __main__ import db, app, ma
|
from __main__ import db, app, ma
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func, Sequence
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Class describing Owned in the database, and via sqlalchemy, connected to the DB as well
|
# Class describing Owned in the database, and via sqlalchemy, connected to the DB as well
|
||||||
################################################################################
|
################################################################################
|
||||||
class Owned(db.Model):
|
class Owned(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True )
|
id = db.Column(db.Integer, db.Sequence('owned_id_seq'), primary_key=True )
|
||||||
name = db.Column(db.String(50), unique=True, nullable=False)
|
name = db.Column(db.String(50), unique=True, nullable=False)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -20,7 +21,6 @@ class Owned(db.Model):
|
|||||||
class OwnedSchema(ma.SQLAlchemyAutoSchema):
|
class OwnedSchema(ma.SQLAlchemyAutoSchema):
|
||||||
class Meta: model = Owned
|
class Meta: model = Owned
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Helper class that defines a form for owned, used to make html <form>, with field validation (via wtforms)
|
# Helper class that defines a form for owned, used to make html <form>, with field validation (via wtforms)
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -40,6 +40,25 @@ def owneds():
|
|||||||
owneds = Owned.query.order_by('id').all()
|
owneds = Owned.query.order_by('id').all()
|
||||||
return render_template("show_id_name.html", objects=owneds, page_title='Show All Ownership types', url_base='owned')
|
return render_template("show_id_name.html", objects=owneds, page_title='Show All Ownership types', url_base='owned')
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# /owned -> GET/POST -> creates a new owned type and when created, takes you back to /owneds
|
||||||
|
################################################################################
|
||||||
|
@app.route("/owned", methods=["GET", "POST"])
|
||||||
|
def new_owned():
|
||||||
|
alert="success"
|
||||||
|
owned_form = OwnedForm(request.form)
|
||||||
|
if 'name' not in request.form:
|
||||||
|
owned=None
|
||||||
|
message=""
|
||||||
|
return render_template("edit_id_name.html", owned=owned, alert=alert, message=message, form=owned_form, page_title='Create new Owned Type' )
|
||||||
|
else:
|
||||||
|
owned = Owned( name=request.form["name"] )
|
||||||
|
db.session.add(owned)
|
||||||
|
db.session.commit()
|
||||||
|
message="Created new Owned Type (id={})".format(owned.id)
|
||||||
|
owneds = Owned.query.order_by('id').all()
|
||||||
|
return render_template("show_id_name.html", objects=owneds, page_title='Show All Ownership types', url_base='owned', alert=alert, message=message)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# /owned/<id> -> GET/POST(save or delete) -> shows/edits/delets a single
|
# /owned/<id> -> GET/POST(save or delete) -> shows/edits/delets a single
|
||||||
# owned
|
# owned
|
||||||
@@ -47,24 +66,8 @@ def owneds():
|
|||||||
@app.route("/owned/<id>", methods=["GET", "POST"])
|
@app.route("/owned/<id>", methods=["GET", "POST"])
|
||||||
def owned(id):
|
def owned(id):
|
||||||
alert="success"
|
alert="success"
|
||||||
owned_form = OwnedForm(request.form)
|
|
||||||
if id == "-1":
|
|
||||||
if 'name' not in request.form:
|
|
||||||
owned=None
|
|
||||||
message=""
|
|
||||||
return render_template("edit_id_name.html", owned=owned, alert=alert, message=message, form=owned_form, page_title='Create new Owned Type' )
|
|
||||||
else:
|
|
||||||
res=db.session.query(func.max(Owned.id)).all()
|
|
||||||
new_id=res[0][0]
|
|
||||||
new_id=new_id+1
|
|
||||||
owned = Owned( id=new_id, name=request.form["name"] )
|
|
||||||
db.session.add(owned)
|
|
||||||
db.session.commit()
|
|
||||||
message="Created new Owned Type (id={})".format(new_id)
|
|
||||||
owneds = Owned.query.order_by('id').all()
|
|
||||||
return render_template("show_id_name.html", objects=owneds, page_title='Show All Ownership types', url_base='owned', alert=alert, message=message)
|
|
||||||
|
|
||||||
### DDP: should this be request.form or request.values?
|
### DDP: should this be request.form or request.values?
|
||||||
|
owned_form = OwnedForm(request.form)
|
||||||
if request.method == 'POST' and owned_form.validate():
|
if request.method == 'POST' and owned_form.validate():
|
||||||
owned = Owned.query.get(id)
|
owned = Owned.query.get(id)
|
||||||
if 'delete' in request.form:
|
if 'delete' in request.form:
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
<a class="dropdown-item" href="{{url_for('conditions')}}">Show Conditions</a>
|
<a class="dropdown-item" href="{{url_for('conditions')}}">Show Conditions</a>
|
||||||
<a class="dropdown-item" href="{{url_for('covertypes')}}">Create new Covertype</a>
|
<a class="dropdown-item" href="{{url_for('covertypes')}}">Create new Covertype</a>
|
||||||
<a class="dropdown-item" href="{{url_for('covertypes')}}">Show Covertypes</a>
|
<a class="dropdown-item" href="{{url_for('covertypes')}}">Show Covertypes</a>
|
||||||
<a class="dropdown-item" href="{{url_for('owned', id=-1)}}">Create new Owned Type</a>
|
<a class="dropdown-item" href="/owned">Create new Owned Type</a>
|
||||||
<a class="dropdown-item" href="{{url_for('owneds')}}">Show Ownership Types</a>
|
<a class="dropdown-item" href="{{url_for('owneds')}}">Show Ownership Types</a>
|
||||||
<a class="dropdown-item" href="{{url_for('ratings')}}">Create new Rating</a>
|
<a class="dropdown-item" href="{{url_for('ratings')}}">Create new Rating</a>
|
||||||
<a class="dropdown-item" href="{{url_for('ratings')}}">Show Ratings</a>
|
<a class="dropdown-item" href="{{url_for('ratings')}}">Show Ratings</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user