Skip to content

Commit c0ecb78

Browse files
committed
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
1 parent a6a0596 commit c0ecb78

6 files changed

Lines changed: 139 additions & 222 deletions

File tree

ietf/doc/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,10 @@ def add_state_change_event(doc, by, prev_state, new_state, timestamp=None):
217217
e.save()
218218
return e
219219

220+
221+
def prettify_std_name(n):
222+
if re.match(r"(rfc|bcp|fyi|std)[0-9]{4}", n):
223+
return n[:3].upper() + " " + n[3:]
224+
else:
225+
return n
226+

ietf/idrfc/views_doc.py

Lines changed: 68 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from ietf.doc.models import *
5454
from ietf.doc.utils import *
5555
from ietf.utils.history import find_history_active_at
56-
from ietf.ietfauth.utils import user_is_person, has_role, role_required, is_authorized_in_doc_stream
56+
from ietf.ietfauth.utils import *
5757

5858
def render_document_top(request, doc, tab, name):
5959
tabs = []
@@ -89,13 +89,20 @@ def document_main(request, name, rev=None):
8989
if rev != None: # no support for old revisions at the moment
9090
raise Http404()
9191
return document_main_idrfc(request, name, tab="document")
92-
9392
# generic part
9493

9594
doc = get_object_or_404(Document, docalias__name=name)
95+
96+
# take care of possible redirections
97+
aliases = DocAlias.objects.filter(document=doc).values_list("name", flat=True)
98+
if doc.type_id == "draft" and not name.startswith("rfc"):
99+
for a in aliases:
100+
if a.startswith("rfc"):
101+
return redirect("doc_view", name=a)
102+
96103
group = doc.group
97104
if doc.type_id == 'conflrev':
98-
conflictdoc = doc.relateddocument_set.get(relationship__slug='conflrev').target.document
105+
conflictdoc = doc.related_that_doc('conflrev').get().document
99106

100107
revisions = []
101108
for h in doc.history_set.order_by("time", "id"):
@@ -135,10 +142,7 @@ def document_main(request, name, rev=None):
135142

136143

137144
# specific document types
138-
139145
if doc.type_id == "draft":
140-
filename = "%s-%s.txt" % (doc.name, doc.rev)
141-
142146
split_content = not request.GET.get('include_text')
143147
if request.COOKIES.get("full_draft", "") == "on":
144148
split = False
@@ -153,27 +157,24 @@ def document_main(request, name, rev=None):
153157
person__user=request.user)))
154158
can_edit_iana_state = has_role(request.user, ("Secretariat", "IANA"))
155159

156-
if name.startswith("rfc"):
157-
# RFC tab
160+
rfc_number = name[3:] if name.startswith("") else None
161+
draft_name = None
162+
for a in aliases:
163+
if a.startswith("draft"):
164+
draft_name = a
158165

159-
rfc_number = name[3:]
166+
rfc_aliases = [prettify_std_name(a) for a in aliases
167+
if a.startswith("fyi") or a.startswith("std") or a.startswith("bcp")]
168+
169+
latest_revision = None
170+
171+
if doc.get_state_slug() == "rfc":
172+
# content
160173
filename = name + ".txt"
161174

162175
content = get_document_content(filename, os.path.join(settings.RFC_PATH, filename),
163176
split_content, markup=True)
164177

165-
draft_name = doc.name if doc.name.startswith("draft") else None
166-
167-
def prettify_std_name(n):
168-
if re.match(r"(rfc|bcp|fyi)[0-9]{4}", n):
169-
return n[:3].upper() + " " + n[3:]
170-
else:
171-
return n
172-
173-
aliases = [prettify_std_name(a.name) for a in doc.docalias_set.filter(
174-
models.Q(name__startswith="fyi") |
175-
models.Q(name__startswith="std"))]
176-
177178
# file types
178179
base_path = os.path.join(settings.RFC_PATH, name + ".")
179180
possible_types = ["txt", "pdf", "ps"]
@@ -198,34 +199,35 @@ def prettify_std_name(n):
198199
elif "txt" not in found_types:
199200
content = "This RFC is not available in plain text format."
200201
split_content = False
202+
else:
203+
filename = "%s-%s.txt" % (draft_name, doc.rev)
204+
205+
content = get_document_content(filename, os.path.join(settings.INTERNET_DRAFT_PATH, filename),
206+
split_content, markup=True)
207+
208+
# file types
209+
base_path = os.path.join(settings.INTERNET_DRAFT_PATH, doc.name + "-" + doc.rev + ".")
210+
possible_types = ["pdf", "xml", "ps"]
211+
found_types = ["txt"] + [t for t in possible_types if os.path.exists(base_path + t)]
212+
213+
tools_base = "http://tools.ietf.org/"
214+
215+
if doc.get_state_slug() == "active":
216+
base = "http://www.ietf.org/id/"
217+
else:
218+
base = tools_base + "id/"
201219

