From 55d587f6d0d384972d8982bfd572ca1329e05e76 Mon Sep 17 00:00:00 2001 From: Matthew Scragg Date: Thu, 16 Jan 2014 17:46:22 -0600 Subject: [PATCH] flask make response --- realms/__init__.py | 15 ++++++++++++++- realms/modules/wiki/views.py | 2 -- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/realms/__init__.py b/realms/__init__.py index 87a2b06..84c450a 100644 --- a/realms/__init__.py +++ b/realms/__init__.py @@ -17,7 +17,7 @@ logging.getLogger('requests').setLevel(logging.WARNING) import time import sys -import os +import json import httplib import traceback from flask import Flask, request, render_template, url_for, redirect, session, flash, g @@ -129,6 +129,19 @@ class Application(Flask): print >> sys.stderr, ' * Ready in %.2fms' % (1000.0 * (time.time() - start_time)) + def make_response(self, rv): + if rv is None: + rv = '', httplib.NO_CONTENT + elif not isinstance(rv, tuple): + rv = rv, + + rv = list(rv) + + if isinstance(rv[0], (list, dict)): + rv[0] = self.response_class(json.dumps(rv[0]), mimetype='application/json') + + return super(Application, self).make_response(tuple(rv)) + class RegexConverter(BaseConverter): """ diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index 0384931..950901d 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -70,8 +70,6 @@ def delete(name): @blueprint.route("/wiki/_create/", defaults={'name': None}, methods=['GET', 'POST']) @blueprint.route("/wiki/_create/", methods=['GET', 'POST']) def create(name): - - if request.method == 'POST': g.current_wiki.write_page(request.form['name'], request.form['content'],