|
21 | 21 | parser.add_argument("--document", help="specific document name") |
22 | 22 | parser.add_argument("--words", action="store_true", help="fill in word count") |
23 | 23 | 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") |
24 | 25 | args = parser.parse_args() |
25 | 26 |
|
26 | 27 | formal_language_dict = { l.pk: l for l in FormalLanguageName.objects.all() } |
|
31 | 32 | if args.document: |
32 | 33 | docs_qs = docs_qs.filter(docalias__name=args.document) |
33 | 34 |
|
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"): |
35 | 36 | canonical_name = doc.name |
36 | 37 | for n in doc.docalias_set.all(): |
37 | 38 | if n.name.startswith("rfc"): |
|
72 | 73 | doc.formal_languages.remove(l) |
73 | 74 | updated = True |
74 | 75 |
|
| 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 | + |
75 | 105 | if updates: |
76 | 106 | Document.objects.filter(pk=doc.pk).update(**updates) |
77 | 107 | updated = True |
|
0 commit comments