From c0ecb787611e4088fb2fd89b9901ac2b621c87e1 Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Thu, 17 Jan 2013 13:28:42 +0000 Subject: [PATCH] Merge the I-D and RFC views by showing I-D information on RFCs too. I-Ds that have been published as RFCs redirect to the RFC URL. Also support alias URLs so e.g. /doc/bcpXXXX redirects to /doc/rfcXXXX. - Legacy-Id: 5285 --- ietf/doc/utils.py | 7 + ietf/idrfc/views_doc.py | 143 +++++++++----------- ietf/idtracker/templatetags/ietf_filters.py | 2 + ietf/templates/idrfc/document_draft.html | 117 ++++++++-------- ietf/templates/idrfc/document_rfc.html | 92 ------------- static/css/doc.css | 4 +- 6 files changed, 141 insertions(+), 224 deletions(-) delete mode 100644 ietf/templates/idrfc/document_rfc.html diff --git a/ietf/doc/utils.py b/ietf/doc/utils.py index 4046f91ad..655a9e6a8 100644 --- a/ietf/doc/utils.py +++ b/ietf/doc/utils.py @@ -217,3 +217,10 @@ def add_state_change_event(doc, by, prev_state, new_state, timestamp=None): e.save() return e + +def prettify_std_name(n): + if re.match(r"(rfc|bcp|fyi|std)[0-9]{4}", n): + return n[:3].upper() + " " + n[3:] + else: + return n + diff --git a/ietf/idrfc/views_doc.py b/ietf/idrfc/views_doc.py index 14898ea1a..b248297a9 100644 --- a/ietf/idrfc/views_doc.py +++ b/ietf/idrfc/views_doc.py @@ -53,7 +53,7 @@ from ietf.ietfworkflows.utils import get_full_info_for_draft from ietf.doc.models import * from ietf.doc.utils import * from ietf.utils.history import find_history_active_at -from ietf.ietfauth.utils import user_is_person, has_role, role_required, is_authorized_in_doc_stream +from ietf.ietfauth.utils import * def render_document_top(request, doc, tab, name): tabs = [] @@ -89,13 +89,20 @@ def document_main(request, name, rev=None): if rev != None: # no support for old revisions at the moment raise Http404() return document_main_idrfc(request, name, tab="document") - # generic part doc = get_object_or_404(Document, docalias__name=name) + + # take care of possible redirections + aliases = DocAlias.objects.filter(document=doc).values_list("name", flat=True) + if doc.type_id == "draft" and not name.startswith("rfc"): + for a in aliases: + if a.startswith("rfc"): + return redirect("doc_view", name=a) + group = doc.group if doc.type_id == 'conflrev': - conflictdoc = doc.relateddocument_set.get(relationship__slug='conflrev').target.document + conflictdoc = doc.related_that_doc('conflrev').get().document revisions = [] for h in doc.history_set.order_by("time", "id"): @@ -135,10 +142,7 @@ def document_main(request, name, rev=None): # specific document types - if doc.type_id == "draft": - filename = "%s-%s.txt" % (doc.name, doc.rev) - split_content = not request.GET.get('include_text') if request.COOKIES.get("full_draft", "") == "on": split = False @@ -153,27 +157,24 @@ def document_main(request, name, rev=None): person__user=request.user))) can_edit_iana_state = has_role(request.user, ("Secretariat", "IANA")) - if name.startswith("rfc"): - # RFC tab + rfc_number = name[3:] if name.startswith("") else None + draft_name = None + for a in aliases: + if a.startswith("draft"): + draft_name = a - rfc_number = name[3:] + rfc_aliases = [prettify_std_name(a) for a in aliases + if a.startswith("fyi") or a.startswith("std") or a.startswith("bcp")] + + latest_revision = None + + if doc.get_state_slug() == "rfc": + # content filename = name + ".txt" content = get_document_content(filename, os.path.join(settings.RFC_PATH, filename), split_content, markup=True) - draft_name = doc.name if doc.name.startswith("draft") else None - - def prettify_std_name(n): - if re.match(r"(rfc|bcp|fyi)[0-9]{4}", n): - return n[:3].upper() + " " + n[3:] - else: - return n - - aliases = [prettify_std_name(a.name) for a in doc.docalias_set.filter( - models.Q(name__startswith="fyi") | - models.Q(name__startswith="std"))] - # file types base_path = os.path.join(settings.RFC_PATH, name + ".") possible_types = ["txt", "pdf", "ps"] @@ -198,34 +199,35 @@ def document_main(request, name, rev=None): elif "txt" not in found_types: content = "This RFC is not available in plain text format." split_content = False + else: + filename = "%s-%s.txt" % (draft_name, doc.rev) - return render_to_response("idrfc/document_rfc.html", - dict(doc=doc, - top=top, - name=name, - content=content, - split_content=split_content, - rfc_number=rfc_number, - updates=[prettify_std_name(d.name) for d in doc.related_that_doc("updates")], - updated_by=[prettify_std_name(d.canonical_name()) for d in doc.related_that("updates")], - obsoletes=[prettify_std_name(d.name) for d in doc.related_that_doc("obs")], - obsoleted_by=[prettify_std_name(d.canonical_name()) for d in doc.related_that("obs")], - draft_name=draft_name, - aliases=aliases, - has_errata=doc.tags.filter(slug="errata"), - published=doc.latest_event(type="published_rfc"), - file_urls=file_urls, - # can_edit=can_edit, - # can_change_stream=can_change_stream, - # can_edit_stream_info=can_edit_stream_info, - # telechat=telechat, - # ballot_summary=ballot_summary, - # iesg_state=iesg_state, - ), - context_instance=RequestContext(request)) + content = get_document_content(filename, os.path.join(settings.INTERNET_DRAFT_PATH, filename), + split_content, markup=True) - content = get_document_content(filename, os.path.join(settings.INTERNET_DRAFT_PATH, filename), - split_content, markup=True) + # file types + base_path = os.path.join(settings.INTERNET_DRAFT_PATH, doc.name + "-" + doc.rev + ".") + possible_types = ["pdf", "xml", "ps"] + found_types = ["txt"] + [t for t in possible_types if os.path.exists(base_path + t)] + + tools_base = "http://tools.ietf.org/" + + if doc.get_state_slug() == "active": + base = "http://www.ietf.org/id/" + else: + base = tools_base + "id/" + + file_urls = [] + for t in found_types: + label = "plain text" if t == "txt" else t + file_urls.append((label, base + doc.name + "-" + doc.rev + "." + t)) + + if "pdf" not in found_types: + file_urls.append(("pdf", tools_base + "pdf/" + doc.name + "-" + doc.rev + ".pdf")) + file_urls.append(("html", tools_base + "html/" + doc.name + "-" + doc.rev)) + + # latest revision + latest_revision = doc.latest_event(NewRevisionDocEvent, type="new_revision") # ballot ballot_summary = None @@ -237,17 +239,14 @@ def document_main(request, name, rev=None): # submission submission = "" if group.type_id == "individ": - if doc.stream_id and doc.stream_id != "ietf": - submission = doc.stream.name - else: - submission = "individual" + submission = "individual" elif group.type_id == "area" and doc.stream_id == "ietf": submission = "individual in %s area" % group.acronym - else: + elif group.type_id in ("rg", "wg"): submission = "%s %s" % (group.acronym, group.type) if group.type_id == "wg": submission = "%s" % (urlreverse("wg_docs", kwargs=dict(acronym=doc.group.acronym)), submission) - if doc.get_state_slug("draft-stream-%s" % doc.stream_id) == "c-adopt": + if doc.stream_id and doc.get_state_slug("draft-stream-%s" % doc.stream_id) == "c-adopt": submission = "candidate for %s" % submission # resurrection @@ -257,32 +256,11 @@ def document_main(request, name, rev=None): if e and e.type == "requested_resurrect": resurrected_by = e.by - # file types - base_path = os.path.join(settings.INTERNET_DRAFT_PATH, doc.name + "-" + doc.rev + ".") - possible_types = ["pdf", "xml", "ps"] - found_types = ["txt"] + [t for t in possible_types if os.path.exists(base_path + t)] - - tools_base = "http://tools.ietf.org/" - - if doc.get_state_slug() == "active": - base = "http://www.ietf.org/id/" - else: - base = tools_base + "id/" - - file_urls = [] - for t in found_types: - label = "plain text" if t == "txt" else t - file_urls.append((label, base + doc.name + "-" + doc.rev + "." + t)) - - if "pdf" not in found_types: - file_urls.append(("pdf", tools_base + "pdf/" + doc.name + "-" + doc.rev + ".pdf")) - file_urls.append(("html", tools_base + "html/" + doc.name + "-" + doc.rev)) - # stream info stream_state = None if doc.stream: stream_state = doc.get_state("draft-stream-%s" % doc.stream_id) - stream_tags = get_tags_for_stream_id(doc.stream_id) + stream_tags = doc.tags.filter(slug__in=get_tags_for_stream_id(doc.stream_id)) shepherd_writeup = doc.latest_event(WriteupDocEvent, type="changed_protocol_writeup") @@ -329,12 +307,15 @@ def document_main(request, name, rev=None): return render_to_response("idrfc/document_draft.html", dict(doc=doc, + group=group, top=top, name=name, content=content, split_content=split_content, revisions=revisions, snapshot=snapshot, + latest_revision=latest_revision, + can_edit=can_edit, can_change_stream=can_change_stream, can_edit_stream_info=can_edit_stream_info, @@ -342,14 +323,24 @@ def document_main(request, name, rev=None): can_edit_intended_std_level=can_edit_intended_std_level(request.user, doc), can_edit_consensus=can_edit_consensus(request.user, doc), can_edit_iana_state=can_edit_iana_state, + + rfc_number=rfc_number, + draft_name=draft_name, telechat=telechat, ballot_summary=ballot_summary, - group=group, submission=submission, resurrected_by=resurrected_by, + replaces=[d.name for d in doc.related_that_doc("replaces")], replaced_by=[d.name for d in doc.related_that("replaces")], + updates=[prettify_std_name(d.name) for d in doc.related_that_doc("updates")], + updated_by=[prettify_std_name(d.canonical_name()) for d in doc.related_that("updates")], + obsoletes=[prettify_std_name(d.name) for d in doc.related_that_doc("obs")], + obsoleted_by=[prettify_std_name(d.canonical_name()) for d in doc.related_that("obs")], conflict_reviews=conflict_reviews, + rfc_aliases=rfc_aliases, + has_errata=doc.tags.filter(slug="errata"), + published=doc.latest_event(type="published_rfc"), file_urls=file_urls, stream_state=stream_state, stream_tags=stream_tags, diff --git a/ietf/idtracker/templatetags/ietf_filters.py b/ietf/idtracker/templatetags/ietf_filters.py index ea2d32b7d..0a8ae5a4d 100644 --- a/ietf/idtracker/templatetags/ietf_filters.py +++ b/ietf/idtracker/templatetags/ietf_filters.py @@ -221,12 +221,14 @@ def urlize_ietf_docs(string, autoescape=None): """ if autoescape and not isinstance(string, SafeData): string = escape(string) + print string string = re.sub("(?)(RFC ?)0{0,3}(\d+)", "\\1\\2", string) string = re.sub("(?)(BCP ?)0{0,3}(\d+)", "\\1\\2", string) string = re.sub("(?)(STD ?)0{0,3}(\d+)", "\\1\\2", string) string = re.sub("(?)(FYI ?)0{0,3}(\d+)", "\\1\\2", string) string = re.sub("(?)(draft-[-0-9a-zA-Z._+]+)", "\\1", string) string = re.sub("(?)(conflict-review-[-0-9a-zA-Z._+]+)", "\\1", string) + print string return mark_safe(string) urlize_ietf_docs.is_safe = True urlize_ietf_docs.needs_autoescape = True diff --git a/ietf/templates/idrfc/document_draft.html b/ietf/templates/idrfc/document_draft.html index 73838437f..b33f964da 100644 --- a/ietf/templates/idrfc/document_draft.html +++ b/ietf/templates/idrfc/document_draft.html @@ -2,60 +2,83 @@ {% load ietf_filters %} -{% block title %}{{ name }}-{{ doc.rev }}{% endblock %} +{% block title %}{% if doc.get_state_slug == "rfc" %}RFC {{ rfc_number }}{% else %}{{ name }}-{{ doc.rev }}{% endif %}{% endblock %} {% block pagehead %} - + {% endblock %} {% block content %} {{ top|safe }} -{% comment %} -
- Snapshots: - - {% for rev in revisions %} - {{ rev }} - {% endfor %} - -
-{% endcomment %} -
-
- {{ doc.get_state }} {% if not doc.get_state_slug == "rfc" %}Internet-Draft{% endif %} - ({{ submission|safe }}) - - {% if resurrected_by %}- resurrect requested by {{ resurrected_by }}{% endif %} -
- - - + + + + + + + - + - {% if replaces %} + {% if doc.get_state_slug != "rfc" %} - - + + {% endif %} - {% if replaced_by %} - - + + - {% endif %} {% if conflict_reviews %} @@ -64,22 +87,6 @@ {% endif %} - - - - - - - - - - @@ -89,11 +96,13 @@ {{ stream_state|default:"(None)" }} - {% if stream_tags %}
{% for tag in tags %}{{ tag.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% endif %} - {% for m in milestones %} - {{ m.due|date:"M Y" }} + {{ m.due|date:"M Y" }} {% endfor %} + + {% if stream_tags %} +
{% for tag in stream_tags %}{{ tag.name }}{% if not forloop.last %}, {% endif %}{% endfor %}
+ {% endif %} @@ -113,7 +122,7 @@ @@ -210,9 +219,9 @@ -{% if doc.get_state_slug == "active" %} +{% if doc.get_state_slug == "active" or doc.get_state_slug == "rfc" %}
{{ content|safe }} diff --git a/ietf/templates/idrfc/document_rfc.html b/ietf/templates/idrfc/document_rfc.html deleted file mode 100644 index 03ddcf659..000000000 --- a/ietf/templates/idrfc/document_rfc.html +++ /dev/null @@ -1,92 +0,0 @@ -{% extends "base.html" %} - -{% load ietf_filters %} - -{% block title %}RFC {{ rfc_number }}{% endblock %} - -{% block pagehead %} - - -{% endblock %} - -{% block content %} -{{ top|safe }} - -
-
Document Stream: - {{ doc.stream|default:"No stream defined" }}Document type: + {% if doc.get_state_slug == "rfc" %} + RFC - {{ doc.std_level }} + ({% if published %}{{ published.time|date:"F Y" }}{% else %}publication date unknown{% endif %}{% if has_errata %}; Errata{% endif %}) + + {% if obsoleted_by %}
Obsoleted by {{ obsoleted_by|join:", "|urlize_ietf_docs }}
{% endif %} + {% if updated_by %}
Updated by {{ updated_by|join:", "|urlize_ietf_docs }}
{% endif %} + {% if obsoletes %}
Obsoletes {{ obsoletes|join:", "|urlize_ietf_docs }}
{% endif %} + {% if updates %}
Updates {{ updates|join:", "|urlize_ietf_docs }}
{% endif %} + {% if rfc_aliases %}
Also Known As {{ rfc_aliases|join:", "|urlize_ietf_docs }}
{% endif %} + {% if draft_name %}
Was {{ draft_name }} {% if submission %}({{ submission|safe }}){% endif %}
{% endif %} + {% else %} + {{ doc.get_state }} Internet-Draft {% if submission %}({{ submission|safe }}){% endif %} + + {% if resurrected_by %}- resurrect requested by {{ resurrected_by }}{% endif %} + {% endif %} + + + {% if replaces %}
Replaces: {{ replaces|join:", "|urlize_ietf_docs }}
{% endif %} + {% if replaced_by %}
Replaced by: {{ replaced_by|join:", "|urlize_ietf_docs }}
{% endif %} +
Document stream: + + {{ doc.stream|default:"No stream defined" }} + +
Last updated:{{ doc.time|date:"Y-m-d" }} + {{ doc.time|date:"Y-m-d" }} + {% if latest_revision and latest_revision.time.date != doc.time.date %} + (latest revision {{ latest_revision.time|date:"Y-m-d" }}) + {% endif %} +
Replaces:{{ replaces|join:", "|urlize_ietf_docs }}Intended RFC status: + + {{ doc.intended_std_level|default:"Unknown" }} +
Replaced by:{{ replaced_by|join:", "|urlize_ietf_docs }}Other versions: + {% if doc.get_state_slug != "active" and doc.get_state_slug != "rfc" %}(expired, archived):{% endif %} + {% if file_urls %} + {% for label, url in file_urls %}{{ label}}{% if not forloop.last%}, {% endif %}{% endfor %} + {% else %} + (not online) + {% endif %} +
Intended RFC status: - - {{ doc.intended_std_level|default:"(None)" }} -
Other versions: - {% if doc.get_state_slug != "active" %}(expired, archived):{% endif %} - {% for label, url in file_urls %}{{ label}}{% if not forloop.last%}, {% endif %}{% endfor %} -

{# the shepherd edit page only works for WGs at the moment ... #} - {{ doc.shepherd|default:"(None)" }} + {{ doc.shepherd|default:"No shepherd assigned" }}
- - - - - - - - - - - {% comment %} -{% if doc.in_ietf_process %} - - - - -{% if doc.ietf_process.iesg_note %}{% endif %} -{% if user|in_group:"Area_Director,Secretariat" %} - -{% endif %}{# if user|in_group:... #} - -{% endif %} - {% endcomment %} - - - - - - - -
Document type: - RFC - {{ doc.std_level }} {% if doc.stream %}({{ doc.stream.name }} stream){% endif %} - - {% if obsoleted_by %}
Obsoleted by {{ obsoleted_by|join:", "|urlize_ietf_docs }}{% endif %} - {% if updated_by %}
Updated by {{ updated_by|join:", "|urlize_ietf_docs }}{% endif %} - {% if obsoletes %}
Obsoletes {{ obsoletes|join:", "|urlize_ietf_docs }}{% endif %} - {% if updates %}
Updates {{ updates|join:", "|urlize_ietf_docs }}{% endif %} - {% if aliases %}
Also Known As {{ aliases|join:", "|urlize_ietf_docs }}{% endif %} - {% if draft_name %}
Was {{ draft_name }}{% endif %} - {% if has_errata %}
Errata{% endif %} -
Published:{% if published %}{{ published.time|date:"F Y" }}{% else %}Unknown{% endif %}
* This information refers to IESG processing after the RFC was initially published
State: -{{ doc.friendly_state|safe }} (IESG: {{ doc.ietf_process.state}}) -{% if doc.ietf_process.telechat_date %}
On agenda of {{ doc.ietf_process.telechat_date }} IESG telechat {% if doc.ietf_process.telechat_returning_item %} (returning item){%endif%}{%endif%} -
Intended status:{% if doc.in_ietf_process %}{{ doc.ietf_process.intended_maturity_level|default:"-" }}{% else %}-{%endif%}
Responsible AD:{{ doc.ietf_process.ad_name|default:"-"|escape }}
IESG Note:{{ doc.ietf_process.iesg_note|escape }}
Send notices to:{{ doc.ietf_process.state_change_notice_to}}
Other versions: - {% if file_urls %} - {% for label, url in file_urls %}{{ label}}{% if not forloop.last%}, {% endif %}{% endfor %} - {% else %} - (not online) - {% endif %} -

- - - - {% if can_edit and iesg_state %} - - {% endif %} -
- - -
-{{ content|safe }} -
- -{% if split_content %} -

[include full document text]

-{% endif %} - -{% endblock %} - diff --git a/static/css/doc.css b/static/css/doc.css index 6bf76cd8e..deaa737d9 100644 --- a/static/css/doc.css +++ b/static/css/doc.css @@ -3,6 +3,8 @@ #metatable tr { vertical-align: top; } #metatable tr:first-child td:first-child { width: 15em; } +.stream-tags { font-style: italic; } + .document-markup pre { line-height: 1.2em; margin: 0; } .document-markup .m_hdr, .m_ftr { color: #808080; } .document-markup .m_ftr { border-bottom: 1px solid #a0a0a0; } @@ -40,8 +42,6 @@ a.editlink:visited {text-decoration:none; color:inherit;} a.editlink:hover {text-decoration:underline;} a.editlink:active {text-decoration:underline;} - - h3 a.edit { font-weight: normal; font-size: 13px; display: inline-block; margin-left: 0.5em;} h4 { margin-bottom: 0; }