|
9 | 9 |
|
10 | 10 | from ietf.utils.mail import send_mail, send_mail_text |
11 | 11 | from ietf.ipr.search import iprs_from_docs, related_docs |
12 | | -from ietf.doc.models import WriteupDocEvent, BallotPositionDocEvent, LastCallDocEvent, DocAlias, ConsensusDocEvent |
| 12 | +from ietf.doc.models import WriteupDocEvent, BallotPositionDocEvent, LastCallDocEvent, DocAlias, ConsensusDocEvent, DocTagName |
13 | 13 | from ietf.person.models import Person |
14 | 14 | from ietf.group.models import Group, Role |
15 | 15 |
|
@@ -413,3 +413,66 @@ def email_last_call_expired(doc): |
413 | 413 | doc=doc, |
414 | 414 | url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url()), |
415 | 415 | cc="iesg-secretary@ietf.org") |
| 416 | + |
| 417 | +def stream_state_email_recipients(doc, extra_recipients=[]): |
| 418 | + persons = set() |
| 419 | + res = [] |
| 420 | + for r in Role.objects.filter(group=doc.group, name__in=("chair", "delegate")).select_related("person", "email"): |
| 421 | + res.append(r.formatted_email()) |
| 422 | + persons.add(r.person) |
| 423 | + |
| 424 | + for email in doc.authors.all(): |
| 425 | + if email.person not in persons: |
| 426 | + res.append(email.formatted_email()) |
| 427 | + persons.add(email.person) |
| 428 | + |
| 429 | + for p in extra_recipients: |
| 430 | + if not p in persons: |
| 431 | + res.append(p.formatted_email()) |
| 432 | + persons.add(p) |
| 433 | + |
| 434 | + return res |
| 435 | + |
| 436 | +def email_draft_adopted(request, doc, by, comment): |
| 437 | + recipients = stream_state_email_recipients(doc) |
| 438 | + send_mail(request, recipients, settings.DEFAULT_FROM_EMAIL, |
| 439 | + u"%s adopted in %s %s" % (doc.name, doc.group.acronym, doc.group.type.name), |
| 440 | + 'doc/mail/draft_adopted_email.txt', |
| 441 | + dict(doc=doc, |
| 442 | + url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url(), |
| 443 | + by=by, |
| 444 | + comment=comment)) |
| 445 | + |
| 446 | +def email_stream_state_changed(request, doc, prev_state, new_state, by, comment=""): |
| 447 | + recipients = stream_state_email_recipients(doc) |
| 448 | + |
| 449 | + state_type = (prev_state or new_state).type |
| 450 | + |
| 451 | + send_mail(request, recipients, settings.DEFAULT_FROM_EMAIL, |
| 452 | + u"%s changed for %s" % (state_type.label, doc.name), |
| 453 | + 'doc/mail/stream_state_changed_email.txt', |
| 454 | + dict(doc=doc, |
| 455 | + url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url(), |
| 456 | + state_type=state_type, |
| 457 | + prev_state=prev_state, |
| 458 | + new_state=new_state, |
| 459 | + by=by, |
| 460 | + comment=comment)) |
| 461 | + |
| 462 | +def email_stream_tags_changed(request, doc, added_tags, removed_tags, by, comment=""): |
| 463 | + extra_recipients = [] |
| 464 | + |
| 465 | + if DocTagName.objects.get(slug="sheph-u") in added_tags and doc.shepherd: |
| 466 | + extra_recipients.append(doc.shepherd) |
| 467 | + |
| 468 | + recipients = stream_state_email_recipients(doc, extra_recipients) |
| 469 | + |
| 470 | + send_mail(request, recipients, settings.DEFAULT_FROM_EMAIL, |
| 471 | + u"Tags changed for %s" % doc.name, |
| 472 | + 'doc/mail/stream_tags_changed_email.txt', |
| 473 | + dict(doc=doc, |
| 474 | + url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url(), |
| 475 | + added=added_tags, |
| 476 | + removed=removed_tags, |
| 477 | + by=by, |
| 478 | + comment=comment)) |
0 commit comments