removed all old *_lst tables, added corresponding new classes, etc. fro covertype, owned, rating, and dropped tables from DB, etc. Updated base.html to use new tables as drop-downs that are set correctly. So far slight hack on BookForm, will finish that after syncing this all back to mara. If I do the sync, and export/import this version of DB, then the fixes.sql and fix_db() code included in main.py can be removed. Finally, lamely added a favicon and a static/ to support it
This commit is contained in:
66
owned.py
Normal file
66
owned.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from wtforms import SubmitField, StringField, HiddenField, SelectField, validators, Form
|
||||
from flask import request, render_template
|
||||
from __main__ import db, app, ma
|
||||
|
||||
################################################################################
|
||||
# Class describing Owned in the database, and via sqlalchemy, connected to the DB as well
|
||||
################################################################################
|
||||
class Owned(db.Model):
|
||||
id = db.Column(db.Integer, unique=True, nullable=False, primary_key=True)
|
||||
name = db.Column(db.String(50), unique=False, nullable=False)
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, name: {}>".format(self.id,self.name)
|
||||
|
||||
################################################################################
|
||||
# Helper class that inherits a .dump() method to turn class Owned into json / useful in jinja2
|
||||
################################################################################
|
||||
class OwnedSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta: model = Owned
|
||||
|
||||
|
||||
################################################################################
|
||||
# Helper class that defines a form for owned, used to make html <form>, with field validation (via wtforms)
|
||||
################################################################################
|
||||
class OwnedForm(Form):
|
||||
id = HiddenField()
|
||||
name = StringField('Name:', [validators.DataRequired()])
|
||||
submit = SubmitField('Save' )
|
||||
delete = SubmitField('Delete' )
|
||||
|
||||
################################################################################
|
||||
# Routes for owned data
|
||||
#
|
||||
# /owneds -> GET only -> prints out list of all owneds
|
||||
################################################################################
|
||||
@app.route("/owneds", methods=["GET"])
|
||||
def owneds():
|
||||
owneds = Owned.query.order_by('id').all()
|
||||
return render_template("owneds.html", owneds=owneds)
|
||||
|
||||
################################################################################
|
||||
# /owned/<id> -> GET/POST(save or delete) -> shows/edits/delets a single
|
||||
# owned
|
||||
################################################################################
|
||||
@app.route("/owned/<id>", methods=["GET", "POST"])
|
||||
def owned(id):
|
||||
### DDP: should this be request.form or request.values?
|
||||
alert="Success"
|
||||
owned_form = OwnedForm(request.form)
|
||||
if request.method == 'POST' and owned_form.validate():
|
||||
id = request.form['id']
|
||||
owned = Owned.query.get(id)
|
||||
try:
|
||||
request.form['submit']
|
||||
except:
|
||||
message="Sorry, Deleting unsupported at present"
|
||||
alert="Danger"
|
||||
else:
|
||||
owned.name = request.form['name']
|
||||
db.session.commit()
|
||||
message="Successfully Updated Owned (id={})".format(id)
|
||||
else:
|
||||
owned = Owned.query.get(id)
|
||||
owned_form = OwnedForm(request.values, obj=owned)
|
||||
message=""
|
||||
return render_template("owned.html", owned=owned, alert=alert, message=message, owned_form=owned_form)
|
||||
Reference in New Issue
Block a user