202-
return render_to_response("idrfc/document_rfc.html",
203-
dict(doc=doc,
204-
top=top,
205-
name=name,
206-
content=content,
207-
split_content=split_content,
208-
rfc_number=rfc_number,
209-
updates=[prettify_std_name(d.name) for d in doc.related_that_doc("updates")],
210-
updated_by=[prettify_std_name(d.canonical_name()) for d in doc.related_that("updates")],
211-
obsoletes=[prettify_std_name(d.name) for d in doc.related_that_doc("obs")],
212-
obsoleted_by=[prettify_std_name(d.canonical_name()) for d in doc.related_that("obs")],
213-
draft_name=draft_name,
214-
aliases=aliases,
215-
has_errata=doc.tags.filter(slug="errata"),
216-
published=doc.latest_event(type="published_rfc"),
217-
file_urls=file_urls,
218-
# can_edit=can_edit,
219-
# can_change_stream=can_change_stream,
220-
# can_edit_stream_info=can_edit_stream_info,
221-
# telechat=telechat,
222-
# ballot_summary=ballot_summary,
223-
# iesg_state=iesg_state,
224-
),
225-
context_instance=RequestContext(request))
226-
227-
content = get_document_content(filename, os.path.join(settings.INTERNET_DRAFT_PATH, filename),
228-
split_content, markup=True)
220+
file_urls = []
221+
for t in found_types:
222+
label = "plain text" if t == "txt" else t
223+
file_urls.append((label, base + doc.name + "-" + doc.rev + "." + t))
224+
225+
if "pdf" not in found_types:
226+
file_urls.append(("pdf", tools_base + "pdf/" + doc.name + "-" + doc.rev + ".pdf"))
227+
file_urls.append(("html", tools_base + "html/" + doc.name + "-" + doc.rev))
228+
229+
# latest revision
230+
latest_revision = doc.latest_event(NewRevisionDocEvent, type="new_revision")
229231

230232
# ballot
231233
ballot_summary = None
@@ -237,17 +239,14 @@ def prettify_std_name(n):
237239
# submission
238240
submission = ""
239241
if group.type_id == "individ":
240-
if doc.stream_id and doc.stream_id != "ietf":
241-
submission = doc.stream.name
242-
else:
243-
submission = "individual"
242+
submission = "individual"
244243
elif group.type_id == "area" and doc.stream_id == "ietf":
245244
submission = "individual in %s area" % group.acronym
246-
else:
245+
elif group.type_id in ("rg", "wg"):
247246
submission = "%s %s" % (group.acronym, group.type)
248247
if group.type_id == "wg":
249248
submission = "<a href=\"%s\">%s</a>" % (urlreverse("wg_docs", kwargs=dict(acronym=doc.group.acronym)), submission)
250-
if doc.get_state_slug("draft-stream-%s" % doc.stream_id) == "c-adopt":
249+
if doc.stream_id and doc.get_state_slug("draft-stream-%s" % doc.stream_id) == "c-adopt":
251250
submission = "candidate for %s" % submission
252251

253252
# resurrection
@@ -257,32 +256,11 @@ def prettify_std_name(n):
257256
if e and e.type == "requested_resurrect":
258257
resurrected_by = e.by
259258

