@@ -197,29 +197,28 @@ def document_main(request, name, rev=None, document_html=False):
197197
198198 # take care of possible redirections
199199 if document_html is False and rev is None :
200- became_rfc = next ( iter ( doc .related_that_doc ( " became_rfc" )), None )
200+ became_rfc = doc .became_rfc ( )
201201 if became_rfc :
202202 return redirect ("ietf.doc.views_doc.document_main" , name = became_rfc .name )
203-
204- revisions = []
205- for h in doc .history_set .order_by ("time" , "id" ):
206- if h .rev and not h .rev in revisions :
207- revisions .append (h .rev )
208- if not doc .rev in revisions :
209- revisions .append (doc .rev )
203+
204+ revisions = doc .revisions_by_dochistory ()
210205 latest_rev = doc .rev
211206
212207 snapshot = False
213208
214209 gh = None
215210 if rev :
216211 # find the entry in the history
212+ debug .show ('doc.name' )
217213 for h in doc .history_set .order_by ("-time" ):
218214 if rev == h .rev :
219215 snapshot = True
220216 doc = h
221217 break
222218
219+ debug .show ('doc.name' )
220+
221+
223222 if not snapshot and document_html is False :
224223 return redirect ('ietf.doc.views_doc.document_main' , name = name )
225224
@@ -239,7 +238,6 @@ def document_main(request, name, rev=None, document_html=False):
239238 if telechat and (not telechat .telechat_date or telechat .telechat_date < date_today (settings .TIME_ZONE )):
240239 telechat = None
241240
242-
243241 # specific document types
244242 if doc .type_id == "rfc" :
245243 split_content = request .COOKIES .get ("full_draft" , settings .USER_PREFERENCE_DEFAULTS ["full_draft" ]) == "off"
@@ -302,7 +300,7 @@ def document_main(request, name, rev=None, document_html=False):
302300 diff_revisions = None
303301 simple_diff_revisions = None
304302 if document_html :
305- diff_revisions = get_diff_revisions (request , name , doc if isinstance ( doc , Document ) else doc . doc )
303+ diff_revisions = get_diff_revisions (request , name , doc )
306304 simple_diff_revisions = [t [1 ] for t in diff_revisions if t [0 ] == doc .name ]
307305 simple_diff_revisions .reverse ()
308306 html = doc .html_body ()
@@ -311,10 +309,8 @@ def document_main(request, name, rev=None, document_html=False):
311309 css = Path (finders .find ("ietf/css/document_html_inline.css" )).read_text ()
312310 if html :
313311 css += Path (finders .find ("ietf/css/document_html_txt.css" )).read_text ()
314- draft_that_became_rfc = None
315- became_rfc = next (iter (doc .related_that ("became_rfc" )), None )
316- if became_rfc :
317- draft_that_became_rfc = became_rfc
312+ draft_that_became_rfc = doc .came_from_draft ()
313+
318314 # submission
319315 submission = ""
320316 if group is None :
@@ -651,6 +647,7 @@ def document_main(request, name, rev=None, document_html=False):
651647 css = Path (finders .find ("ietf/css/document_html_inline.css" )).read_text ()
652648 if html :
653649 css += Path (finders .find ("ietf/css/document_html_txt.css" )).read_text ()
650+ debug .show ("doc.name" )
654651
655652 return render (request , "doc/document_draft.html" if document_html is False else "doc/document_html.html" ,
656653 dict (doc = doc ,
@@ -1134,6 +1131,9 @@ def document_email(request,name):
11341131
11351132
11361133def get_diff_revisions (request , name , doc ):
1134+ """ returns list of (name, rev, time, url, is_this_doc, is_previous_doc)
1135+ ordered by -time for use by forms used to get to the diff tools.
1136+ """
11371137 diffable = any (
11381138 [
11391139 name .startswith (prefix )
@@ -1160,16 +1160,17 @@ def get_diff_revisions(request, name, doc):
11601160 relateddocument__relationship = "replaces" ,
11611161 )
11621162 )
1163- diff_documents .extend (
1164- Document .objects .filter (
1165- relateddocument__target = doc ,
1166- relateddocument__relationship = "became_rfc"
1167- )
1168- )
1163+ if doc .came_from_draft ():
1164+ diff_documents .append (doc .came_from_draft ())
1165+
1166+ if doc .became_rfc ():
1167+ rfc = doc .became_rfc ()
1168+ e = rfc .latest_event (type = "published_rfc" )
1169+ diff_revisions .append ((rfc .name , "" , e .time if e else rfc .time , rfc .name , False , False ))
11691170
11701171 if doc .type_id == "rfc" :
11711172 e = doc .latest_event (type = "published_rfc" )
1172- diff_revisions .append ((name , "" , e .time if e else doc .time , name ))
1173+ diff_revisions .append ((name , "" , e .time if e else doc .time , name , True , False ))
11731174
11741175 seen = set ()
11751176 for e in (
@@ -1198,7 +1199,16 @@ def get_diff_revisions(request, name, doc):
11981199 # rfcdiff tool has special support for IDs
11991200 url = e .doc .name + "-" + e .rev
12001201
1201- diff_revisions .append ((e .doc .name , e .rev , e .time , url ))
1202+ diff_revisions .append ((e .doc .name , e .rev , e .time , url , e .doc == doc and e .rev == doc .rev , False ))
1203+
1204+ diff_revisions .sort (key = lambda t : t [2 ], reverse = True )
1205+ for index , t in enumerate (diff_revisions ):
1206+ if t [4 ]: # is_this_doc
1207+ n = index + 1
1208+ if n < len (diff_revisions ):
1209+ t_name , rev , time , url , _ , _ = diff_revisions [n ]
1210+ diff_revisions [n ] = (t_name , rev , time , url , False , True )
1211+ break
12021212
12031213 return diff_revisions
12041214
@@ -1280,7 +1290,7 @@ def document_bibtex(request, name, rev=None):
12801290 if doc .type_id == "draft" :
12811291 latest_revision = doc .latest_event (NewRevisionDocEvent , type = "new_revision" )
12821292 replaced_by = [d .name for d in doc .related_that ("replaces" )]
1283- draft_became_rfc = next ( iter ( doc .related_that_doc ( " became_rfc" )), None )
1293+ draft_became_rfc = doc .became_rfc ( )
12841294
12851295 if rev != None and rev != doc .rev :
12861296 # find the entry in the history
@@ -2170,7 +2180,7 @@ def idnits2_state(request, name, rev=None):
21702180 raise Http404
21712181 zero_revision = None
21722182 if doc .type_id == "rfc" :
2173- draft = next ( iter ( doc .related_that ( 'became_rfc' )), None )
2183+ draft = doc .came_from_draft ( )
21742184 if draft :
21752185 zero_revision = NewRevisionDocEvent .objects .filter (doc = draft ,rev = '00' ).first ()
21762186 else :
0 commit comments