Fix issues with incompletely filled forms
authorJan Dittberner <jan@dittberner.info>
Tue, 12 Sep 2017 19:58:46 +0000 (21:58 +0200)
committerJan Dittberner <jan@dittberner.info>
Tue, 12 Sep 2017 19:58:46 +0000 (21:58 +0200)
This commit reintroduces support for forms with email address as
the only mandatory parameter.

debianmemberportfolio/forms.py
debianmemberportfolio/model/urlbuilder.py
debianmemberportfolio/views.py

index 85ccadf..11f6b14 100644 (file)
@@ -42,14 +42,15 @@ class PlainText(Regexp):
 
 class DeveloperData(FlaskForm):
     email = StringField('email', validators=[DataRequired(), Email()])
-    name = StringField('name', validators=[DataRequired()])
+    name = StringField('name', validators=[Optional(), DataRequired()])
     gpgfp = StringField('gpgfp', validators=[
-        FingerPrint(),
-        Length(min=32, max=40)
+        Optional(), FingerPrint(), 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', default='html', choices=[
             ('json', _('JSON')), ('html', _('HTML'))
index f948ddc..d84e302 100644 (file)
@@ -3,7 +3,7 @@
 #
 # 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.
 #
@@ -73,7 +73,7 @@ def _build_quoted_fields(fields):
                 qfields[key] = quote_plus(value)
             else:
                 qfields[key] = value
-            qfields[key] = qfields[key].replace('%', '%%')
+            qfields[key] = str(qfields[key]).replace('%', '%%')
 
     if 'gpgfp' not in qfields:
         fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8'))
index 467ad2f..dd88aa3 100644 (file)
@@ -3,7 +3,7 @@
 #
 # 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.
 #
@@ -162,25 +162,26 @@ def urllist():
     form = DeveloperData(request.values)
     if form.validate():
         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):
             for dmtuple in DM_TUPLES:
-                if not dmtuple[0] in rp or not rp[dmtuple[0]]:
-                    rp[dmtuple[0]] = fields[dmtuple[1]]
+                if not form_data[dmtuple[0]]:
+                    form_data[dmtuple[0]] = fields[dmtuple[1]]
         if fields['type'] == dddatabuilder.TYPE_DD:
             for ddtuple in DD_TUPLES:
-                if not ddtuple[0] in rp or not rp[ddtuple[0]]:
-                    rp[ddtuple[0]] = fields[ddtuple[1]]
-        if form.data['wikihomepage'] is None:
+                if not form_data[ddtuple[0]]:
+                    form_data[ddtuple[0]] = fields[ddtuple[1]]
+        if not form_data['wikihomepage']:
             log.debug('generate wikihomepage from name')
-            form.data['wikihomepage'] = "".join([
-                part.capitalize() for part in form.data['name'].split()
+            form_data['wikihomepage'] = "".join([
+                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(
                 [("{}.{}".format(entry[1], entry[2].name), entry[3])
                  for entry in data if entry[0] == 'url'])))