|
| 1 | +# Copyright The IETF Trust 2015, All Rights Reserved |
| 2 | + |
| 3 | +from django.db import models |
| 4 | +from django.template import Template, Context |
| 5 | + |
| 6 | +class Recipe(models.Model): |
| 7 | + slug = models.CharField(max_length=32, primary_key=True) |
| 8 | + desc = models.TextField(blank=True) |
| 9 | + ingredients = models.ManyToManyField('Ingredient', null=True, blank=True) |
| 10 | + |
| 11 | +class Ingredient(models.Model): |
| 12 | + slug = models.CharField(max_length=32, primary_key=True) |
| 13 | + desc = models.TextField(blank=True) |
| 14 | + template = models.CharField(max_length=512, null=True, blank=True) |
| 15 | + |
| 16 | + def gather(self, **kwargs): |
| 17 | + retval = [] |
| 18 | + if hasattr(self,'gather_%s'%self.slug): |
| 19 | + retval.extend(eval('self.gather_%s(**kwargs)'%self.slug)) |
| 20 | + if self.template: |
| 21 | + rendering = Template(self.template).render(Context(kwargs)) |
| 22 | + if rendering: |
| 23 | + retval.extend(rendering.split(',')) |
| 24 | + |
| 25 | + return retval |
| 26 | + |
| 27 | + def gather_doc_group_chairs(self, **kwargs): |
| 28 | + addrs = [] |
| 29 | + if 'doc' in kwargs: |
| 30 | + doc=kwargs['doc'] |
| 31 | + if doc.group.type.slug in ['wg','rg']: |
| 32 | + addrs.append('%s-chairs@ietf.org'%doc.group.acronym) |
| 33 | + return addrs |
| 34 | + |
| 35 | + def gather_doc_group_mail_list(self, **kwargs): |
| 36 | + addrs = [] |
| 37 | + if 'doc' in kwargs: |
| 38 | + doc=kwargs['doc'] |
| 39 | + if doc.group.type.slug in ['wg','rg']: |
| 40 | + if doc.group.list_email: |
| 41 | + addrs.append(doc.group.list_email) |
| 42 | + return addrs |
| 43 | + |
| 44 | + def gather_doc_affecteddoc_authors(self, **kwargs): |
| 45 | + addrs = [] |
| 46 | + if 'doc' in kwargs: |
| 47 | + for reldoc in kwargs['doc'].related_that_doc(['conflrev','tohist','tois','tops']): |
| 48 | + addrs.extend(Ingredient.objects.get(slug='doc_authors').gather(**{'doc':reldoc.document})) |
| 49 | + return addrs |
| 50 | + |
| 51 | + def gather_doc_affecteddoc_group_chairs(self, **kwargs): |
| 52 | + addrs = [] |
| 53 | + if 'doc' in kwargs: |
| 54 | + for reldoc in kwargs['doc'].related_that_doc(['conflrev','tohist','tois','tops']): |
| 55 | + addrs.extend(Ingredient.objects.get(slug='doc_group_chairs').gather(**{'doc':reldoc.document})) |
| 56 | + return addrs |
| 57 | + |
| 58 | +def make_ingredients(): |
| 59 | + |
| 60 | + Ingredient.objects.all().delete() |
| 61 | + Ingredient.objects.create(slug='iesg', |
| 62 | + desc='The IESG', |
| 63 | + template='The IESG <iesg@ietf.org>') |
| 64 | + Ingredient.objects.create(slug='ietf_announce', |
| 65 | + desc='The IETF Announce list', |
| 66 | + template='IETF-Announce <ietf-announce@ietf.org>') |
| 67 | + Ingredient.objects.create(slug='rfc_editor', |
| 68 | + desc='The RFC Editor', |
| 69 | + template='<rfc-editor@rfc-editor.org>') |
| 70 | + Ingredient.objects.create(slug='iesg_secretary', |
| 71 | + desc='The Secretariat', |
| 72 | + template='<iesg-secretary@ietf.org>') |
| 73 | + Ingredient.objects.create(slug='doc_authors', |
| 74 | + desc="The document's authors", |
| 75 | + template='{{doc.name}}@ietf.org') |
| 76 | + Ingredient.objects.create(slug='doc_notify', |
| 77 | + desc="The addresses in the document's notify field", |
| 78 | + template='{{doc.notify}}') |
| 79 | + Ingredient.objects.create(slug='doc_group_chairs', |
| 80 | + desc="The document's group chairs (if the document is assigned to a working or research group)", |
| 81 | + template=None) |
| 82 | + Ingredient.objects.create(slug='doc_affecteddoc_authors', |
| 83 | + desc="The authors of the subject documents of a conflict-review or status-change", |
| 84 | + template=None) |
| 85 | + Ingredient.objects.create(slug='doc_affecteddoc_group_chairs', |
| 86 | + desc="The chairs of groups of the subject documents of a conflict-review or status-change", |
| 87 | + template=None) |
| 88 | + Ingredient.objects.create(slug='doc_shepherd', |
| 89 | + desc="The document's shepherd", |
| 90 | + template='{% if doc.shepherd %}{{doc.shepherd.address}}{% endif %}' ) |
| 91 | + Ingredient.objects.create(slug='doc_ad', |
| 92 | + desc="The document's responsible Area Director", |
| 93 | + template='{% if doc.ad %}{{doc.ad.email_address}}{% endif %}' ) |
| 94 | + Ingredient.objects.create(slug='doc_group_mail_list', |
| 95 | + desc="The list address of the document's group", |
| 96 | + template=None ) |
| 97 | + Ingredient.objects.create(slug='conflict_review_stream_owner', |
| 98 | + desc="The stream owner of a document being reviewed for IETF stream conflicts", |
| 99 | + template='{% ifequal doc.type_id "conflrev" %}{% ifequal doc.stream_id "ise" %}<rfc-ise@rfc-editor.org>{% endifequal %}{% ifequal doc.stream_id "irtf" %}<irtf-chair@irtf.org>{% endifequal %}{% endifequal %}') |
| 100 | + Ingredient.objects.create(slug='iana_approve', |
| 101 | + desc="IANA's draft approval address", |
| 102 | + template='IANA <drafts-approval@icann.org>') |
| 103 | + |
| 104 | +def make_recipes(): |
| 105 | + |
| 106 | + Recipe.objects.all().delete() |
| 107 | + |
| 108 | + r = Recipe.objects.create(slug='ballot_saved', |
| 109 | + desc='Recipients when a new ballot position (with discusses, other blocking positions, or comments) is saved') |
| 110 | + r.ingredients = Ingredient.objects.filter(slug__in=['iesg']) |
| 111 | + |
| 112 | + r = Recipe.objects.create(slug='ballot_saved_cc', |
| 113 | + desc='Copied when a new ballot position (with discusses, other blocking positions, or comments) is saved') |
| 114 | + r.ingredients = Ingredient.objects.filter(slug__in=['doc_authors', |
| 115 | + 'doc_group_chairs', |
| 116 | + 'doc_shepherd', |
| 117 | + 'doc_affecteddoc_authors', |
| 118 | + 'doc_affecteddoc_group_chairs', |
| 119 | + 'conflict_review_stream_owner', |
| 120 | + ]) |
| 121 | + |
| 122 | + r = Recipe.objects.create(slug='ballot_deferred', |
| 123 | + desc='Recipients when a ballot is deferred to or undeferred from a future telechat') |
| 124 | + r.ingredients = Ingredient.objects.filter(slug__in=['iesg', |
| 125 | + 'iesg_secretary', |
| 126 | + 'doc_group_chairs', |
| 127 | + 'doc_notify', |
| 128 | + 'doc_authors', |
| 129 | + 'doc_shepherd', |
| 130 | + 'doc_affecteddoc_authors', |
| 131 | + 'doc_affecteddoc_group_chairs', |
| 132 | + 'conflict_review_stream_owner', |
| 133 | + ]) |
| 134 | + |
| 135 | + r = Recipe.objects.create(slug='ballot_approved_ietf_stream', |
| 136 | + desc='Recipients when an IETF stream document ballot is approved') |
| 137 | + r.ingredients = Ingredient.objects.filter(slug__in=['ietf_announce']) |
| 138 | + |
| 139 | + r = Recipe.objects.create(slug='ballot_approved_ietf_stream_cc', |
| 140 | + desc='Copied when an IETF stream document ballot is approved') |
| 141 | + r.ingredients = Ingredient.objects.filter(slug__in=['iesg', |
| 142 | + 'doc_notify', |
| 143 | + 'doc_ad', |
| 144 | + 'doc_authors', |
| 145 | + 'doc_shepherd', |
| 146 | + 'doc_group_mail_list', |
| 147 | + 'doc_group_chairs', |
| 148 | + 'rfc_editor', |
| 149 | + ]) |
| 150 | + |
| 151 | + r = Recipe.objects.create(slug='ballot_approved_ietf_stream_iana', |
| 152 | + desc='Recipients for IANA message when an IETF stream document ballot is approved') |
| 153 | + r.ingredients = Ingredient.objects.filter(slug__in=['iana_approve']) |
| 154 | + |
| 155 | + |
0 commit comments