260-
# file types
261-
base_path = os.path.join(settings.INTERNET_DRAFT_PATH, doc.name + "-" + doc.rev + ".")
262-
possible_types = ["pdf", "xml", "ps"]
263-
found_types = ["txt"] + [t for t in possible_types if os.path.exists(base_path + t)]
264-
265-
tools_base = "http://tools.ietf.org/"
266-
267-
if doc.get_state_slug() == "active":
268-
base = "http://www.ietf.org/id/"
269-
else:
270-
base = tools_base + "id/"
271-
272-
file_urls = []
273-
for t in found_types:
274-
label = "plain text" if t == "txt" else t
275-
file_urls.append((label, base + doc.name + "-" + doc.rev + "." + t))
276-
277-
if "pdf" not in found_types:
278-
file_urls.append(("pdf", tools_base + "pdf/" + doc.name + "-" + doc.rev + ".pdf"))
279-
file_urls.append(("html", tools_base + "html/" + doc.name + "-" + doc.rev))
280-
281259
# stream info
282260
stream_state = None
283261
if doc.stream:
284262
stream_state = doc.get_state("draft-stream-%s" % doc.stream_id)
285-
stream_tags = get_tags_for_stream_id(doc.stream_id)
263+
stream_tags = doc.tags.filter(slug__in=get_tags_for_stream_id(doc.stream_id))
286264

287265
shepherd_writeup = doc.latest_event(WriteupDocEvent, type="changed_protocol_writeup")
288266

@@ -329,27 +307,40 @@ def prettify_std_name(n):
329307

330308
return render_to_response("idrfc/document_draft.html",
331309
dict(doc=doc,
310+
group=group,
332311
top=top,
333312
name=name,
334313
content=content,
335314
split_content=split_content,
336315
revisions=revisions,
337316
snapshot=snapshot,
317+
latest_revision=latest_revision,
318+
338319
can_edit=can_edit,
339320
can_change_stream=can_change_stream,
340321
can_edit_stream_info=can_edit_stream_info,
341322
can_edit_shepherd_writeup=can_edit_shepherd_writeup,
342323
can_edit_intended_std_level=can_edit_intended_std_level(request.user, doc),
343324
can_edit_consensus=can_edit_consensus(request.user, doc),
344325
can_edit_iana_state=can_edit_iana_state,
326+
327+
rfc_number=rfc_number,
328+
draft_name=draft_name,
345329
telechat=telechat,
346330
ballot_summary=ballot_summary,
347-
group=group,
348331
submission=submission,
349332
resurrected_by=resurrected_by,
333+
350334
replaces=[d.name for d in doc.related_that_doc("replaces")],
351335
replaced_by=[d.name for d in doc.related_that("replaces")],
336+
updates=[prettify_std_name(d.name) for d in doc.related_that_doc("updates")],
337+
updated_by=[prettify_std_name(d.canonical_name()) for d in doc.related_that("updates")],
338+
obsoletes=[prettify_std_name(d.name) for d in doc.related_that_doc("obs")],
339+
obsoleted_by=[prettify_std_name(d.canonical_name()) for d in doc.related_that("obs")],
352340
conflict_reviews=conflict_reviews,
341+
rfc_aliases=rfc_aliases,
342+
has_errata=doc.tags.filter(slug="errata"),
343+
published=doc.latest_event(type="published_rfc"),
353344
file_urls=file_urls,
354345
stream_state=stream_state,
355346
stream_tags=stream_tags,

ietf/idtracker/templatetags/ietf_filters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,14 @@ def urlize_ietf_docs(string, autoescape=None):
221221
"""
222222
if autoescape and not isinstance(string, SafeData):
223223
string = escape(string)
224+
print string
224225
string = re.sub("(?<!>)(RFC ?)0{0,3}(\d+)", "<a href=\"/doc/rfc\\2/\">\\1\\2</a>", string)
225226
string = re.sub("(?<!>)(BCP ?)0{0,3}(\d+)", "<a href=\"http://tools.ietf.org/html/bcp\\2/\">\\1\\2</a>", string)
226227
string = re.sub("(?<!>)(STD ?)0{0,3}(\d+)", "<a href=\"http://tools.ietf.org/html/std\\2/\">\\1\\2</a>", string)
227228
string = re.sub("(?<!>)(FYI ?)0{0,3}(\d+)", "<a href=\"http://tools.ietf.org/html/fyi\\2/\">\\1\\2</a>", string)
228229
string = re.sub("(?<!>)(draft-[-0-9a-zA-Z._+]+)", "<a href=\"/doc/\\1/\">\\1</a>", string)
229230
string = re.sub("(?<!>)(conflict-review-[-0-9a-zA-Z._+]+)", "<a href=\"/doc/\\1/\">\\1</a>", string)
231+
print string
230232
return mark_safe(string)
231233
urlize_ietf_docs.is_safe = True
232234
urlize_ietf_docs.needs_autoescape = True

0 commit comments

Comments
 (0)