[odrs-web] Split out a file to avoid a traceback in the admin panel



commit 81d0006a3325d12ffeea980a2b9c218263078bd0
Author: Richard Hughes <richard hughsie com>
Date:   Wed Jun 26 12:57:49 2019 +0100

    Split out a file to avoid a traceback in the admin panel

 app_data/app/util.py        | 32 ++++++++++++++++++++++++++++++++
 app_data/app/views.py       | 24 +-----------------------
 app_data/app/views_admin.py |  1 +
 3 files changed, 34 insertions(+), 23 deletions(-)
---
diff --git a/app_data/app/util.py b/app_data/app/util.py
new file mode 100644
index 0000000..92d96bf
--- /dev/null
+++ b/app_data/app/util.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2019 Richard Hughes <richard hughsie com>
+#
+# SPDX-License-Identifier: GPL-3.0+
+
+import json
+
+from flask import Response
+
+def json_success(msg=None, errcode=200):
+    """ Success handler: JSON output """
+    item = {}
+    item['success'] = True
+    if msg:
+        item['msg'] = msg
+    dat = json.dumps(item, sort_keys=True, indent=4, separators=(',', ': '))
+    return Response(response=dat,
+                    status=errcode, \
+                    mimetype="application/json")
+
+def json_error(msg=None, errcode=400):
+    """ Error handler: JSON output """
+    item = {}
+    item['success'] = False
+    if msg:
+        item['msg'] = msg
+    dat = json.dumps(item, sort_keys=True, indent=4, separators=(',', ': '))
+    return Response(response=dat,
+                    status=errcode, \
+                    mimetype="application/json")
diff --git a/app_data/app/views.py b/app_data/app/views.py
index f788e6e..1f79406 100644
--- a/app_data/app/views.py
+++ b/app_data/app/views.py
@@ -19,6 +19,7 @@ from app import app, get_db
 
 from .db import CursorError
 from .models import Review
+from .util import json_success, json_error
 
 def _get_user_key(user_hash, app_id):
     salt = os.environ['ODRS_REVIEWS_SECRET']
@@ -166,34 +167,11 @@ def static_resource(resource):
     """ Return a static image or resource """
     return send_from_directory("%s/app/static/" % os.environ['HOME'], os.path.basename(resource))
 
-@app.errorhandler(400)
-def json_error(msg=None, errcode=400):
-    """ Error handler: JSON output """
-    item = {}
-    item['success'] = False
-    if msg:
-        item['msg'] = msg
-    dat = json.dumps(item, sort_keys=True, indent=4, separators=(',', ': '))
-    return Response(response=dat,
-                    status=errcode, \
-                    mimetype="application/json")
-
 @app.errorhandler(401)
 def _error_permission_denied(msg=None):
     """ Error handler: Permission Denied """
     return json_error(msg, 401)
 
-def json_success(msg=None, errcode=200):
-    """ Success handler: JSON output """
-    item = {}
-    item['success'] = True
-    if msg:
-        item['msg'] = msg
-    dat = json.dumps(item, sort_keys=True, indent=4, separators=(',', ': '))
-    return Response(response=dat,
-                    status=errcode, \
-                    mimetype="application/json")
-
 def _check_str(val):
     """ Return with success if the summary and description """
     if val.find('<') != -1:
diff --git a/app_data/app/views_admin.py b/app_data/app/views_admin.py
index 2f77fbb..234ffcb 100644
--- a/app_data/app/views_admin.py
+++ b/app_data/app/views_admin.py
@@ -16,6 +16,7 @@ from flask_login import login_required, current_user
 
 from app import app, get_db
 from .db import CursorError
+from .util import json_error
 
 def _get_chart_labels_months():
     """ Gets the chart labels """


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]