# HG changeset patch # User Benoît Allard # Date 1412082745 -7200 # Node ID eedf9606ab33ed2faa864f458b3dff11e7f0edb2 # Parent f8d51aaac8bc618ed060eda8dce22e83c170776d Add more error handling in the caching system diff -r f8d51aaac8bc -r eedf9606ab33 CHANGES --- a/CHANGES Tue Sep 30 14:45:03 2014 +0200 +++ b/CHANGES Tue Sep 30 15:12:25 2014 +0200 @@ -4,17 +4,17 @@ This is the first patch release of Farol 0.1, it fixes various issues, and improve usability. - Thanks to all the contributors: Michael Wiegand and Benoît Allard. Main changes since 0.1: ----------------------- -* Ease the import of documents, with various shortcuts -* Add a Welcome page -* Add loging of the exceptions to a farol.log file (in the instance dir) +* Ease the import of documents, with various shortcuts. +* Add a Welcome page. +* Add loging of the exceptions to a ``farol.log`` file (in the instance dir). * Implement three different kind of 'caching': disableds, global or session-based. +* Various styling improvements. Farol 0.1 (2014-09-24) diff -r f8d51aaac8bc -r eedf9606ab33 farol/cache.py --- a/farol/cache.py Tue Sep 30 14:45:03 2014 +0200 +++ b/farol/cache.py Tue Sep 30 15:12:25 2014 +0200 @@ -29,7 +29,7 @@ import os from flask import (Blueprint, current_app, session, flash, redirect, url_for, - render_template, request) + render_template, request, abort) from werkzeug import secure_filename from farolluz.parsers.cvrf import parse @@ -85,6 +85,10 @@ @mod.route('/save', methods=['GET', 'POST']) @document_required def save(): + if caching_type() is None: + current_app.logger.warning('Tried to save although caching is disabled.') + flash('This version does not allow you to save your document !', 'danger') + abort(403) if request.method != 'POST': return render_template('cache/save.j2', id_=get_current()._tracking._identification._id) @@ -108,7 +112,17 @@ # Ouch, GET request changing state of the server ... dirname = _caching_dir() + element = secure_filename(element) + if dirname is None: + current_app.logger.warning('Tried to load something although no' + ' caching dir present: %s' % element) + flash('Not able to load %s' % element) + abort(404) fpath = os.path.join(dirname, element+'.xml') + if not os.path.exists(fpath): + current_app.logger.warning('Tried to load an unexisting document: %s' % element) + flash('Document %s does not exists !' % element) + abort(404) with open(fpath, 'rt') as f: set_current(parse(f)) os.remove(fpath)