add fields, improve validation, improve error messages

- add fields for GPG fingerprint and Alioth username
- add validation for new fields, mode and fingerprint
- implement translation and human readable text for error messages
This commit is contained in:
Jan Dittberner 2009-01-22 21:06:23 +01:00
parent a50dc731b6
commit 67a945dd49
4 changed files with 99 additions and 44 deletions

View file

@ -63,13 +63,13 @@ gmane.pattern=http://search.gmane.org/?email=%(name)s&group=gmane.linux.debi
urls=people,oldpeople,alioth
people.pattern=http://people.debian.org/~%(username)s/
oldpeople.pattern=http://oldpeople.debian.org/~%(username)s/
alioth.pattern=http://alioth.debian.org/~%(username)s/
alioth.pattern=http://alioth.debian.org/~%(aliothusername)s/
[membership]
urls=nm,db,alioth
nm.pattern=https://nm.debian.org/nmstatus.php?email=%(email)s
db.pattern=http://db.debian.org/search.cgi?uid=%(username)s&dosearch=Search
alioth.pattern=http://alioth.debian.org/users/%(username)s/
alioth.pattern=http://alioth.debian.org/users/%(aliothusername)s/
[miscellaneous]
urls=debtags,links

View file

@ -26,8 +26,11 @@ class DeveloperData(formencode.Schema):
"""Validation schema for DeveloperData."""
allow_extra_fields = True
filter_extra_fields = True
name = formencode.validators.String(not_empty=True)
email = formencode.validators.Email(not_empty=True)
username = formencode.validators.PlainText(not_empty=True)
# TODO: add validation for fingerprint field
# TODO: add validation for mode field
name = formencode.validators.String(not_empty=True)
gpgfp = formencode.All(formencode.validators.PlainText(),
formencode.validators.MinLength(32),
formencode.validators.MaxLength(32))
username = formencode.validators.PlainText()
aliothusername = formencode.validators.PlainText()
mode = formencode.validators.OneOf([u'json', u'html'], not_empty=True)

View file

@ -26,22 +26,32 @@ URLs using the given information and the URL patterns defined in
ddportfolio.ini.
"""
import ConfigParser
from ConfigParser import ConfigParser, InterpolationMissingOptionError
import pkg_resources
from ddportfolioservice.model import keyfinder
from urllib import quote_plus
from pylons.i18n.translation import _, N_
my_config = ConfigParser.ConfigParser()
my_config = ConfigParser()
my_config.readfp(pkg_resources.resource_stream(__name__, 'ddportfolio.ini'))
_FIELDNAMES_MAP = {
'email' : N_('E-Mail address'),
'name' : N_('Name'),
'gpgfp' : N_('GPG fingerprint'),
'username' : N_('Debian user name'),
'aliothusername' : N_('Alioth user name'),
}
def build_urls(fields):
"""Build personalized URLs using the developer information in
fields."""
data = []
qfields = dict([(key, quote_plus(fields[key].encode('utf8'))) \
for key in fields])
for key in fields if fields[key] is not None])
if 'gpgfp' not in qfields:
fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8'))
if fpr:
qfields['gpgfp'] = fpr[0]
@ -57,6 +67,8 @@ def build_urls(fields):
['url', section, url,
my_config.get(section, url + '.pattern',
False, qfields)])
except Exception, e:
data.append(['error', section, url, str(e)])
except InterpolationMissingOptionError, e:
data.append(['error', section, url,
_('Missing field %s') % \
_(_FIELDNAMES_MAP[e.reference])])
return data

View file

@ -29,27 +29,67 @@ License along with this program. If not, see
${h.start_form(h.url_for(action='urllist'), method='get')}
<fieldset id="ddportfolio">
<legend>${_('Debian Developer Portfolio')}</legend>
<label for="name">${_('Name:')}
% if 'name' in c.messages['errors']:
<br /><span class="errormsg">${c.messages['errors']['name']}</span>
% endif
</label><br />
${h.text_field('name', value=request.params.get('name', None))}<br />
<div id="emailfield">
<label for="email">${_('E-Mail address:')}
% if 'email' in c.messages['errors']:
<br /><span class="errormsg">${c.messages['errors']['email']}</span>
<br />
<span class="errormsg">${c.messages['errors']['email']}</span>
% endif
</label><br />
${h.text_field('email', value=request.params.get('email', None))}<br />
<label for="username">${_('User name:')}
% if 'username' in c.messages['errors']:
<br /><span class="errormsg">${c.messages['errors']['username']}</span>
</div>
<div id="namefield">
<label for="name">${_('Name:')}
% if 'name' in c.messages['errors']:
<br />
<span class="errormsg">${c.messages['errors']['name']}</span>
% endif
</label><br />
${h.text_field('username', value=request.params.get('username', None))}<br />
<label for="mode_html">${_('Output format:')}</label><br />
${_('HTML')}&#160;${h.radio_button('mode', 'html', checked=(request.params.get('mode', 'html') == 'html'))}&#160;${_('JSON')}&#160;${h.radio_button('mode', 'json', checked=(request.params.get('mode', 'html') == 'json'))}<br />
${h.text_field('name', value=request.params.get('name', None))}<br />
</div>
<div id="gpgfpfield">
<label for="gpgfp">${_('GPG fingerprint:')}
% if 'gpgfp' in c.messages['errors']:
<br />
<span class="errormsg">${c.messages['errors']['gpgfp']}</span>
% endif
</label><br />
${h.text_field('gpgfp', value=request.params.get('gpgfp', None))}<br />
</div>
<div id="usernamefield">
<label for="username">${_('Debian user name:')}
% if 'username' in c.messages['errors']:
<br />
<span class="errormsg">${c.messages['errors']['username']}</span>
% endif
</label><br />
${h.text_field('username',
value=request.params.get('username', None))}<br />
</div>
<div id="aliothusernamefield">
<label for="aliothusername">${_('Alioth user name:')}
% if 'aliothusername' in c.messages['errors']:
<br />
<span
class="errormsg">${c.messages['errors']['aliothusername']}</span>
% endif
</label><br />
${h.text_field('aliothusername',
value=request.params.get('username', None))}<br />
</div>
<div id="modefield">
<label for="mode_html">${_('Output format:')}
% if 'mode' in c.messages['errors']:
<br />
<span class="errormsg">${c.messages['errors']['mode']}</span>
% endif
</label><br />
${_('HTML')}&#160;${h.radio_button('mode', 'html',
checked=(request.params.get('mode',
'html') == 'html'))}&#160;${_('JSON')}&#160;${h.radio_button('mode',
'json', checked=(request.params.get('mode', 'html') == 'json'))}<br />
${h.submit(value=_('Build DD Portfolio URLs'))}
</div>
</fieldset>
${h.end_form()}
</body>