Add interval and window fields to NotificationRule

master
Mark Veidemanis 1 year ago
parent 158fffed99
commit fbe5607899
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -8,10 +8,9 @@ from core.lib.rules import NotificationRuleData
from .models import NotificationRule, NotificationSettings, User
# from django.forms import ModelForm
# flake8: noqa: E501
# Create your forms here.
class RestrictedFormMixin:
"""
This mixin is used to restrict the queryset of a form to the current user.
@ -89,16 +88,20 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
fields = (
"name",
"data",
"interval",
"window",
"priority",
"topic",
"enabled",
)
help_texts = {
"name": "The name of the rule.",
"priority": "The priority of the rule.",
"priority": "The notification priority of the rule.",
"topic": "The topic to send notifications to. Leave blank for default.",
"enabled": "Whether the rule is enabled.",
"data": "The notification rule definition.",
"interval": "How often to run the search. On demand only evaluates messages as they are received.",
"window": "Time window to search: 1d, 1h, 1m, 1s, etc.",
}
def clean(self):

@ -0,0 +1,23 @@
# Generated by Django 4.1.3 on 2023-01-14 14:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0015_notificationrule_topic'),
]
operations = [
migrations.AddField(
model_name='notificationrule',
name='interval',
field=models.CharField(choices=[('ondemand', 'On demand'), ('minute', 'Every minute'), ('15m', 'Every 15 minutes'), ('30m', 'Every 30 minutes'), ('hour', 'Every hour'), ('4h', 'Every 4 hours'), ('day', 'Every day'), ('week', 'Every week'), ('month', 'Every month')], default='ondemand', max_length=255),
),
migrations.AddField(
model_name='notificationrule',
name='window',
field=models.CharField(blank=True, max_length=255, null=True),
),
]

@ -23,6 +23,18 @@ PRIORITY_CHOICES = (
(5, "max"),
)
INTERVAL_CHOICES = (
("ondemand", "On demand"),
("minute", "Every minute"),
("15m", "Every 15 minutes"),
("30m", "Every 30 minutes"),
("hour", "Every hour"),
("4h", "Every 4 hours"),
("day", "Every day"),
("week", "Every week"),
("month", "Every month"),
)
class Plan(models.Model):
name = models.CharField(max_length=255, unique=True)
@ -147,6 +159,10 @@ class NotificationRule(models.Model):
name = models.CharField(max_length=255)
priority = models.IntegerField(choices=PRIORITY_CHOICES, default=1)
topic = models.CharField(max_length=255, null=True, blank=True)
interval = models.CharField(
choices=INTERVAL_CHOICES, max_length=255, default="ondemand"
)
window = models.CharField(max_length=255, null=True, blank=True)
enabled = models.BooleanField(default=True)
data = models.TextField()

Loading…
Cancel
Save