Change view /ipr/by-draft-recursive to use static content
- Legacy-Id: 19488
This commit is contained in:
parent
c09baf47a5
commit
93d5d193e5
17
ietf/ipr/management/commands/generate_draft_recursive_txt.py
Normal file
17
ietf/ipr/management/commands/generate_draft_recursive_txt.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Copyright The IETF Trust 2014-2021, All Rights Reserved
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
|
from ietf.ipr.utils import generate_draft_recursive_txt
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = ("Generate machine-readable list of IPR disclosures by draft name (recursive)")
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
try:
|
||||||
|
generate_draft_recursive_txt()
|
||||||
|
except (ValueError, IOError) as e:
|
||||||
|
raise CommandError(e)
|
26
ietf/ipr/migrations/0009_generate_draft_recursive_txt.py
Normal file
26
ietf/ipr/migrations/0009_generate_draft_recursive_txt.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# Generated by Django 2.2.24 on 2021-10-28 11:20
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.management import call_command
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def forwards(apps, schema_editor):
|
||||||
|
call_command('generate_draft_recursive_txt')
|
||||||
|
os.chmod('/a/ietfdata/derived/ipr_draft_recursive.txt', 0o666)
|
||||||
|
|
||||||
|
|
||||||
|
def reverse(apps, schema_editor):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('ipr', '0008_auto_20201109_0439'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(forwards, reverse),
|
||||||
|
]
|
|
@ -1,6 +1,9 @@
|
||||||
# Copyright The IETF Trust 2014-2020, All Rights Reserved
|
# Copyright The IETF Trust 2014-2020, All Rights Reserved
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from ietf.ipr.models import IprDocRel
|
||||||
|
|
||||||
import debug # pyflakes:ignore
|
import debug # pyflakes:ignore
|
||||||
|
|
||||||
|
@ -61,4 +64,30 @@ def related_docs(alias, relationship=('replaces', 'obs')):
|
||||||
|
|
||||||
return list(set(results))
|
return list(set(results))
|
||||||
|
|
||||||
|
|
||||||
|
def generate_draft_recursive_txt():
|
||||||
|
docipr = {}
|
||||||
|
|
||||||
|
for o in IprDocRel.objects.filter(disclosure__state='posted').select_related('document'):
|
||||||
|
alias = o.document
|
||||||
|
name = alias.name
|
||||||
|
for document in alias.docs.all():
|
||||||
|
related = set(document.docalias.all()) | set(document.all_related_that_doc(('obs', 'replaces')))
|
||||||
|
for alias in related:
|
||||||
|
name = alias.name
|
||||||
|
if name.startswith("rfc"):
|
||||||
|
name = name.upper()
|
||||||
|
if not name in docipr:
|
||||||
|
docipr[name] = []
|
||||||
|
docipr[name].append(o.disclosure_id)
|
||||||
|
|
||||||
|
lines = [ "# Machine-readable list of IPR disclosures by draft name" ]
|
||||||
|
for name, iprs in docipr.items():
|
||||||
|
lines.append(name + "\t" + "\t".join(str(ipr_id) for ipr_id in sorted(iprs)))
|
||||||
|
|
||||||
|
data = '\n'.join(lines)
|
||||||
|
filename = '/a/ietfdata/derived/ipr_draft_recursive.txt'
|
||||||
|
with open(filename, 'w') as f:
|
||||||
|
f.write(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -459,26 +459,14 @@ def by_draft_txt(request):
|
||||||
return HttpResponse("\n".join(lines), content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
|
return HttpResponse("\n".join(lines), content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
|
||||||
|
|
||||||
def by_draft_recursive_txt(request):
|
def by_draft_recursive_txt(request):
|
||||||
docipr = {}
|
"""Returns machine-readable list of IPR disclosures by draft name, recursive.
|
||||||
|
NOTE: this view is expensive and should be removed once tools.ietf.org is retired,
|
||||||
|
including util function and management commands that generate the content for
|
||||||
|
this view."""
|
||||||
|
|
||||||
for o in IprDocRel.objects.filter(disclosure__state='posted').select_related('document'):
|
with open('/a/ietfdata/derived/ipr_draft_recursive.txt') as f:
|
||||||
alias = o.document
|
content = f.read()
|
||||||
name = alias.name
|
return HttpResponse(content, content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
|
||||||
for document in alias.docs.all():
|
|
||||||
related = set(document.docalias.all()) | set(document.all_related_that_doc(('obs', 'replaces')))
|
|
||||||
for alias in related:
|
|
||||||
name = alias.name
|
|
||||||
if name.startswith("rfc"):
|
|
||||||
name = name.upper()
|
|
||||||
if not name in docipr:
|
|
||||||
docipr[name] = []
|
|
||||||
docipr[name].append(o.disclosure_id)
|
|
||||||
|
|
||||||
lines = [ "# Machine-readable list of IPR disclosures by draft name" ]
|
|
||||||
for name, iprs in docipr.items():
|
|
||||||
lines.append(name + "\t" + "\t".join(str(ipr_id) for ipr_id in sorted(iprs)))
|
|
||||||
|
|
||||||
return HttpResponse("\n".join(lines), content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
|
|
||||||
|
|
||||||
|
|
||||||
def new(request, type, updates=None):
|
def new(request, type, updates=None):
|
||||||
|
|
Loading…
Reference in a new issue