def _get_session(): # TODO Get user from auth user = '******' # TODO cache sessions s = Metadata( { 'user' : str, 'conf' : Metadata, 'engine' : Engine } ) s.user = user s.conf = conf try: s.engine = conf.engine(s) except Exception: log.x('fail to initialize session: User = %s' % s.user) abort(500) return s
def edit(user, file_path): '''Setup Edit form and fill it with file content''' s = _get_session() try: # TODO adjust preview and finish URIs in form.html return render_template('form.html', content=s.engine.get_file_content(file_path)) except Exception as e: log.x('fail to retrieve content from: %s' % file_path) return redirect('/') # TODO move preview code into own method (save_and_preview) # and call it asynchronously? Use fancy user feedback. if request.method == 'POST': try: s.engine.store_file(file_path, new_content) except Exception as e: print e # TODO something messed the commit up # there is no way to solve this exception # return message to user and send stacktrace to admin try: s.engine.preview(file_path) except Exception as e: print e # TODO the file content could be faulty and cause an # render error # return user feedback # TODO move edit_finish code into own method if request.form.get('save'): save(file_path) # faulty request abort(500)