forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
107 lines (85 loc) · 3.79 KB
/
utils.py
File metadata and controls
107 lines (85 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Copyright The IETF Trust 2014-2025, All Rights Reserved
# -*- coding: utf-8 -*-
import json
import debug # pyflakes:ignore
from textwrap import dedent
from django.core import serializers
from ietf.ipr.mail import process_response_email, UndeliverableIprResponseError
from ietf.ipr.models import IprDocRel
def get_genitive(name):
"""Return the genitive form of name"""
return name + "'" if name.endswith('s') else name + "'s"
def get_ipr_summary(disclosure):
"""Return IPR related document names as a formatted string"""
names = []
for doc in disclosure.docs.all():
if doc.name.startswith('rfc'):
names.append('RFC {}'.format(doc.name[3:]))
else:
names.append(doc.name)
if disclosure.other_designations:
names.append(disclosure.other_designations)
if not names:
summary = ''
elif len(names) == 1:
summary = names[0]
elif len(names) == 2:
summary = " and ".join(names)
elif len(names) > 2:
summary = ", ".join(names[:-1]) + ", and " + names[-1]
return summary if len(summary) <= 128 else summary[:125]+'...'
def iprs_from_docs(docs,**kwargs):
"""Returns a list of IPRs related to docs"""
iprdocrels = []
for document in docs:
if document.ipr(**kwargs):
iprdocrels += document.ipr(**kwargs)
return list(set([i.disclosure for i in iprdocrels]))
def related_docs(doc, relationship=('replaces', 'obs'), reverse_relationship=("became_rfc",)):
"""Returns list of related documents"""
results = [doc]
rels = doc.all_relations_that_doc(relationship)
for rel in rels:
rel.target.related = rel
rel.target.relation = rel.relationship.revname
results += [x.target for x in rels]
rev_rels = doc.all_relations_that(reverse_relationship)
for rel in rev_rels:
rel.source.related = rel
rel.source.relation = rel.relationship.name
results += [x.source for x in rev_rels]
return list(set(results))
def ingest_response_email(message: bytes):
from ietf.api.views import EmailIngestionError # avoid circular import
try:
process_response_email(message)
except UndeliverableIprResponseError:
# Message was rejected due to some problem the sender can fix, so bounce but don't send
# an email to the admins
raise EmailIngestionError("IPR response rejected", email_body=None)
except Exception as err:
# Message was rejected due to an unhandled exception. This is likely something
# the admins need to address, so send them a copy of the email.
raise EmailIngestionError(
"Datatracker IPR email ingestion error",
email_body=dedent("""\
An error occurred while ingesting IPR email into the Datatracker. The original message is attached.
{error_summary}
"""),
email_original_message=message,
email_attach_traceback=True,
) from err
def json_dump_disclosure(disclosure):
objs = set()
objs.add(disclosure)
objs.add(disclosure.iprdisclosurebase_ptr)
objs.add(disclosure.by)
objs.update(IprDocRel.objects.filter(disclosure=disclosure))
objs.update(disclosure.iprevent_set.all())
objs.update([i.by for i in disclosure.iprevent_set.all()])
objs.update([i.message for i in disclosure.iprevent_set.all() if i.message ])
objs.update([i.message.by for i in disclosure.iprevent_set.all() if i.message ])
objs.update([i.in_reply_to for i in disclosure.iprevent_set.all() if i.in_reply_to ])
objs.update([i.in_reply_to.by for i in disclosure.iprevent_set.all() if i.in_reply_to ])
objs = sorted(list(objs),key=lambda o:o.__class__.__name__)
return json.dumps(json.loads(serializers.serialize("json",objs)),indent=4)