Fix issues with incompletely filled forms

This commit reintroduces support for forms with email address as
the only mandatory parameter.
This commit is contained in:
Jan Dittberner 2017-09-12 21:58:46 +02:00
parent fc3d0fe705
commit ff3cc9d940
3 changed files with 21 additions and 19 deletions

View file

@ -42,14 +42,15 @@ class PlainText(Regexp):
class DeveloperData(FlaskForm): class DeveloperData(FlaskForm):
email = StringField('email', validators=[DataRequired(), Email()]) email = StringField('email', validators=[DataRequired(), Email()])
name = StringField('name', validators=[DataRequired()]) name = StringField('name', validators=[Optional(), DataRequired()])
gpgfp = StringField('gpgfp', validators=[ gpgfp = StringField('gpgfp', validators=[
FingerPrint(), Optional(), FingerPrint(), Length(min=32, max=40)
Length(min=32, max=40) ])
username = StringField('username', validators=[Optional(), PlainText()])
nonddemail = StringField('nonddemail', validators=[Optional(), Email()])
aliothusername = StringField('aliothusername', validators=[
Optional(), PlainText()
]) ])
username = StringField('username', validators=[PlainText()])
nonddemail = StringField('nonddemail', validators=[Email()])
aliothusername = StringField('aliothusername', validators=[PlainText()])
mode = RadioField( mode = RadioField(
'mode', default='html', choices=[ 'mode', default='html', choices=[
('json', _('JSON')), ('html', _('HTML')) ('json', _('JSON')), ('html', _('HTML'))

View file

@ -3,7 +3,7 @@
# #
# Debian Member Portfolio Service url builder # Debian Member Portfolio Service url builder
# #
# Copyright © 2009-2015 Jan Dittberner <jan@dittberner.info> # Copyright © 2009-2017 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of the Debian Member Portfolio Service. # This file is part of the Debian Member Portfolio Service.
# #
@ -73,7 +73,7 @@ def _build_quoted_fields(fields):
qfields[key] = quote_plus(value) qfields[key] = quote_plus(value)
else: else:
qfields[key] = value qfields[key] = value
qfields[key] = qfields[key].replace('%', '%%') qfields[key] = str(qfields[key]).replace('%', '%%')
if 'gpgfp' not in qfields: if 'gpgfp' not in qfields:
fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8')) fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8'))

View file

@ -3,7 +3,7 @@
# #
# Debian Member Portfolio Service views # Debian Member Portfolio Service views
# #
# Copyright © 2015 Jan Dittberner <jan@dittberner.info> # Copyright © 2015-2017 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of the Debian Member Portfolio Service. # This file is part of the Debian Member Portfolio Service.
# #
@ -162,25 +162,26 @@ def urllist():
form = DeveloperData(request.values) form = DeveloperData(request.values)
if form.validate(): if form.validate():
fields = dddatabuilder.build_data(form.data['email']) fields = dddatabuilder.build_data(form.data['email'])
rp = request.values
form_data = form.data.copy()
if fields['type'] in (dddatabuilder.TYPE_DD, dddatabuilder.TYPE_DM): if fields['type'] in (dddatabuilder.TYPE_DD, dddatabuilder.TYPE_DM):
for dmtuple in DM_TUPLES: for dmtuple in DM_TUPLES:
if not dmtuple[0] in rp or not rp[dmtuple[0]]: if not form_data[dmtuple[0]]:
rp[dmtuple[0]] = fields[dmtuple[1]] form_data[dmtuple[0]] = fields[dmtuple[1]]
if fields['type'] == dddatabuilder.TYPE_DD: if fields['type'] == dddatabuilder.TYPE_DD:
for ddtuple in DD_TUPLES: for ddtuple in DD_TUPLES:
if not ddtuple[0] in rp or not rp[ddtuple[0]]: if not form_data[ddtuple[0]]:
rp[ddtuple[0]] = fields[ddtuple[1]] form_data[ddtuple[0]] = fields[ddtuple[1]]
if form.data['wikihomepage'] is None: if not form_data['wikihomepage']:
log.debug('generate wikihomepage from name') log.debug('generate wikihomepage from name')
form.data['wikihomepage'] = "".join([ form_data['wikihomepage'] = "".join([
part.capitalize() for part in form.data['name'].split() part.capitalize() for part in form_data['name'].split()
]) ])
data = build_urls(form.data) data = build_urls(form_data)
if form.data['mode'] == 'json': if form_data['mode'] == 'json':
response = make_response(json.dumps(dict( response = make_response(json.dumps(dict(
[("{}.{}".format(entry[1], entry[2].name), entry[3]) [("{}.{}".format(entry[1], entry[2].name), entry[3])
for entry in data if entry[0] == 'url']))) for entry in data if entry[0] == 'url'])))