diff --git a/core/forms.py b/core/forms.py index 6cfb89b..fef64df 100644 --- a/core/forms.py +++ b/core/forms.py @@ -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.", } diff --git a/core/lib/rules.py b/core/lib/rules.py index d1eb5da..5400411 100644 --- a/core/lib/rules.py +++ b/core/lib/rules.py @@ -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): diff --git a/core/migrations/0014_notificationrule_priority.py b/core/migrations/0014_notificationrule_priority.py new file mode 100644 index 0000000..c25885e --- /dev/null +++ b/core/migrations/0014_notificationrule_priority.py @@ -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), + ), + ] diff --git a/core/models.py b/core/models.py index 13b0c92..f81fad8 100644 --- a/core/models.py +++ b/core/models.py @@ -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()