From 0157faa8db064d71dc62588f6a83cecb1b8a35bd Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sun, 18 Nov 2018 11:31:21 +0100 Subject: [PATCH] Make scrolling message conditionally include information. This fixes a number of Nonetype accessing bugs when things are not present in the database. Have manually tested this for now. --- xppl/views.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/xppl/views.py b/xppl/views.py index 342cf56..4b1b4c8 100755 --- a/xppl/views.py +++ b/xppl/views.py @@ -157,20 +157,33 @@ def uploaded_file_cover(filename): @app.route('/updates', methods=['POST', 'GET']) def get_updates(): - userin = UserIns.query.filter_by(title="lastViewed").first() allbooks = db.session.query(Book).all() - latest_upload = allbooks[-1] - return ( - "This is the XPPL ~ Library XPUB ~ Updates / / / / / / / Last viewed: " - + userin.info - + " / / / / / / / " - + str(len(allbooks)) - + " Books online " - + " / / / / / / / " - + "Latest entry: " - + latest_upload.title + + scrolling_message = ( + '{domain} ~ XPPL ~ Updates' + ' / / / / / / / ' + '{count} books online ' + ).format( + domain=app.config['DOMAIN'], + count=str(len(allbooks)) ) + userin = UserIns.query.filter_by(title='lastViewed').first() + if userin: + scrolling_message += ( + ' / / / / / / / ' + ' Last viewed: {user}' + ).format(user=userin.info) + + if allbooks: + latest_upload = allbooks[-1] + scrolling_message += ( + ' / / / / / / / ' + 'Latest entry: {title}' + ).format(title=latest_upload.title) + + return scrolling_message + @app.route('/volumetric_catalog', methods=['GET']) def volumetric_catalog():