Skip to content

Commit 3395d6f

Browse files
committed
Add simple back-filling of affiliation on authors to backfilling script
- Legacy-Id: 12750
1 parent 8fdb004 commit 3395d6f

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

ietf/stats/backfill_data.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
parser.add_argument("--document", help="specific document name")
2222
parser.add_argument("--words", action="store_true", help="fill in word count")
2323
parser.add_argument("--formlang", action="store_true", help="fill in formal languages")
24+
parser.add_argument("--authors", action="store_true", help="fill in author info")
2425
args = parser.parse_args()
2526

2627
formal_language_dict = { l.pk: l for l in FormalLanguageName.objects.all() }
@@ -31,7 +32,7 @@
3132
if args.document:
3233
docs_qs = docs_qs.filter(docalias__name=args.document)
3334

34-
for doc in docs_qs.prefetch_related("docalias_set", "formal_languages"):
35+
for doc in docs_qs.prefetch_related("docalias_set", "formal_languages", "documentauthor_set", "documentauthor_set__person", "documentauthor_set__person__alias_set"):
3536
canonical_name = doc.name
3637
for n in doc.docalias_set.all():
3738
if n.name.startswith("rfc"):
@@ -72,6 +73,35 @@
7273
doc.formal_languages.remove(l)
7374
updated = True
7475

76+
if args.authors:
77+
old_authors = doc.documentauthor_set.all()
78+
old_authors_by_name = {}
79+
old_authors_by_email = {}
80+
for author in old_authors:
81+
for alias in author.person.alias_set.all():
82+
old_authors_by_name[alias.name] = author
83+
84+
if author.email_id:
85+
old_authors_by_email[author.email_id] = author
86+
87+
for full, _, _, _, _, email, company in d.get_author_list():
88+
old_author = None
89+
if email:
90+
old_author = old_authors_by_email.get(email)
91+
if not old_author:
92+
old_author = old_authors_by_name.get(full)
93+
94+
if not old_author:
95+
print "UNKNOWN AUTHOR", doc.name, full, email, company
96+
continue
97+
98+
if old_author.affiliation != company:
99+
print "new affiliation", old_author.affiliation, company
100+
old_author.affiliation = company
101+
old_author.save(update_fields=["affiliation"])
102+
updated = True
103+
104+
75105
if updates:
76106
Document.objects.filter(pk=doc.pk).update(**updates)
77107
updated = True

0 commit comments

Comments
 (0)