Add functions in migration file for deleting and altering 'any' state notifications

This commit is contained in:
beeankha 2019-06-17 10:46:50 -04:00
parent 17c89ed412
commit 69502bc133
2 changed files with 17 additions and 3 deletions

View File

@ -5,6 +5,21 @@ from __future__ import unicode_literals
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):
dependencies = [
@ -22,7 +37,8 @@ class Migration(migrations.Migration):
name='notification_templates_started',
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(
model_name='organization',
name='notification_templates_any',

View File

@ -243,8 +243,6 @@ class JobNotificationMixin(object):
notification_template_type = 'error'
all_notification_templates = set(notification_templates.get(notification_template_type, []))
if len(all_notification_templates):
# if status_str != 'running':
# all_notification_templates.update(notification_templates.get('any', []))
try:
(notification_subject, notification_body) = getattr(self, 'build_notification_%s_message' % status_str)()
except AttributeError: