mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 16:48:16 -06:00
Define dynamic choices for Notification.event_name
This commit is contained in:
parent
71860ba985
commit
c22b7052ff
@ -18,7 +18,7 @@ from utilities.api import get_serializer_for_model
|
|||||||
from utilities.rqworker import get_rq_retry
|
from utilities.rqworker import get_rq_retry
|
||||||
from utilities.serialization import serialize_object
|
from utilities.serialization import serialize_object
|
||||||
from .choices import EventRuleActionChoices
|
from .choices import EventRuleActionChoices
|
||||||
from .constants import EVENT_CREATE, EVENT_DELETE, EVENT_UPDATE
|
from .constants import EVENT_CREATE, EVENT_DELETE, EVENT_JOB_END, EVENT_JOB_START, EVENT_UPDATE
|
||||||
from .models import EventRule
|
from .models import EventRule
|
||||||
|
|
||||||
logger = logging.getLogger('netbox.events_processor')
|
logger = logging.getLogger('netbox.events_processor')
|
||||||
@ -27,6 +27,8 @@ logger = logging.getLogger('netbox.events_processor')
|
|||||||
Event(name=EVENT_CREATE, text=_('Object created')).register()
|
Event(name=EVENT_CREATE, text=_('Object created')).register()
|
||||||
Event(name=EVENT_UPDATE, text=_('Object updated')).register()
|
Event(name=EVENT_UPDATE, text=_('Object updated')).register()
|
||||||
Event(name=EVENT_DELETE, text=_('Object deleted')).register()
|
Event(name=EVENT_DELETE, text=_('Object deleted')).register()
|
||||||
|
Event(name=EVENT_JOB_START, text=_('Job started')).register()
|
||||||
|
Event(name=EVENT_JOB_END, text=_('Job ended')).register()
|
||||||
|
|
||||||
|
|
||||||
def serialize_for_event(instance):
|
def serialize_for_event(instance):
|
||||||
|
@ -21,6 +21,16 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_event_type_choices():
|
||||||
|
"""
|
||||||
|
Compile a list of choices from all registered event types
|
||||||
|
"""
|
||||||
|
return [
|
||||||
|
(name, event.text)
|
||||||
|
for name, event in registry['events'].items()
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class Notification(models.Model):
|
class Notification(models.Model):
|
||||||
"""
|
"""
|
||||||
A notification message for a User relating to a specific object in NetBox.
|
A notification message for a User relating to a specific object in NetBox.
|
||||||
@ -49,7 +59,8 @@ class Notification(models.Model):
|
|||||||
)
|
)
|
||||||
event_name = models.CharField(
|
event_name = models.CharField(
|
||||||
verbose_name=_('event'),
|
verbose_name=_('event'),
|
||||||
max_length=50
|
max_length=50,
|
||||||
|
choices=get_event_type_choices
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = NotificationQuerySet.as_manager()
|
objects = NotificationQuerySet.as_manager()
|
||||||
|
Loading…
Reference in New Issue
Block a user