Fixed BUG-02 (recalc rating on book change), also added route to reset all ratings in Admin menu
This commit is contained in:
21
series.py
21
series.py
@@ -42,8 +42,8 @@ class SeriesForm(FlaskForm):
|
||||
def CalcAvgRating(sid):
|
||||
res=db.engine.execute("select round(avg(to_number(r.name, '99')),1) as rating from book b, rating r, series s, book_series_link bsl where s.id={} and s.id = bsl.series_id and bsl.book_id = b.id and b.rating = r.id and r.name ~ E'^\\\\d+$'".format(sid))
|
||||
for row in res:
|
||||
print( row )
|
||||
return row.rating
|
||||
rating = row.rating
|
||||
return rating
|
||||
|
||||
def ListOfSeriesWithMissingBooks():
|
||||
res=db.engine.execute("select id, title, num_books, count from ( select s.id, s.title, s.num_books, count(bsl.book_id) from series s, book_series_link bsl where s.id = bsl.series_id group by s.id ) as foo where num_books > count")
|
||||
@@ -121,6 +121,23 @@ def series(id):
|
||||
form = SeriesForm(request.values, obj=series)
|
||||
return render_template("series.html", form=form, page_title=page_title, message=st.GetMessage(), alert=st.GetAlert() )
|
||||
|
||||
################################################################################
|
||||
# /series/rating_reset -> forces a reset of calculated ratings of all series
|
||||
################################################################################
|
||||
@app.route("/seriess/rating_reset", methods=["GET"])
|
||||
def reset_all_series_ratings():
|
||||
s_list = Series.query.all()
|
||||
try:
|
||||
for s in s_list:
|
||||
s.calcd_rating = CalcAvgRating(s.id)
|
||||
db.session.commit()
|
||||
st.SetMessage("Successfully reset calculated average ratings for all series");
|
||||
return render_template("base.html", message=st.GetMessage(), alert=st.GetAlert() )
|
||||
except:
|
||||
st.SetAlert("danger")
|
||||
st.SetMessage("Failed to reset calculated average rating for all series");
|
||||
return render_template("base.html", message=st.GetMessage(), alert=st.GetAlert() )
|
||||
|
||||
################################################################################
|
||||
# Gets the Series matching id from DB, helper func in jinja2 code to show books
|
||||
################################################################################
|
||||
|
||||
Reference in New Issue
Block a user