fixed BUGS 28/29 -> can now have empty year_published, fixed up limits to 1850-2100 now too and better error messages. Also auto-change when choose wishlist
This commit is contained in:
2
BUGs
2
BUGs
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
#### BUGS (next-30)
|
#### BUGS (next-30)
|
||||||
BUG-27: created a new book, with a series, series was not added
|
BUG-27: created a new book, with a series, series was not added
|
||||||
BUG-28: choosing on wish list, does not alter the condition/covertype, etc. (anymore?)
|
|
||||||
BUG-29: saving a book on wish list needs a year_published (shouldn't)
|
|
||||||
|
|
||||||
### DB/back-end
|
### DB/back-end
|
||||||
|
|
||||||
|
|||||||
56
main.py
56
main.py
@@ -3,7 +3,7 @@ from flask_sqlalchemy import SQLAlchemy
|
|||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from flask_marshmallow import Marshmallow
|
from flask_marshmallow import Marshmallow
|
||||||
from flask_bootstrap import Bootstrap
|
from flask_bootstrap import Bootstrap
|
||||||
from wtforms import SubmitField, StringField, HiddenField, SelectField, IntegerField, TextAreaField, validators
|
from wtforms import SubmitField, StringField, HiddenField, SelectField, IntegerField, TextAreaField, validators, ValidationError
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
#from flask_compress import Compress
|
#from flask_compress import Compress
|
||||||
from status import st, Status
|
from status import st, Status
|
||||||
@@ -65,6 +65,12 @@ from loan import Loan, LoanForm, LoanSchema
|
|||||||
from series import Series, SeriesForm, SeriesSchema, ListOfSeriesWithMissingBooks, CalcAvgRating
|
from series import Series, SeriesForm, SeriesSchema, ListOfSeriesWithMissingBooks, CalcAvgRating
|
||||||
from user import BDBUser
|
from user import BDBUser
|
||||||
|
|
||||||
|
|
||||||
|
# hacky constants (FIX THIS)
|
||||||
|
ON_WISHLIST=2
|
||||||
|
COVERTYPE_NOT_APPLICABLE=4
|
||||||
|
CONDITION_NOT_APPLICABLE=4
|
||||||
|
|
||||||
####################################### CLASSES / DB model #######################################
|
####################################### CLASSES / DB model #######################################
|
||||||
class QuickParentBook:
|
class QuickParentBook:
|
||||||
parent=[]
|
parent=[]
|
||||||
@@ -223,7 +229,7 @@ class BookForm(FlaskForm):
|
|||||||
owned = SelectField( 'owned' )
|
owned = SelectField( 'owned' )
|
||||||
covertype = SelectField( 'covertype' )
|
covertype = SelectField( 'covertype' )
|
||||||
condition = SelectField( 'condition' )
|
condition = SelectField( 'condition' )
|
||||||
year_published = IntegerField('Year Published:', validators=[validators.DataRequired(), validators.NumberRange(min=1900, max=2100)] )
|
year_published = IntegerField('Year Published:', validators=[validators.Optional(), validators.NumberRange(min=1850, max=2100)] )
|
||||||
rating = SelectField( 'rating' )
|
rating = SelectField( 'rating' )
|
||||||
notes = TextAreaField('Notes:')
|
notes = TextAreaField('Notes:')
|
||||||
blurb = TextAreaField('Blurb:')
|
blurb = TextAreaField('Blurb:')
|
||||||
@@ -232,6 +238,25 @@ class BookForm(FlaskForm):
|
|||||||
add_sub = SubmitField('Add Sub-Book' )
|
add_sub = SubmitField('Add Sub-Book' )
|
||||||
rem_sub = SubmitField('Remove Sub-Book from Parent' )
|
rem_sub = SubmitField('Remove Sub-Book from Parent' )
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
print( f"type: self.errors={type(self.errors)}" )
|
||||||
|
# if on wish list, just accept year_published
|
||||||
|
if int(self.owned.data) == ON_WISHLIST:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
# we own/sold this, so covertype and condition cant be N/A
|
||||||
|
if int(self.covertype.data) == COVERTYPE_NOT_APPLICABLE:
|
||||||
|
return False
|
||||||
|
if int(self.condition.data) == CONDITION_NOT_APPLICABLE:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# otherwise lets check that there is data and its in the right range
|
||||||
|
if self.year_published.data and self.year_published.data>1850 and int(self.year_published.raw_data[0]) < 2100:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
################################# helper functions ###################################
|
################################# helper functions ###################################
|
||||||
def GetBookIdFromSeriesByBookNum( series_id, book_num ):
|
def GetBookIdFromSeriesByBookNum( series_id, book_num ):
|
||||||
tmp_book = Book_Series_Link.query.filter(Book_Series_Link.series_id==series_id,Book_Series_Link.book_num==book_num).all()
|
tmp_book = Book_Series_Link.query.filter(Book_Series_Link.series_id==series_id,Book_Series_Link.book_num==book_num).all()
|
||||||
@@ -547,7 +572,11 @@ def new_book():
|
|||||||
form.process()
|
form.process()
|
||||||
return render_template("book.html", page_title='Create new (sub) Book', b=bb, books=None, book_form=form, author_list=author_list, genre_list=genre_list, alert="", message="", poss_series_list=ListOfSeriesWithMissingBooks() )
|
return render_template("book.html", page_title='Create new (sub) Book', b=bb, books=None, book_form=form, author_list=author_list, genre_list=genre_list, alert="", message="", poss_series_list=ListOfSeriesWithMissingBooks() )
|
||||||
elif form.validate_on_submit() and len(book_genres):
|
elif form.validate_on_submit() and len(book_genres):
|
||||||
book = Book( title=request.form['title'], owned=request.form['owned'], covertype=request.form['covertype'], condition=request.form['condition'], publisher=request.form['publisher'], year_published=request.form['year_published'], rating=request.form['rating'], notes=request.form['notes'], blurb=request.form['blurb'], genre=book_genres, author=book_authors )
|
if request.form['year_published'].isnumeric():
|
||||||
|
book = Book( title=request.form['title'], owned=request.form['owned'], covertype=request.form['covertype'], condition=request.form['condition'], publisher=request.form['publisher'], year_published=request.form['year_published'], rating=request.form['rating'], notes=request.form['notes'], blurb=request.form['blurb'], genre=book_genres, author=book_authors )
|
||||||
|
else:
|
||||||
|
book = Book( title=request.form['title'], owned=request.form['owned'], covertype=request.form['covertype'], condition=request.form['condition'], publisher=request.form['publisher'], rating=request.form['rating'], notes=request.form['notes'], blurb=request.form['blurb'], genre=book_genres, author=book_authors )
|
||||||
|
|
||||||
db.session.add(book)
|
db.session.add(book)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
# this is a sub-book we have added
|
# this is a sub-book we have added
|
||||||
@@ -574,13 +603,17 @@ def new_book():
|
|||||||
return redirect( '/book/{}'.format(book.id) )
|
return redirect( '/book/{}'.format(book.id) )
|
||||||
else:
|
else:
|
||||||
alert="danger"
|
alert="danger"
|
||||||
message="Failed to create Book"
|
message="Failed to create Book."
|
||||||
for field in form.errors:
|
for field in form.errors:
|
||||||
message = "{}<br>{}={}".format( message, field, form.errors[field] )
|
message = "{}<br>{}={}".format( message, field, form.errors[field] )
|
||||||
if len(book_genres) == 0:
|
if len(book_genres) == 0:
|
||||||
message = "{}<br>genre=book has to have a genre selected".format( message )
|
message = "{}<br>genre=book has to have a genre selected".format( message )
|
||||||
print( "ERROR: Failed to create book: {}".format(message) )
|
print( "ERROR: Failed to create book: {}".format(message) )
|
||||||
book = Book( title=request.form["title"], owned=request.form['owned'], covertype=request.form['covertype'], condition=request.form['condition'], publisher=request.form['publisher'], year_published=request.form['year_published'], rating=request.form['rating'], notes=request.form['notes'], blurb=request.form['blurb'], genre=book_genres, author=book_authors )
|
if request.form['year_published'].isnumeric():
|
||||||
|
book = Book( title=request.form["title"], owned=request.form['owned'], covertype=request.form['covertype'], condition=request.form['condition'], publisher=request.form['publisher'], year_published=request.form['year_published'], rating=request.form['rating'], notes=request.form['notes'], blurb=request.form['blurb'], genre=book_genres, author=book_authors )
|
||||||
|
else:
|
||||||
|
book = Book( title=request.form["title"], owned=request.form['owned'], covertype=request.form['covertype'], condition=request.form['condition'], publisher=request.form['publisher'], rating=request.form['rating'], notes=request.form['notes'], blurb=request.form['blurb'], genre=book_genres, author=book_authors )
|
||||||
|
|
||||||
if 'parent_id' in request.form:
|
if 'parent_id' in request.form:
|
||||||
bb=QuickParentBook()
|
bb=QuickParentBook()
|
||||||
bb.parent=[]
|
bb.parent=[]
|
||||||
@@ -643,7 +676,8 @@ def book(id):
|
|||||||
book.covertype = request.form['covertype']
|
book.covertype = request.form['covertype']
|
||||||
book.condition = request.form['condition']
|
book.condition = request.form['condition']
|
||||||
book.publisher = request.form['publisher']
|
book.publisher = request.form['publisher']
|
||||||
book.year_published = request.form['year_published']
|
if request.form['year_published'].isnumeric():
|
||||||
|
book.year_published = request.form['year_published']
|
||||||
book.rating = request.form['rating']
|
book.rating = request.form['rating']
|
||||||
book.notes = request.form['notes']
|
book.notes = request.form['notes']
|
||||||
book.blurb = request.form['blurb']
|
book.blurb = request.form['blurb']
|
||||||
@@ -715,9 +749,13 @@ def book(id):
|
|||||||
st.SetMessage( "Successfully Updated Book (id={})".format(id) )
|
st.SetMessage( "Successfully Updated Book (id={})".format(id) )
|
||||||
else:
|
else:
|
||||||
st.SetAlert("danger")
|
st.SetAlert("danger")
|
||||||
message="Failed to update Book (id={})".format(id)
|
message=f"Failed to update Book (id={id}). "
|
||||||
for field in book_form.errors:
|
if not book_form.year_published.data:
|
||||||
message = "{}<br>{}={}".format( message, field, book_form.errors[field] )
|
message += f" year_published cannot be empty";
|
||||||
|
if int(book_form.condition.data) == CONDITION_NOT_APPLICABLE:
|
||||||
|
message += f" condition cannot be N/A";
|
||||||
|
if int(book_form.covertype.data) == COVERTYPE_NOT_APPLICABLE:
|
||||||
|
message += f" covertype cannot be N/A";
|
||||||
book = Book.query.get(id)
|
book = Book.query.get(id)
|
||||||
st.SetMessage(message)
|
st.SetMessage(message)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -436,6 +436,7 @@ function AddAuthorToBook(num) {
|
|||||||
function() { $('#author-{{cnt.idx}}').prop( 'style', '' ) } )
|
function() { $('#author-{{cnt.idx}}').prop( 'style', '' ) } )
|
||||||
{% set cnt.idx = cnt.idx+1 %}
|
{% set cnt.idx = cnt.idx+1 %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
$('#owned').click( function() { if( $("#owned option:selected").text() == 'On Wish List' ) { $('#covertype').val( $('#covertype option:last').val() ); $('#condition').val( $('#condition option:last').val() ); $('#year_published').val(''); $('#rating').val( $('#rating option:last').val() ) } } )
|
||||||
} )
|
} )
|
||||||
</script>
|
</script>
|
||||||
{% endblock script_content %}
|
{% endblock script_content %}
|
||||||
|
|||||||
Reference in New Issue
Block a user