44from django .core .urlresolvers import reverse as urlreverse
55from django .contrib .contenttypes .models import ContentType
66from django .conf import settings
7+ from django .utils .html import mark_safe
78
89from ietf .group .models import *
910from ietf .name .models import *
@@ -168,7 +169,7 @@ class Meta:
168169
169170class Document (DocumentInfo ):
170171 name = models .CharField (max_length = 255 , primary_key = True ) # immutable
171- related = models .ManyToManyField ('DocAlias' , through = RelatedDocument , blank = True , related_name = "reversely_related_document_set" )
172+ # related = models.ManyToManyField('DocAlias', through=RelatedDocument, blank=True, related_name="reversely_related_document_set")
172173 authors = models .ManyToManyField (Email , through = DocumentAuthor , blank = True )
173174
174175 def __unicode__ (self ):
@@ -231,6 +232,14 @@ def display_name(self):
231232 name = name .upper ()
232233 return name
233234
235+ def related_that (self , relationship ):
236+ """Return the documents that are source of relationship targeting self."""
237+ return Document .objects .filter (relateddocument__target__document = self , relateddocument__relationship = relationship )
238+
239+ def related_that_doc (self , relationship ):
240+ """Return the doc aliases that are target of relationship originating from self."""
241+ return DocAlias .objects .filter (relateddocument__source = self , relateddocument__relationship = relationship )
242+
234243 #TODO can/should this be a function instead of a property? Currently a view uses it as a property
235244 @property
236245 def telechat_date (self ):
@@ -285,9 +294,6 @@ def rfc_number(self):
285294 qs = self .docalias_set .filter (name__startswith = 'rfc' )
286295 return qs [0 ].name [3 :] if qs else None
287296
288- def replaced_by (self ):
289- return [ rel .source for alias in self .docalias_set .all () for rel in alias .relateddocument_set .filter (relationship = 'replaces' ) ]
290-
291297 def friendly_state (self ):
292298 """ Return a concise text description of the document's current state """
293299 if self .type_id == 'draft' :
@@ -306,11 +312,12 @@ def friendly_state(self):
306312 iesg_state_summary = iesg_state_summary + "::" + "::" .join (tag .name for tag in iesg_substate )
307313
308314 if self .get_state_slug () == "rfc" :
309- return "<a href=\" %s\" >RFC %d</a>" % (urlreverse ('doc_view' , args = ['rfc%d' % self .rfc_number ]), self .rfc_number )
315+ n = self .rfc_number ()
316+ return "<a href=\" %s\" >RFC %s</a>" % (urlreverse ('doc_view' , kwargs = dict (name = 'rfc%s' % n )), n )
310317 elif self .get_state_slug () == "repl" :
311- rs = self .replaced_by ( )
318+ rs = self .related_that ( "replaces" )
312319 if rs :
313- return "Replaced by " + ", " .join ("<a href=\" %s\" >%s</a>" % (urlreverse ('doc_view' , args = [name ]),name ) for name in rs )
320+ return mark_safe ( "Replaced by " + ", " .join ("<a href=\" %s\" >%s</a>" % (urlreverse ('doc_view' , args = [name ]), name ) for name in rs ) )
314321 else :
315322 return "Replaced"
316323 elif self .get_state_slug () == "active" :
0 commit comments