14132 model changes

This commit is contained in:
Arthur 2023-10-31 07:37:22 -07:00
parent 498ac5e44f
commit 1cc8a82921
4 changed files with 60 additions and 1 deletions

View File

@ -280,3 +280,18 @@ class DashboardWidgetColorChoices(ChoiceSet):
(BLACK, _('Black')),
(WHITE, _('White')),
)
#
# Event Rules
#
class EventRuleTypeChoices(ChoiceSet):
WEBHOOK = 'webhook'
SCRIPT = 'script'
CHOICES = (
(WEBHOOK, _('Webhook'), 'webhook'),
(SCRIPT, _('Script'), 'script'),
)

View File

@ -1,3 +1,6 @@
from django.db.models import Q
# Events
EVENT_CREATE = 'create'
EVENT_UPDATE = 'update'
@ -133,3 +136,10 @@ DEFAULT_DASHBOARD = [
}
},
]
EVENT_TYPE_MODELS = Q(
app_label='extras',
model__in=(
'webhook',
'script',
))

View File

@ -1,6 +1,7 @@
# Generated by Django 4.2.5 on 2023-10-30 21:57
# Generated by Django 4.2.5 on 2023-10-31 14:37
from django.db import migrations, models
import django.db.models.deletion
import extras.utils
import taggit.managers
import utilities.json
@ -31,6 +32,8 @@ class Migration(migrations.Migration):
('type_job_end', models.BooleanField(default=False)),
('enabled', models.BooleanField(default=True)),
('conditions', models.JSONField(blank=True, null=True)),
('event_type', models.CharField(default='webhook', max_length=30)),
('object_id', models.PositiveBigIntegerField(blank=True, null=True)),
(
'content_types',
models.ManyToManyField(
@ -39,6 +42,15 @@ class Migration(migrations.Migration):
to='contenttypes.contenttype',
),
),
(
'object_type',
models.ForeignKey(
limit_choices_to=models.Q(('app_label', 'extras'), ('model__in', ('webhook', 'script'))),
on_delete=django.db.models.deletion.CASCADE,
related_name='eventrule_actions',
to='contenttypes.contenttype',
),
),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={

View File

@ -93,6 +93,28 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
help_text=_("A set of conditions which determine whether the event will be generated.")
)
event_type = models.CharField(
max_length=30,
choices=EventRuleTypeChoices,
default=EventRuleTypeChoices.WEBHOOK,
verbose_name=_('event type')
)
# Action to take
object_type = models.ForeignKey(
to=ContentType,
related_name='eventrule_actions',
limit_choices_to=EVENT_TYPE_MODELS,
on_delete=models.CASCADE,
)
object_id = models.PositiveBigIntegerField(
blank=True,
null=True
)
object = GenericForeignKey(
ct_field='object_type',
fk_field='object_id',
)
class Meta:
ordering = ('name',)
verbose_name = _('eventrule')