aboutsummaryrefslogtreecommitdiff
path: root/rrd
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2023-12-08 15:11:51 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2023-12-29 07:29:15 +0100
commitc9c3ac00c1a27ff4bcdb0733789a94c738c35c93 (patch)
treee3065ad59a87c4c01f136a19efda31587d5ae8b8 /rrd
parent0195aa4ce2010061b42bacd0b3e13d88007ffacc (diff)
Add RRD-related models
Diffstat (limited to 'rrd')
-rw-r--r--rrd/admin.py5
-rw-r--r--rrd/apps.py2
-rw-r--r--rrd/migrations/0001_initial.py69
-rw-r--r--rrd/models.py57
4 files changed, 131 insertions, 2 deletions
diff --git a/rrd/admin.py b/rrd/admin.py
index 8c38f3f..d83650b 100644
--- a/rrd/admin.py
+++ b/rrd/admin.py
@@ -1,3 +1,8 @@
from django.contrib import admin
+from . import models
+
# Register your models here.
+admin.site.register(models.DataSource)
+admin.site.register(models.Graph)
+admin.site.register(models.Dashboard)
diff --git a/rrd/apps.py b/rrd/apps.py
index ef97edc..61733ba 100644
--- a/rrd/apps.py
+++ b/rrd/apps.py
@@ -1,6 +1,6 @@
from django.apps import AppConfig
-class RrdConfig(AppConfig):
+class RRDConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'rrd'
diff --git a/rrd/migrations/0001_initial.py b/rrd/migrations/0001_initial.py
new file mode 100644
index 0000000..c4bbee8
--- /dev/null
+++ b/rrd/migrations/0001_initial.py
@@ -0,0 +1,69 @@
+# Generated by Django 3.2.21 on 2023-12-08 13:48
+
+from django.conf import settings
+from django.db import migrations, models
+import pathlib
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ('auth', '0012_alter_user_first_name_max_length'),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='DataSource',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('topic', models.CharField(max_length=512)),
+ ('path', models.FilePathField(max_length=512, path=pathlib.PurePosixPath('/home/valhalla/projects/software/kerbana/django-kerbana/../data/rrd'), recursive=True)),
+ ('rrd_config', models.TextField()),
+ ('active', models.BooleanField(default=True)),
+ ('groups_read', models.ManyToManyField(related_name='datasource_read', to='auth.Group')),
+ ('groups_write', models.ManyToManyField(related_name='datasource_write', to='auth.Group')),
+ ('users_read', models.ManyToManyField(related_name='datasource_read', to=settings.AUTH_USER_MODEL)),
+ ('users_write', models.ManyToManyField(related_name='datasource_write', to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ migrations.CreateModel(
+ name='Graph',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('title', models.CharField(max_length=64)),
+ ('path', models.FilePathField(max_length=512, path=pathlib.PurePosixPath('/home/valhalla/projects/software/kerbana/django-kerbana/../data/graph'), recursive=True)),
+ ('rrd_config', models.TextField()),
+ ('data_sources', models.ManyToManyField(to='rrd.DataSource')),
+ ('groups_read', models.ManyToManyField(related_name='graph_read', to='auth.Group')),
+ ('groups_write', models.ManyToManyField(related_name='graph_write', to='auth.Group')),
+ ('users_read', models.ManyToManyField(related_name='graph_read', to=settings.AUTH_USER_MODEL)),
+ ('users_write', models.ManyToManyField(related_name='graph_write', to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ migrations.CreateModel(
+ name='Dashboard',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('title', models.CharField(max_length=64)),
+ ('template', models.TextField()),
+ ('data_sources', models.ManyToManyField(to='rrd.DataSource')),
+ ('graphs', models.ManyToManyField(to='rrd.Graph')),
+ ('groups_read', models.ManyToManyField(related_name='dashboard_read', to='auth.Group')),
+ ('groups_write', models.ManyToManyField(related_name='dashboard_write', to='auth.Group')),
+ ('users_read', models.ManyToManyField(related_name='dashboard_read', to=settings.AUTH_USER_MODEL)),
+ ('users_write', models.ManyToManyField(related_name='dashboard_write', to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ ]
diff --git a/rrd/models.py b/rrd/models.py
index 71a8362..49efd57 100644
--- a/rrd/models.py
+++ b/rrd/models.py
@@ -1,3 +1,58 @@
from django.db import models
+from django.conf import settings
+import django.contrib.auth.models as amodels
-# Create your models here.
+
+class ModelWithPerms(models.Model):
+ users_read = models.ManyToManyField(
+ amodels.User,
+ related_name="%(class)s_read"
+ )
+ users_write = models.ManyToManyField(
+ amodels.User,
+ related_name="%(class)s_write"
+ )
+ groups_read = models.ManyToManyField(
+ amodels.Group,
+ related_name="%(class)s_read"
+ )
+ groups_write = models.ManyToManyField(
+ amodels.Group,
+ related_name="%(class)s_write"
+ )
+
+ class Meta:
+ abstract = True
+
+
+class DataSource(ModelWithPerms):
+ # an mqtt topic can be as long as 65,535 bytes when UTF-8 encoded,
+ # which is probably too much for a sensible db
+ topic = models.CharField(max_length=512)
+ path = models.FilePathField(
+ path=settings.RRD_DB_PATH,
+ recursive=True,
+ max_length=512,
+ )
+ rrd_config = models.TextField()
+ active = models.BooleanField(
+ default=True,
+ )
+
+
+class Graph(ModelWithPerms):
+ title = models.CharField(max_length=64)
+ data_sources = models.ManyToManyField(DataSource)
+ path = models.FilePathField(
+ path=settings.RRD_GRAPH_PATH,
+ recursive=True,
+ max_length=512,
+ )
+ rrd_config = models.TextField()
+
+
+class Dashboard(ModelWithPerms):
+ title = models.CharField(max_length=64)
+ graphs = models.ManyToManyField(Graph)
+ data_sources = models.ManyToManyField(DataSource)
+ template = models.TextField()