Skip to content

Commit 153cdc7

Browse files
committed
Include middle initial and name suffix into authors information if presented.
Fix author update when auto posting. Fixes ietf-tools#626 - Legacy-Id: 2903
1 parent 1dbe9bf commit 153cdc7

3 files changed

Lines changed: 67 additions & 6 deletions

File tree

ietf/submit/forms.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,14 @@ def save_draft_info(self, draft):
272272
)
273273
order = 0
274274
for author in draft.get_author_info():
275-
first_name, last_name, email = author
275+
full_name, first_name, middle_initial, last_name, name_suffix, email = author
276276
order += 1
277277
TempIdAuthors.objects.create(
278278
id_document_tag=document_id,
279279
first_name=first_name,
280+
middle_initial=middle_initial,
280281
last_name=last_name,
282+
name_suffix=name_suffix,
281283
email_address=email,
282284
author_order=order,
283285
submission=detail)
@@ -302,7 +304,7 @@ def get_author_buttons(self):
302304
full_name = '%s. %s' % (i.first_name[0], i.last_name)
303305
buttons.append(button_template % {'first_name': i.first_name,
304306
'last_name': i.last_name,
305-
'email': i.email()[1],
307+
'email': i.email()[1] or '',
306308
'full_name': full_name})
307309
return ''.join(buttons)
308310

ietf/submit/utils.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from django.conf import settings
66
from django.contrib.sites.models import Site
77

8-
from ietf.idtracker.models import InternetDraft, PersonOrOrgInfo, IETFWG
8+
from ietf.idtracker.models import (InternetDraft, PersonOrOrgInfo, IETFWG,
9+
IDAuthor, EmailAddress)
910
from ietf.utils.mail import send_mail
1011

1112

@@ -34,7 +35,6 @@ def request_full_url(request, submission):
3435

3536
def perform_post(submission):
3637
group_id = submission.group_acronym and submission.group_acronym.pk or NONE_WG
37-
updated = False
3838
try:
3939
draft = InternetDraft.objects.get(filename=submission.filename)
4040
draft.title = submission.id_document_name
@@ -47,7 +47,6 @@ def perform_post(submission):
4747
draft.last_modified_date = datetime.date.today()
4848
draft.abstract = submission.abstract
4949
draft.save()
50-
updated = True
5150
except InternetDraft.DoesNotExist:
5251
draft = InternetDraft.objects.create(
5352
title=submission.id_document_name,
@@ -63,11 +62,71 @@ def perform_post(submission):
6362
status_id=1, # Active
6463
intended_status_id=8, # None
6564
)
65+
update_authors(draft, submission)
6666
move_docs(submission)
6767
submission.status_id = POSTED
6868
submission.save()
6969

7070

71+
def find_person(first_name, last_name, middle_initial, name_suffix, email):
72+
person_list = None
73+
if email:
74+
person_list = PersonOrOrgInfo.objects.filter(emailaddress__address=email).distinct()
75+
if person_list and len(person_list) == 1:
76+
return person_list[0]
77+
if not person_list:
78+
person_list = PersonOrOrgInfo.objects.all()
79+
person_list = person_list.filter(first_name=first_name,
80+
last_name=last_name)
81+
if middle_initial:
82+
person_list = person_list.filter(middle_initial=middle_initial)
83+
if name_suffix:
84+
person_list = person_list.filter(name_suffix=name_suffix)
85+
if person_list:
86+
return person_list[0]
87+
return None
88+
89+
90+
def update_authors(draft, submission):
91+
# TempAuthor of order 0 is submitter
92+
new_authors = list(submission.tempidauthors_set.filter(author_order__gt=0))
93+
person_pks = []
94+
for author in new_authors:
95+
person = find_person(author.first_name, author.last_name,
96+
author.middle_initial, author.name_suffix,
97+
author.email_address)
98+
if not person:
99+
person = PersonOrOrgInfo(
100+
first_name=author.first_name,
101+
last_name=author.last_name,
102+
middle_initial=author.middle_initial or '',
103+
name_suffix=author.name_suffix or '',
104+
)
105+
person.save()
106+
if author.email:
107+
EmailAddress.objects.create(
108+
address=author.email,
109+
priority=1,
110+
type='INET',
111+
person_or_org=person,
112+
)
113+
person_pks.append(person.pk)
114+
try:
115+
idauthor = IDAuthor.objects.get(
116+
document=draft,
117+
person=person,
118+
)
119+
idauthor.author_order = author.author_order
120+
except IDAuthor.DoesNotExist:
121+
idauthor = IDAuthor(
122+
document=draft,
123+
person=person,
124+
author_order=author.author_order,
125+
)
126+
idauthor.save()
127+
draft.authors.exclude(person__pk__in=person_pks).delete()
128+
129+
71130
def get_person_for_user(user):
72131
try:
73132
return user.get_profile().person()

ietf/templates/submit/draft_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ <h3>Meta-Data errors found</h3>
157157
{% endif %}
158158
{% if validation.authors %}
159159
{% for author in validation.authors %}
160-
<tr{% if validation.warnings.authors %} class="warning"{% endif %}><th class="author">Author {{ forloop.counter }}</th><td>{{ author.email.0 }} {% if author.email.1 %}&lt;{{ author.email.1 }}&gt;{% endif %}</td></tr>
160+
<tr{% if validation.warnings.authors %} class="warning"{% endif %}><th class="author">Author {{ forloop.counter }}</th><td>{{ author.get_full_name }} {% if author.email.1 %}&lt;{{ author.email.1 }}&gt;{% endif %}</td></tr>
161161
{% endfor %}
162162
{% endif %}
163163
<tr{% if validation.warnings.pages %} class="warning"{% endif %}><th>Pages</th><td>{{ detail.txt_page_count }}<div class="warn_message">{{ validation.warnings.pages }}</div></td></tr>

0 commit comments

Comments
 (0)