From 894a609f3fb18d566a61b1a4aa979ebe356a0f1b Mon Sep 17 00:00:00 2001 From: j Date: Tue, 12 Mar 2019 15:51:13 +0000 Subject: [PATCH 1/2] json_dump shortcut --- pandora/oxdjango/shortcuts.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pandora/oxdjango/shortcuts.py b/pandora/oxdjango/shortcuts.py index f2a98662..8246a98a 100644 --- a/pandora/oxdjango/shortcuts.py +++ b/pandora/oxdjango/shortcuts.py @@ -25,14 +25,20 @@ def _to_json(python_object): return python_object.strftime('%Y-%m-%dT%H:%M:%SZ') raise TypeError(u'%s %s is not JSON serializable' % (repr(python_object), type(python_object))) +def json_dump(data, fp, indent=4): + return json.dump(data, fp, indent=indent, default=_to_json, ensure_ascii=False) + +def json_dumps(data, indent=4): + return json.dumps(data, indent=indent, default=_to_json, ensure_ascii=False) + def render_to_json_response(dictionary, content_type="application/json", status=200): indent = None if settings.DEBUG: content_type = "text/javascript" indent = 2 if getattr(settings, 'JSON_DEBUG', False): - print(json.dumps(dictionary, indent=2, default=_to_json, ensure_ascii=False).encode('utf-8')) - response = json.dumps(dictionary, indent=indent, default=_to_json, ensure_ascii=False) + print(json_dumps(dictionary, indent=2).encode('utf-8')) + response = json_dumps(dictionary, indent=indent) if not isinstance(response, bytes): response = response.encode('utf-8') return HttpResponse(response, content_type=content_type, status=status) From 302af9cda4d4840040938a0d4a0012d6682e06b0 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 12 Mar 2019 17:48:03 +0000 Subject: [PATCH 2/2] fix findindex in postgresql 10 --- pandora/item/management/commands/sqlfindindex.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pandora/item/management/commands/sqlfindindex.py b/pandora/item/management/commands/sqlfindindex.py index bba3a247..c651e18f 100644 --- a/pandora/item/management/commands/sqlfindindex.py +++ b/pandora/item/management/commands/sqlfindindex.py @@ -45,12 +45,16 @@ class Command(BaseCommand): indexes = connection.introspection.get_indexes(cursor, table) drop = [] if column in indexes: - sql = "SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \ - "WHERE indexdef LIKE '%ON {table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column) - cursor.execute(sql) - for r in cursor: - if 'USING gin' not in r[1]: - drop.append(r[0]) + for sql in ( + "SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \ + "WHERE indexdef LIKE '%ON {table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column), + "SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \ + "WHERE indexdef LIKE '%ON public.{table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column), + ): + cursor.execute(sql) + for r in cursor: + if 'USING gin' not in r[1]: + drop.append(r[0]) if drop: for idx in drop: sql = 'DROP INDEX ' + idx