5656
5757from ietf .doc .models import ( Document , DocAlias , DocHistory , DocEvent , BallotDocEvent , BallotType ,
5858 ConsensusDocEvent , NewRevisionDocEvent , TelechatDocEvent , WriteupDocEvent , IanaExpertDocEvent ,
59- IESG_BALLOT_ACTIVE_STATES , STATUSCHANGE_RELATIONS , DocumentActionHolder , DocumentAuthor )
59+ IESG_BALLOT_ACTIVE_STATES , STATUSCHANGE_RELATIONS , DocumentActionHolder , DocumentAuthor ,
60+ RelatedDocument , RelatedDocHistory )
6061from ietf .doc .utils import (add_links_in_new_revision_events , augment_events_with_revision ,
6162 can_adopt_draft , can_unadopt_draft , get_chartering_type , get_tags_for_stream_id ,
6263 needed_ballot_positions , nice_consensus , prettify_std_name , update_telechat , has_same_ballot ,
@@ -118,6 +119,25 @@ def render_document_top(request, doc, tab, name):
118119 selected = tab ,
119120 name = name ))
120121
122+ def interesting_doc_relations (doc ):
123+
124+ if isinstance (doc , Document ):
125+ cls = RelatedDocument
126+ target = doc
127+ elif isinstance (doc , DocHistory ):
128+ cls = RelatedDocHistory
129+ target = doc .doc
130+ else :
131+ raise TypeError ("Expected this method to be called with a Document or DocHistory object" )
132+
133+ that_relationships = STATUSCHANGE_RELATIONS + ('conflrev' , 'replaces' , 'possibly_replaces' , 'updates' , 'obs' )
134+
135+ that_doc_relationships = ('replaces' , 'possibly_replaces' , 'updates' , 'obs' )
136+
137+ interesting_relations_that = cls .objects .filter (target__docs = target , relationship__in = that_relationships ).select_related ('source' )
138+ interesting_relations_that_doc = cls .objects .filter (source = doc , relationship__in = that_doc_relationships ).prefetch_related ('target__docs' )
139+
140+ return interesting_relations_that , interesting_relations_that_doc
121141
122142def document_main (request , name , rev = None ):
123143 doc = get_object_or_404 (Document .objects .select_related (), docalias__name = name )
@@ -128,9 +148,6 @@ def document_main(request, name, rev=None):
128148 for a in aliases :
129149 if a .startswith ("rfc" ):
130150 return redirect ("ietf.doc.views_doc.document_main" , name = a )
131-
132- if doc .type_id == 'conflrev' :
133- conflictdoc = doc .related_that_doc ('conflrev' )[0 ].document
134151
135152 revisions = []
136153 for h in doc .history_set .order_by ("time" , "id" ):
@@ -182,6 +199,8 @@ def document_main(request, name, rev=None):
182199 else :
183200 pass
184201
202+ interesting_relations_that , interesting_relations_that_doc = interesting_doc_relations (doc )
203+
185204 iesg_state = doc .get_state ("draft-iesg" )
186205 if isinstance (doc , Document ):
187206 log .assertion ('iesg_state' , note = "A document's 'draft-iesg' state should never be unset'. Failed for %s" % doc .name )
@@ -328,11 +347,11 @@ def document_main(request, name, rev=None):
328347 search_archive = quote (search_archive , safe = "~" )
329348
330349 # conflict reviews
331- conflict_reviews = [d . document .name for d in doc . related_that ( "conflrev" )]
350+ conflict_reviews = [r . source .name for r in interesting_relations_that . filter ( relationship = "conflrev" )]
332351
333- status_change_docs = doc . related_that ( STATUSCHANGE_RELATIONS )
334- status_changes = [ rel . document for rel in status_change_docs if rel . document .get_state_slug () in ('appr-sent' ,'appr-pend' )]
335- proposed_status_changes = [ rel . document for rel in status_change_docs if rel . document .get_state_slug () in ('needshep' ,'adrev' ,'iesgeval' ,'defer' ,'appr-pr' )]
352+ status_change_docs = interesting_relations_that . filter ( relationship__in = STATUSCHANGE_RELATIONS )
353+ status_changes = [ r . source for r in status_change_docs if r . source .get_state_slug () in ('appr-sent' ,'appr-pend' )]
354+ proposed_status_changes = [ r . source for r in status_change_docs if r . source .get_state_slug () in ('needshep' ,'adrev' ,'iesgeval' ,'defer' ,'appr-pr' )]
336355
337356 presentations = doc .future_presentations ()
338357
@@ -454,14 +473,14 @@ def document_main(request, name, rev=None):
454473 submission = submission ,
455474 resurrected_by = resurrected_by ,
456475
457- replaces = doc . related_that_doc ( "replaces" ),
458- replaced_by = doc . related_that ( "replaces" ),
459- possibly_replaces = doc . related_that_doc ( "possibly_replaces" ),
460- possibly_replaced_by = doc . related_that ( "possibly_replaces" ),
461- updates = doc . related_that_doc ( "updates" ),
462- updated_by = doc . related_that ( "updates" ),
463- obsoletes = doc . related_that_doc ( "obs" ),
464- obsoleted_by = doc . related_that ( "obs" ),
476+ replaces = interesting_relations_that_doc . filter ( relationship = "replaces" ),
477+ replaced_by = interesting_relations_that . filter ( relationship = "replaces" ),
478+ possibly_replaces = interesting_relations_that_doc . filter ( relationship = "possibly_replaces" ),
479+ possibly_replaced_by = interesting_relations_that . filter ( relationship = "possibly_replaces" ),
480+ updates = interesting_relations_that_doc . filter ( relationship = "updates" ),
481+ updated_by = interesting_relations_that . filter ( relationship = "updates" ),
482+ obsoletes = interesting_relations_that_doc . filter ( relationship = "obs" ),
483+ obsoleted_by = interesting_relations_that . filter ( relationship = "obs" ),
465484 conflict_reviews = conflict_reviews ,
466485 status_changes = status_changes ,
467486 proposed_status_changes = proposed_status_changes ,
@@ -565,6 +584,8 @@ def document_main(request, name, rev=None):
565584 if doc .get_state_slug () in ("iesgeval" , ) and doc .active_ballot ():
566585 ballot_summary = needed_ballot_positions (doc , list (doc .active_ballot ().active_balloter_positions ().values ()))
567586
587+ conflictdoc = doc .related_that_doc ('conflrev' )[0 ].document
588+
568589 return render (request , "doc/document_conflict_review.html" ,
569590 dict (doc = doc ,
570591 top = top ,
0 commit comments