|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from __future__ import unicode_literals |
| 3 | + |
| 4 | +from django.db import migrations |
| 5 | + |
| 6 | + |
| 7 | +def make_mailtriggers(apps): |
| 8 | + Recipient = apps.get_model('mailtrigger','Recipient') |
| 9 | + MailTrigger = apps.get_model('mailtrigger','MailTrigger') |
| 10 | + |
| 11 | + def mt_factory(slug,desc,to_slugs,cc_slugs=[]): |
| 12 | + |
| 13 | + # Try to protect ourselves from typos |
| 14 | + all_slugs = to_slugs[:] |
| 15 | + all_slugs.extend(cc_slugs) |
| 16 | + for recipient_slug in all_slugs: |
| 17 | + try: |
| 18 | + Recipient.objects.get(slug=recipient_slug) |
| 19 | + except Recipient.DoesNotExist: |
| 20 | + print "****Some rule tried to use",recipient_slug |
| 21 | + raise |
| 22 | + |
| 23 | + m = MailTrigger.objects.create(slug=slug, desc=desc) |
| 24 | + m.to = Recipient.objects.filter(slug__in=to_slugs) |
| 25 | + m.cc = Recipient.objects.filter(slug__in=cc_slugs) |
| 26 | + |
| 27 | + mt_factory(slug='interim_approved', |
| 28 | + desc="Recipients when an interim meeting is approved " |
| 29 | + "and an announcement needs to be sent", |
| 30 | + to_slugs=['iesg_secretary'], |
| 31 | + cc_slugs=[] |
| 32 | + ) |
| 33 | + |
| 34 | +def forward(apps, schema_editor): |
| 35 | + make_mailtriggers(apps) |
| 36 | + |
| 37 | + |
| 38 | +class Migration(migrations.Migration): |
| 39 | + dependencies = [ |
| 40 | + ('mailtrigger', '0004_auto_20160516_1659'), |
| 41 | + ] |
| 42 | + |
| 43 | + operations = [migrations.RunPython(forward)] |
0 commit comments