1
0
mirror of https://github.com/daniviga/bite.git synced 2024-12-23 08:41:24 +01:00

Commit forgotten changes from last night

This commit is contained in:
Daniele Viganò 2020-06-22 09:48:37 +02:00
parent ce88e47ed8
commit ff9157dc7e
Signed by: dani
GPG Key ID: DB49AFC03C40EE02
4 changed files with 42 additions and 1 deletions

23
bite/bite/admin.py Normal file
View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# BITE - A Basic/IoT/Example
# Copyright (C) 2020 Daniele Viganò <daniele@vigano.me>
#
# 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 <http://www.gnu.org/licenses/>.
from django.contrib import admin
admin.site.site_header = 'BITE administration'
admin.site.site_title = 'BITE site administration'

View File

@ -60,6 +60,7 @@ INSTALLED_APPS = [
'health_check.db',
# 'health_check.storage',
'rest_framework',
'bite',
'api',
'telemetry',
]

View File

@ -17,13 +17,29 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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 = "<style>" + formatter.get_style_defs() + "</style>"
return mark_safe(style + response)
payload_pp.short_description = 'Payload'

View File

@ -4,4 +4,5 @@ django-health-check
psycopg2-binary
paho-mqtt==1.5.0
asyncio-mqtt==0.5.0
pygments
gunicorn