Skip to content

Commit 93d5d19

Browse files
committed
Change view /ipr/by-draft-recursive to use static content
- Legacy-Id: 19488
1 parent c09baf4 commit 93d5d19

4 files changed

Lines changed: 80 additions & 20 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright The IETF Trust 2014-2021, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from django.core.management.base import BaseCommand, CommandError
6+
7+
from ietf.ipr.utils import generate_draft_recursive_txt
8+
9+
10+
class Command(BaseCommand):
11+
help = ("Generate machine-readable list of IPR disclosures by draft name (recursive)")
12+
13+
def handle(self, *args, **options):
14+
try:
15+
generate_draft_recursive_txt()
16+
except (ValueError, IOError) as e:
17+
raise CommandError(e)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 2.2.24 on 2021-10-28 11:20
2+
3+
import os
4+
5+
from django.core.management import call_command
6+
from django.db import migrations
7+
8+
9+
def forwards(apps, schema_editor):
10+
call_command('generate_draft_recursive_txt')
11+
os.chmod('/a/ietfdata/derived/ipr_draft_recursive.txt', 0o666)
12+
13+
14+
def reverse(apps, schema_editor):
15+
pass
16+
17+
18+
class Migration(migrations.Migration):
19+
20+
dependencies = [
21+
('ipr', '0008_auto_20201109_0439'),
22+
]
23+
24+
operations = [
25+
migrations.RunPython(forwards, reverse),
26+
]

ietf/ipr/utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright The IETF Trust 2014-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

4+
import sys
5+
6+
from ietf.ipr.models import IprDocRel
47

58
import debug # pyflakes:ignore
69

@@ -61,4 +64,30 @@ def related_docs(alias, relationship=('replaces', 'obs')):
6164

6265
return list(set(results))
6366

67+
68+
def generate_draft_recursive_txt():
69+
docipr = {}
70+
71+
for o in IprDocRel.objects.filter(disclosure__state='posted').select_related('document'):
72+
alias = o.document
73+
name = alias.name
74+
for document in alias.docs.all():
75+
related = set(document.docalias.all()) | set(document.all_related_that_doc(('obs', 'replaces')))
76+
for alias in related:
77+
name = alias.name
78+
if name.startswith("rfc"):
79+
name = name.upper()
80+
if not name in docipr:
81+
docipr[name] = []
82+
docipr[name].append(o.disclosure_id)
83+
84+
lines = [ "# Machine-readable list of IPR disclosures by draft name" ]
85+
for name, iprs in docipr.items():
86+
lines.append(name + "\t" + "\t".join(str(ipr_id) for ipr_id in sorted(iprs)))
87+
88+
data = '\n'.join(lines)
89+
filename = '/a/ietfdata/derived/ipr_draft_recursive.txt'
90+
with open(filename, 'w') as f:
91+
f.write(data)
92+
6493

ietf/ipr/views.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -459,26 +459,14 @@ def by_draft_txt(request):
459459
return HttpResponse("\n".join(lines), content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
460460

461461
def by_draft_recursive_txt(request):
462-
docipr = {}
463-
464-
for o in IprDocRel.objects.filter(disclosure__state='posted').select_related('document'):
465-
alias = o.document
466-
name = alias.name
467-
for document in alias.docs.all():
468-
related = set(document.docalias.all()) | set(document.all_related_that_doc(('obs', 'replaces')))
469-
for alias in related:
470-
name = alias.name
471-
if name.startswith("rfc"):
472-
name = name.upper()
473-
if not name in docipr:
474-
docipr[name] = []
475-
docipr[name].append(o.disclosure_id)
476-
477-
lines = [ "# Machine-readable list of IPR disclosures by draft name" ]
478-
for name, iprs in docipr.items():
479-
lines.append(name + "\t" + "\t".join(str(ipr_id) for ipr_id in sorted(iprs)))
480-
481-
return HttpResponse("\n".join(lines), content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
462+
"""Returns machine-readable list of IPR disclosures by draft name, recursive.
463+
NOTE: this view is expensive and should be removed once tools.ietf.org is retired,
464+
including util function and management commands that generate the content for
465+
this view."""
466+
467+
with open('/a/ietfdata/derived/ipr_draft_recursive.txt') as f:
468+
content = f.read()
469+
return HttpResponse(content, content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
482470

483471

484472
def new(request, type, updates=None):

0 commit comments

Comments
 (0)