mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
Add functions in migration file for deleting and altering 'any' state notifications
This commit is contained in:
@@ -5,6 +5,21 @@ from __future__ import unicode_literals
|
|||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def forwards_split_unified_job_template_any(apps, schema_editor):
|
||||||
|
UnifiedJobTemplate = apps.get_model('main', 'unifiedjobtemplate')
|
||||||
|
for ujt in UnifiedJobTemplate.objects.all():
|
||||||
|
for ujt_notification in ujt.notification_templates_any.all():
|
||||||
|
ujt.notification_templates_success.add(ujt_notification)
|
||||||
|
ujt.notification_templates_error.add(ujt_notification)
|
||||||
|
|
||||||
|
def forwards_split_organization_any(apps, schema_editor):
|
||||||
|
Organization = apps.get_model('main', 'organization')
|
||||||
|
for org in Organization.objects.all():
|
||||||
|
for org_notification in org.notification_templates_any.all():
|
||||||
|
org.notification_templates_success.add(org_notification)
|
||||||
|
org.notification_templates_error.add(org_notification)
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@@ -22,7 +37,8 @@ class Migration(migrations.Migration):
|
|||||||
name='notification_templates_started',
|
name='notification_templates_started',
|
||||||
field=models.ManyToManyField(blank=True, related_name='unifiedjobtemplate_notification_templates_for_started', to='main.NotificationTemplate'),
|
field=models.ManyToManyField(blank=True, related_name='unifiedjobtemplate_notification_templates_for_started', to='main.NotificationTemplate'),
|
||||||
),
|
),
|
||||||
# migrations.RunPython() stuff goes in here
|
# Separate out "any" notifications into "success" and "error" before the "any" state gets deleted.
|
||||||
|
migrations.RunPython(forwards_split_unified_job_template_any, forwards_split_organization_any),
|
||||||
migrations.RemoveField(
|
migrations.RemoveField(
|
||||||
model_name='organization',
|
model_name='organization',
|
||||||
name='notification_templates_any',
|
name='notification_templates_any',
|
||||||
|
|||||||
@@ -243,8 +243,6 @@ class JobNotificationMixin(object):
|
|||||||
notification_template_type = 'error'
|
notification_template_type = 'error'
|
||||||
all_notification_templates = set(notification_templates.get(notification_template_type, []))
|
all_notification_templates = set(notification_templates.get(notification_template_type, []))
|
||||||
if len(all_notification_templates):
|
if len(all_notification_templates):
|
||||||
# if status_str != 'running':
|
|
||||||
# all_notification_templates.update(notification_templates.get('any', []))
|
|
||||||
try:
|
try:
|
||||||
(notification_subject, notification_body) = getattr(self, 'build_notification_%s_message' % status_str)()
|
(notification_subject, notification_body) = getattr(self, 'build_notification_%s_message' % status_str)()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|||||||
Reference in New Issue
Block a user