diff --git a/ietf/doc/urls.py b/ietf/doc/urls.py index d9d8489ec..6c8108f44 100644 --- a/ietf/doc/urls.py +++ b/ietf/doc/urls.py @@ -55,6 +55,7 @@ urlpatterns = patterns('', url(r'^(?P[A-Za-z0-9._+-]+)/(?:(?P[0-9-]+)/)?$', views_doc.document_main, name="doc_view"), url(r'^(?P[A-Za-z0-9._+-]+)/history/$', views_doc.document_history, name="doc_history"), url(r'^(?P[A-Za-z0-9._+-]+)/writeup/$', views_doc.document_writeup, name="doc_writeup"), + url(r'^(?P[A-Za-z0-9._+-]+)/email/$', views_doc.document_email, name="doc_email"), url(r'^(?P[A-Za-z0-9._+-]+)/shepherdwriteup/$', views_doc.document_shepherd_writeup, name="doc_shepherd_writeup"), url(r'^(?P[A-Za-z0-9._+-]+)/references/$', views_doc.document_references, name="doc_references"), url(r'^(?P[A-Za-z0-9._+-]+)/referencedby/$', views_doc.document_referenced_by, name="doc_referenced_by"), diff --git a/ietf/doc/views_doc.py b/ietf/doc/views_doc.py index e44355847..654b6f50c 100644 --- a/ietf/doc/views_doc.py +++ b/ietf/doc/views_doc.py @@ -59,6 +59,7 @@ from ietf.person.models import Email from ietf.utils.history import find_history_active_at from ietf.doc.forms import TelechatForm, NotifyForm from ietf.doc.mails import email_ad +from ietf.mailtoken.utils import gather_relevant_expansions def render_document_top(request, doc, tab, name): tabs = [] @@ -73,6 +74,7 @@ def render_document_top(request, doc, tab, name): if doc.type_id == "draft" or (doc.type_id == "charter" and doc.group.type_id == "wg"): tabs.append(("IESG Writeups", "writeup", urlreverse("doc_writeup", kwargs=dict(name=name)), True)) + tabs.append(("Email expansions","email",urlreverse("doc_email", kwargs=dict(name=name)), True)) tabs.append(("History", "history", urlreverse("doc_history", kwargs=dict(name=name)), True)) if name.startswith("rfc"): @@ -572,6 +574,18 @@ def document_main(request, name, rev=None): +def document_email(request,name): + doc = get_object_or_404(Document, docalias__name=name) + top = render_document_top(request, doc, "email", name) + + expansions = gather_relevant_expansions(doc=doc) + + return render(request, "doc/document_email.html", + dict(doc=doc, + top=top, + expansions=expansions, + ) + ) def document_history(request, name): diff --git a/ietf/mailtoken/migrations/0002_auto_20150809_1314.py b/ietf/mailtoken/migrations/0002_auto_20150809_1314.py index 1337441ee..ac75d4919 100644 --- a/ietf/mailtoken/migrations/0002_auto_20150809_1314.py +++ b/ietf/mailtoken/migrations/0002_auto_20150809_1314.py @@ -103,7 +103,7 @@ def make_recipients(apps): rc(slug='group_mail_list', desc="The group's mailing list", - template='<{{ group.list_email }}>') + template='{% if group.list_email %}<{{ group.list_email }}>{% endif %}') rc(slug='group_steering_group', desc="The group's steering group (IESG or IRSG)", @@ -111,7 +111,7 @@ def make_recipients(apps): rc(slug='group_chairs', desc="The group's chairs", - template="<{{group.acronym}}-chairs@ietf.org>") + template="{% if group and group.acronym %}<{{group.acronym}}-chairs@ietf.org>{% endif %}") rc(slug='group_responsible_directors', desc="The group's responsible AD(s) or IRTF chair", @@ -429,7 +429,8 @@ def make_mailtokens(apps): mt_factory(slug='doc_stream_changed', desc="Recipients for notification when a document's stream changes", - to_slugs=['stream_managers', + to_slugs=['doc_authors', + 'stream_managers', 'doc_notify', ]) diff --git a/ietf/mailtoken/utils.py b/ietf/mailtoken/utils.py index a3cdca85b..5f4bedb58 100644 --- a/ietf/mailtoken/utils.py +++ b/ietf/mailtoken/utils.py @@ -28,6 +28,50 @@ def gather_address_lists(slug, **kwargs): return AddrLists(to=list(to),cc=list(cc)) +def gather_relevant_expansions(**kwargs): + relevant = set() + + if 'doc' in kwargs: + + doc = kwargs['doc'] + + relevant.update(MailToken.objects.filter(slug__startswith='doc_').values_list('slug',flat=True)) + + if doc.stream_id == 'ietf': + relevant.update(['ballot_approved_ietf_stream']) + else: + relevant.update(['pubreq_rfced']) + + if doc.type_id in ['draft','statchg']: + relevant.update(MailToken.objects.filter(slug__startswith='last_call_').values_list('slug',flat=True)) + if doc.type_id == 'draft': + relevant.update(['ipr_posted_on_doc',]) + if doc.type_id == 'conflrev': + relevant.update(['conflrev_requested','ballot_approved_conflrev']) + if doc.type_id == 'charter': + relevant.update(['charter_external_review','ballot_approved_charter']) + + rule_list = [] + for mailtoken in MailToken.objects.filter(slug__in=relevant): + addrs = gather_address_lists(mailtoken.slug,**kwargs) + rule_list.append((mailtoken.slug,mailtoken.desc,addrs.to,addrs.cc)) + return sorted(rule_list) + +#def gather_relevant_expansions_recipient(**kwargs): +# relevant_tokens = [] +# +# if 'doc' in kwargs: +# relevant_tokens.extend(Recipient.objects.filter(slug__startswith='doc').values_list('slug',flat=True)) +# +# rule_dict = {} +# +# for recipient in Recipient.objects.filter(slug__in=relevant_tokens): +# #for recipient in Recipient.objects.all(): +# addrs = recipient.gather(**kwargs) +# if addrs: +# rule_dict[recipient.slug] = recipient.gather(**kwargs) +# return sorted(rule_dict.iteritems()) + def get_base_ipr_request_address(): return Recipient.objects.get(slug='ipr_requests').gather()[0] diff --git a/ietf/name/fixtures/names.json b/ietf/name/fixtures/names.json index 8987a7408..1bfb7923a 100644 --- a/ietf/name/fixtures/names.json +++ b/ietf/name/fixtures/names.json @@ -4473,7 +4473,7 @@ }, { "fields": { - "template": "<{{group.acronym}}-chairs@ietf.org>", + "template": "{% if group and group.acronym %}<{{group.acronym}}-chairs@ietf.org>{% endif %}", "desc": "The group's chairs" }, "model": "mailtoken.recipient", @@ -4489,7 +4489,7 @@ }, { "fields": { - "template": "<{{ group.list_email }}>", + "template": "{% if group.list_email %}<{{ group.list_email }}>{% endif %}", "desc": "The group's mailing list" }, "model": "mailtoken.recipient", @@ -5081,6 +5081,7 @@ "fields": { "cc": [], "to": [ + "doc_authors", "doc_notify", "stream_managers" ], diff --git a/ietf/templates/doc/document_email.html b/ietf/templates/doc/document_email.html new file mode 100644 index 000000000..8eae383c3 --- /dev/null +++ b/ietf/templates/doc/document_email.html @@ -0,0 +1,57 @@ +{% extends "base.html" %} +{# Copyright The IETF Trust 2015, All Rights Reserved #} +{% load origin %} +{% load ietf_filters %} +{% load future %} + +{% block title %}Email expansions for {{ doc.name }}-{{ doc.rev }}{% endblock %} + +{% block content %} + {% origin %} + {{ top|safe }} + +

Recipient Expansions

+ + + + + + + + + + + {% for token,desc,to,cc in expansions %} + + + + + + {% endfor %} + +
MailTokenToCc
{{token}} {{to|join:', '}} {{cc|join:', '}}
+{% comment %} + + + + + + + + + + + + {% for e in events %} + + + + + + + {% endfor %} + +
DateRev.ByAction
{{ e.time|date:"Y-m-d" }}{{ e.rev }}{{ e.by|escape }}{{ e.desc|format_history_text|safe }}
+{% endcomment %} +{% endblock content %} diff --git a/ietf/templates/mailtoken/recipient.html b/ietf/templates/mailtoken/recipient.html index 547854ead..9f2c24a01 100644 --- a/ietf/templates/mailtoken/recipient.html +++ b/ietf/templates/mailtoken/recipient.html @@ -23,8 +23,11 @@ {{recipient.slug}} - {% for mailtoken in recipient.mailtoken_set.all %} - {{mailtoken.slug}}{% if not forloop.last %}, {%endif%} + {% for mailtoken in recipient.used_in_to.all %} + {{mailtoken.slug}}{% if not forloop.last %}, {%endif%} + {% endfor %}{% if recipient.used_in_to.exists and recipient.used_in_cc.exists %},{% endif %} + {% for mailtoken in recipient.used_in_cc.all %} + {{mailtoken.slug}}{% if not forloop.last %}, {%endif%} {% endfor %} {{recipient.template}}