From fbe5607899082859d193fca4d090aaebab968057 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 14 Jan 2023 14:36:46 +0000 Subject: [PATCH] Add interval and window fields to NotificationRule --- core/forms.py | 9 +++++--- ...onrule_interval_notificationrule_window.py | 23 +++++++++++++++++++ core/models.py | 16 +++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 core/migrations/0016_notificationrule_interval_notificationrule_window.py diff --git a/core/forms.py b/core/forms.py index c988838..bc3ef87 100644 --- a/core/forms.py +++ b/core/forms.py @@ -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): diff --git a/core/migrations/0016_notificationrule_interval_notificationrule_window.py b/core/migrations/0016_notificationrule_interval_notificationrule_window.py new file mode 100644 index 0000000..7931043 --- /dev/null +++ b/core/migrations/0016_notificationrule_interval_notificationrule_window.py @@ -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), + ), + ] diff --git a/core/models.py b/core/models.py index 22fc2bd..853937b 100644 --- a/core/models.py +++ b/core/models.py @@ -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()