From ff9157dc7ef4e74e3c919cf9f3f7cef858d72c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Mon, 22 Jun 2020 09:48:37 +0200 Subject: [PATCH] Commit forgotten changes from last night --- bite/bite/admin.py | 23 +++++++++++++++++++++++ bite/bite/settings.py | 1 + bite/telemetry/admin.py | 18 +++++++++++++++++- requirements.txt | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 bite/bite/admin.py diff --git a/bite/bite/admin.py b/bite/bite/admin.py new file mode 100644 index 0000000..07d1fb7 --- /dev/null +++ b/bite/bite/admin.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# BITE - A Basic/IoT/Example +# Copyright (C) 2020 Daniele ViganĂ² +# +# BITE is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BITE is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django.contrib import admin + +admin.site.site_header = 'BITE administration' +admin.site.site_title = 'BITE site administration' diff --git a/bite/bite/settings.py b/bite/bite/settings.py index 06efa88..d985d54 100644 --- a/bite/bite/settings.py +++ b/bite/bite/settings.py @@ -60,6 +60,7 @@ INSTALLED_APPS = [ 'health_check.db', # 'health_check.storage', 'rest_framework', + 'bite', 'api', 'telemetry', ] diff --git a/bite/telemetry/admin.py b/bite/telemetry/admin.py index 5bfb62d..6c9c807 100644 --- a/bite/telemetry/admin.py +++ b/bite/telemetry/admin.py @@ -17,13 +17,29 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import json +from pygments import highlight +from pygments.lexers import JsonLexer +from pygments.formatters import HtmlFormatter + from django.contrib import admin +from django.utils.safestring import mark_safe from telemetry.models import Telemetry @admin.register(Telemetry) class TelemetryAdmin(admin.ModelAdmin): - readonly_fields = ('device', 'transport', 'time', 'clock', 'payload',) + fields = ('device', 'transport', 'time', 'clock', 'payload_pp',) + readonly_fields = fields list_display = ('__str__', 'device') list_filter = ('time', 'device__serial') search_fields = ('device__serial',) + + def payload_pp(self, instance): + response = json.dumps(instance.payload, sort_keys=True, indent=2) + formatter = HtmlFormatter(style='colorful') + response = highlight(response, JsonLexer(), formatter) + style = "" + return mark_safe(style + response) + + payload_pp.short_description = 'Payload' diff --git a/requirements.txt b/requirements.txt index fa70155..f2c9891 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ django-health-check psycopg2-binary paho-mqtt==1.5.0 asyncio-mqtt==0.5.0 +pygments gunicorn