|
10 | 10 | from django.forms import ValidationError |
11 | 11 | from django.utils.html import strip_tags, escape |
12 | 12 |
|
13 | | -from ietf.utils import markup_txt |
14 | | -from ietf.doc.models import Document, DocHistory |
| 13 | +from ietf.doc.models import Document, DocHistory, State |
15 | 14 | from ietf.doc.models import DocAlias, RelatedDocument, BallotType, DocReminder |
16 | 15 | from ietf.doc.models import DocEvent, BallotDocEvent, NewRevisionDocEvent, StateDocEvent |
17 | 16 | from ietf.doc.models import save_document_in_history, STATUSCHANGE_RELATIONS |
18 | 17 | from ietf.name.models import DocReminderTypeName, DocRelationshipName |
19 | 18 | from ietf.group.models import Role |
20 | 19 | from ietf.person.models import Email |
21 | 20 | from ietf.ietfauth.utils import has_role |
22 | | -from ietf.utils import draft |
| 21 | +from ietf.utils import draft, markup_txt |
23 | 22 | from ietf.utils.mail import send_mail |
24 | 23 |
|
25 | 24 | #FIXME - it would be better if this lived in ietf/doc/mails.py, but there's |
@@ -314,9 +313,9 @@ def update_reminder(doc, reminder_type_slug, event, due_date): |
314 | 313 | reminder.active = False |
315 | 314 | reminder.save() |
316 | 315 |
|
317 | | -def prettify_std_name(n): |
| 316 | +def prettify_std_name(n, spacing=" "): |
318 | 317 | if re.match(r"(rfc|bcp|fyi|std)[0-9]+", n): |
319 | | - return n[:3].upper() + " " + n[3:] |
| 318 | + return n[:3].upper() + spacing + n[3:] |
320 | 319 | else: |
321 | 320 | return n |
322 | 321 |
|
@@ -459,6 +458,75 @@ def rebuild_reference_relations(doc,filename=None): |
459 | 458 |
|
460 | 459 | return ret |
461 | 460 |
|
| 461 | +def collect_email_addresses(emails, doc): |
| 462 | + for author in doc.authors.all(): |
| 463 | + if author.address not in emails: |
| 464 | + emails[author.address] = '"%s"' % (author.person.name) |
| 465 | + if doc.group and doc.group.acronym != 'none': |
| 466 | + for role in doc.group.role_set.filter(name='chair'): |
| 467 | + if role.email.address not in emails: |
| 468 | + emails[role.email.address] = '"%s"' % (role.person.name) |
| 469 | + if doc.group.type.slug == 'wg': |
| 470 | + address = '%s-ads@tools.ietf.org' % doc.group.acronym |
| 471 | + if address not in emails: |
| 472 | + emails[address] = '"%s-ads"' % (doc.group.acronym) |
| 473 | + elif doc.group.type.slug == 'rg': |
| 474 | + for role in doc.group.parent.role_set.filter(name='chair'): |
| 475 | + if role.email.address not in emails: |
| 476 | + emails[role.email.address] = '"%s"' % (role.person.name) |
| 477 | + if doc.shepherd and doc.shepherd.address not in emails: |
| 478 | + emails[doc.shepherd.address] = u'"%s"' % (doc.shepherd.person.name or "") |
| 479 | + |
| 480 | +def set_replaces_for_document(request, doc, new_replaces, by, email_subject, email_comment=""): |
| 481 | + emails = {} |
| 482 | + collect_email_addresses(emails, doc) |
| 483 | + |
| 484 | + relationship = DocRelationshipName.objects.get(slug='replaces') |
| 485 | + old_replaces = doc.related_that_doc("replaces") |
| 486 | + |
| 487 | + for d in old_replaces: |
| 488 | + if d not in new_replaces: |
| 489 | + collect_email_addresses(emails, d.document) |
| 490 | + RelatedDocument.objects.filter(source=doc, target=d, relationship=relationship).delete() |
| 491 | + if not RelatedDocument.objects.filter(target=d, relationship=relationship): |
| 492 | + s = 'active' if d.document.expires > datetime.datetime.now() else 'expired' |
| 493 | + d.document.set_state(State.objects.get(type='draft', slug=s)) |
| 494 | + |
| 495 | + for d in new_replaces: |
| 496 | + if d not in old_replaces: |
| 497 | + collect_email_addresses(emails, d.document) |
| 498 | + RelatedDocument.objects.create(source=doc, target=d, relationship=relationship) |
| 499 | + d.document.set_state(State.objects.get(type='draft', slug='repl')) |
| 500 | + |
| 501 | + e = DocEvent(doc=doc, by=by, type='changed_document') |
| 502 | + new_replaces_names = u", ".join(d.name for d in new_replaces) or u"None" |
| 503 | + old_replaces_names = u", ".join(d.name for d in old_replaces) or u"None" |
| 504 | + e.desc = u"This document now replaces <b>%s</b> instead of %s" % (new_replaces_names, old_replaces_names) |
| 505 | + e.save() |
| 506 | + |
| 507 | + # make sure there are no lingering suggestions duplicating new replacements |
| 508 | + RelatedDocument.objects.filter(source=doc, target__in=new_replaces, relationship="possibly-replaces").delete() |
| 509 | + |
| 510 | + email_desc = e.desc.replace(", ", "\n ") |
| 511 | + |
| 512 | + if email_comment: |
| 513 | + email_desc += "\n" + email_comment |
| 514 | + |
| 515 | + to = [ |
| 516 | + u'%s <%s>' % (emails[email], email) if emails[email] else u'<%s>' % email |
| 517 | + for email in sorted(emails) |
| 518 | + ] |
| 519 | + |
| 520 | + from ietf.doc.mails import html_to_text |
| 521 | + |
| 522 | + send_mail(request, to, |
| 523 | + "DraftTracker Mail System <iesg-secretary@ietf.org>", |
| 524 | + email_subject, |
| 525 | + "doc/mail/change_notice.txt", |
| 526 | + dict(text=html_to_text(email_desc), |
| 527 | + doc=doc, |
| 528 | + url=settings.IDTRACKER_BASE_URL + doc.get_absolute_url())) |
| 529 | + |
462 | 530 | def check_common_doc_name_rules(name): |
463 | 531 | """Check common rules for document names for use in forms, throws |
464 | 532 | ValidationError in case there's a problem.""" |
|
0 commit comments