Skip to content

Commit 7925223

Browse files
committed
Merged [6622] from rjsparks@nostrum.com:
Refines Bill Fenner's regex based search through documents for references. Populates RelatedDocument with relations for references for each type draft Document. Replaces these reference relationships with updated copies on draft submission. Note to deployer: There is a script to run in patches/fill_in_references.py that does the work of bringing the database up to date. It takes around 10 minutes to complete on a fast development laptop. fixes bug ietf-tools#1173 - Legacy-Id: 6633 Note: SVN reference [6622] has been migrated to Git commit a677a70
2 parents 782136b + a677a70 commit 7925223

6 files changed

Lines changed: 306544 additions & 3 deletions

File tree

ietf/doc/utils.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from ietf.utils import markup_txt
77
from ietf.doc.models import *
88

9+
from ietf.utils import draft
10+
911
def get_state_types(doc):
1012
res = []
1113

@@ -290,3 +292,47 @@ def update_telechat(request, doc, by, new_telechat_date, new_returning_item=None
290292
e.desc = "Removed telechat returning item indication"
291293

292294
e.save()
295+
296+
def rebuild_reference_relations(doc):
297+
if doc.type.slug != 'draft':
298+
return None
299+
300+
if doc.get_state_slug() == 'rfc':
301+
filename=os.path.join(settings.RFC_PATH,doc.canonical_name()+".txt")
302+
else:
303+
filename=os.path.join(settings.INTERNET_DRAFT_PATH,doc.filename_with_rev())
304+
305+
try:
306+
refs = draft.Draft(draft._gettext(filename), filename).get_refs()
307+
except IOError as e:
308+
return { 'errors': ["%s :%s" % (e.strerror, filename)] }
309+
310+
doc.relateddocument_set.filter(relationship__slug__in=['refnorm','refinfo','refold','refunk']).delete()
311+
312+
warnings = []
313+
errors = []
314+
unfound = set()
315+
for ( ref, refType ) in refs.iteritems():
316+
refdoc = DocAlias.objects.filter( name=ref )
317+
count = refdoc.count()
318+
if count == 0:
319+
unfound.add( "%s" % ref )
320+
continue
321+
elif count > 1:
322+
errors.append("Too many DocAlias objects found for %s"%ref)
323+
else:
324+
# Don't add references to ourself
325+
if doc != refdoc[0].document:
326+
RelatedDocument.objects.get_or_create( source=doc, target=refdoc[ 0 ], relationship=DocRelationshipName.objects.get( slug='ref%s' % refType ) )
327+
if unfound:
328+
warnings.append('There were %d references with no matching DocAlias'%len(unfound))
329+
330+
ret = {}
331+
if errors:
332+
ret['errors']=errors
333+
if warnings:
334+
ret['warnings']=warnings
335+
if unfound:
336+
ret['unfound']=list(unfound)
337+
338+
return ret

ietf/meeting/tests/agenda-83-utc.html.good

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ img.hidden { display: none; }
8686
</head>
8787
<body class="yui-skin-sam" onload='setGroupState();updateAgendaColors()'>
8888
<div style="background-color:#c00000;color:white;font-size:150%;height:35px;" class="noprint">
89-
<a href="/" style="text-decoration:none;color:white"><img src="/images/ietflogo-blue-small.png" width="60" height="34" style="vertical-align:middle;padding-left:8px;" alt=""/><span style="padding-left:15px;font-weight:bold;letter-spacing:0.1em;">datatracker.ietf.org</a> - DEVELOPMENT MODE</span>
89+
<span style="padding-left:15px;font-weight:bold;letter-spacing:0.1em;"><a href="/" style="text-decoration:none;color:white"><img src="/images/ietflogo-blue-small.png" width="60" height="34" style="vertical-align:middle;padding-left:8px;" alt=""/>datatracker.ietf.org</a> - DEVELOPMENT MODE</span>
9090
</div>
9191

9292

ietf/meeting/tests/agenda-83.html.good

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ img.hidden { display: none; }
9090
</head>
9191
<body class="yui-skin-sam" onload='setGroupState();updateAgendaColors()'>
9292
<div style="background-color:#c00000;color:white;font-size:150%;height:35px;" class="noprint">
93-
<a href="/" style="text-decoration:none;color:white"><img src="/images/ietflogo-blue-small.png" width="60" height="34" style="vertical-align:middle;padding-left:8px;" alt=""/><span style="padding-left:15px;font-weight:bold;letter-spacing:0.1em;">datatracker.ietf.org</a> - DEVELOPMENT MODE</span>
93+
<span style="padding-left:15px;font-weight:bold;letter-spacing:0.1em;"><a href="/" style="text-decoration:none;color:white"><img src="/images/ietflogo-blue-small.png" width="60" height="34" style="vertical-align:middle;padding-left:8px;" alt=""/>datatracker.ietf.org</a> - DEVELOPMENT MODE</span>
9494
</div>
9595

9696

0 commit comments

Comments
 (0)