def do_show(path, action='show'): content = None rev_info = None lock_info = None # Handle help document if path.startswith(HELP_PREFIX): if action not in ('render', 'show'): raise InvalidRequest() # Get document data try: mimetype, size, content = get_help(path[len(HELP_PREFIX):]) except: mimetype, size, content = None if action == 'render': return render_document(content) else: return Response(render_template('wiki/show.html', content=content, immutable=True), 404 if content is None else 200) # Check for file document is_file = path.startswith(FILE_PREFIX) # Unlock document if needed if request.args.get('discard'): lock_document(path, (session.get('login'), session.get('id')), unlock=True) return redirect(url_for('index', path=path)) elif action == 'edit' and request.args.get('force'): lock_document(path, (session.get('login'), session.get('id')), unlock=True, force=True) return redirect(url_for('index', path=path, do='edit')) # Lock document for edition if action == 'edit': lock_info = lock_document(path, (session.get('login'), session.get('id'))) # Get document data try: mimetype, size, meta, content = get_document(path, request.args.get('rev'), meta=(action == 'edit'), preview=is_file) except DocumentNotFound: mimetype, size, meta, content = None, 0, None, None if action == 'edit': meta = None # Handle normal documents if action == 'edit' and 'data' in request.form: content = request.form.get('data') else: if content is not None: # Get last revision information rev_info = get_history(path, rev=request.args.get('rev', -1)) elif is_file and not path[len(FILE_PREFIX):]: # Force edition if unnamed file action = 'edit' # Render document and exit if needed if action == 'render': return render_document(content) response = Response(render_template('wiki/%s.html' % action, is_file=is_file, mimetype=mimetype, meta=meta, content=content, rev_info=rev_info, lock_info=lock_info), 404 if content is None else 200) if action == 'edit': response.cache_control.no_cache = True return response
def filter_render(data, toc=False): return Markup(render_document(data, toc))