Fix form to not crash on invalid author extraction. Fixes

- Legacy-Id: 2893
This commit is contained in:
Emilio A. Sánchez López 2011-03-17 17:11:47 +00:00
parent db905d3903
commit 2c2655a564
3 changed files with 27 additions and 6 deletions
ietf
submit
templates/submit

View file

@ -272,8 +272,18 @@ class UploadForm(forms.Form):
)
order = 0
for author in draft.get_authors():
name, email = author.rsplit(' ', 1)
first_name, last_name = name.split(' ', 1)
try:
name, email = author.rsplit(' ', 1)
except ValueError:
first_name = author
last_name = ''
email = ''
else:
try:
first_name, last_name = name.split(' ', 1)
except ValueError:
first_name = name
last_name = ''
email = email.replace('<', '').replace('>', '')
order += 1
TempIdAuthors.objects.create(

View file

@ -166,6 +166,16 @@ class DraftValidation(object):
def validate_authors(self):
if not self.authors:
self.add_warning('authors', 'No authors found')
return
index = 1
message = ''
for author in self.authors:
if not author.last_name:
message += 'Author %s has no last name<br />' % index
if not author.email:
message += 'Author %s has no email<br />' % index
if message:
self.add_warning('authors', message)
def validate_creation_date(self):
date = self.draft.creation_date

View file

@ -152,11 +152,12 @@ returned to the submitter.
<tr><th>File size</th><td>{{ detail.filesize|filesizeformat }}</td></tr>
<tr{% if validation.warnings.creation_date %} class="warning"{% endif %}><th>Creation date</th><td>{{ detail.creation_date }}<div class="warn_message">{{ validation.warnings.creation_date }}</div></td></tr>
<tr{% if validation.warnings.authors %} class="warning"{% endif %}><th colspan="2">Author(s) information</th></tr>
{% if not validation.authors %}
<tr class="warning"><td colspan="2"><div class="warn_message">{{ validation.warning.authors }}</div></td></tr>
{% else %}
{% if validation.warnings.authors %}
<tr class="warning"><td colspan="2"><div class="warn_message">{{ validation.warnings.authors|safe }}</div></td></tr>
{% endif %}
{% if validation.authors %}
{% for author in validation.authors %}
<tr><th class="author">Author {{ forloop.counter }}</th><td>{{ author.email.0 }} &lt;{{ author.email.1 }}&gt;</td></tr>
<tr{% if validation.warnings.authors %} class="warning"{% endif %}><th class="author">Author {{ forloop.counter }}</th><td>{{ author.email.0 }} &lt;{{ author.email.1 }}&gt;</td></tr>
{% endfor %}
{% endif %}
<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>