Add priority to notification rules
This commit is contained in:
parent
e01aea7712
commit
0b840d227b
|
@ -88,11 +88,13 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
|
|||
model = NotificationRule
|
||||
fields = (
|
||||
"name",
|
||||
"priority",
|
||||
"enabled",
|
||||
"data",
|
||||
)
|
||||
help_texts = {
|
||||
"name": "The name of the rule.",
|
||||
"priority": "The priority of the rule.",
|
||||
"enabled": "Whether the rule is enabled.",
|
||||
"data": "The notification rule definition.",
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ def rule_matched(rule, message, matched_fields):
|
|||
|
||||
notify_message = f"{rule.name} matched on {matched_fields}\n{message}"
|
||||
notify_message = notify_message.encode("utf-8", "replace")
|
||||
sendmsg(rule.user, notify_message, title=title)
|
||||
sendmsg(rule.user, notify_message, title=title, priority=str(rule.priority))
|
||||
|
||||
|
||||
def process_rules(data):
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.1.5 on 2023-01-12 18:06
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0013_notificationsettings'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='notificationrule',
|
||||
name='priority',
|
||||
field=models.IntegerField(choices=[(1, 'min'), (2, 'low'), (3, 'default'), (4, 'high'), (5, 'max')], default=1),
|
||||
),
|
||||
]
|
|
@ -15,6 +15,14 @@ except ImportError:
|
|||
from yaml import Loader
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PRIORITY_CHOICES = (
|
||||
(1, "min"),
|
||||
(2, "low"),
|
||||
(3, "default"),
|
||||
(4, "high"),
|
||||
(5, "max"),
|
||||
)
|
||||
|
||||
|
||||
class Plan(models.Model):
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
|
@ -137,6 +145,7 @@ class Perms(models.Model):
|
|||
class NotificationRule(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=255)
|
||||
priority = models.IntegerField(choices=PRIORITY_CHOICES, default=1)
|
||||
enabled = models.BooleanField(default=True)
|
||||
data = models.TextField()
|
||||
|
||||
|
|
Loading…
Reference in New Issue