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 urls=people,oldpeople,alioth
people.pattern=http://people.debian.org/~%(username)s/ people.pattern=http://people.debian.org/~%(username)s/
oldpeople.pattern=http://oldpeople.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] [membership]
urls=nm,db,alioth urls=nm,db,alioth
nm.pattern=https://nm.debian.org/nmstatus.php?email=%(email)s nm.pattern=https://nm.debian.org/nmstatus.php?email=%(email)s
db.pattern=http://db.debian.org/search.cgi?uid=%(username)s&dosearch=Search 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] [miscellaneous]
urls=debtags,links urls=debtags,links

View file

@ -26,8 +26,11 @@ class DeveloperData(formencode.Schema):
"""Validation schema for DeveloperData.""" """Validation schema for DeveloperData."""
allow_extra_fields = True allow_extra_fields = True
filter_extra_fields = True filter_extra_fields = True
name = formencode.validators.String(not_empty=True)
email = formencode.validators.Email(not_empty=True) email = formencode.validators.Email(not_empty=True)
username = formencode.validators.PlainText(not_empty=True) name = formencode.validators.String(not_empty=True)
# TODO: add validation for fingerprint field gpgfp = formencode.All(formencode.validators.PlainText(),
# TODO: add validation for mode field 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,25 +26,35 @@ URLs using the given information and the URL patterns defined in
ddportfolio.ini. ddportfolio.ini.
""" """
import ConfigParser from ConfigParser import ConfigParser, InterpolationMissingOptionError
import pkg_resources import pkg_resources
from ddportfolioservice.model import keyfinder from ddportfolioservice.model import keyfinder
from urllib import quote_plus 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')) 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): def build_urls(fields):
"""Build personalized URLs using the developer information in """Build personalized URLs using the developer information in
fields.""" fields."""
data = [] data = []
qfields = dict([(key, quote_plus(fields[key].encode('utf8'))) \ qfields = dict([(key, quote_plus(fields[key].encode('utf8'))) \
for key in fields]) for key in fields if fields[key] is not None])
fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8')) if 'gpgfp' not in qfields:
if fpr: fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8'))
qfields['gpgfp'] = fpr[0] if fpr:
qfields['gpgfp'] = fpr[0]
for section in [section.strip() for section in \ for section in [section.strip() for section in \
my_config.get('DEFAULT', my_config.get('DEFAULT',
'urlbuilder.sections').split(',')]: 'urlbuilder.sections').split(',')]:
@ -57,6 +67,8 @@ def build_urls(fields):
['url', section, url, ['url', section, url,
my_config.get(section, url + '.pattern', my_config.get(section, url + '.pattern',
False, qfields)]) False, qfields)])
except Exception, e: except InterpolationMissingOptionError, e:
data.append(['error', section, url, str(e)]) data.append(['error', section, url,
_('Missing field %s') % \
_(_FIELDNAMES_MAP[e.reference])])
return data return data

View file

@ -21,36 +21,76 @@ License along with this program. If not, see
<http://www.gnu.org/licenses/>. <http://www.gnu.org/licenses/>.
</%doc> </%doc>
<html> <html>
<head> <head>
<title>${_('Debian Developer Portfolio')}</title> <title>${_('Debian Developer Portfolio')}</title>
${h.stylesheet_link_tag('style')} ${h.stylesheet_link_tag('style')}
</head> </head>
<body> <body>
${h.start_form(h.url_for(action='urllist'), method='get')} ${h.start_form(h.url_for(action='urllist'), method='get')}
<fieldset id="ddportfolio"> <fieldset id="ddportfolio">
<legend>${_('Debian Developer Portfolio')}</legend> <legend>${_('Debian Developer Portfolio')}</legend>
<label for="name">${_('Name:')} <div id="emailfield">
% if 'name' in c.messages['errors']: <label for="email">${_('E-Mail address:')}
<br /><span class="errormsg">${c.messages['errors']['name']}</span> % if 'email' in c.messages['errors']:
% endif <br />
</label><br /> <span class="errormsg">${c.messages['errors']['email']}</span>
${h.text_field('name', value=request.params.get('name', None))}<br /> % endif
<label for="email">${_('E-Mail address:')} </label><br />
% if 'email' in c.messages['errors']: ${h.text_field('email', value=request.params.get('email', None))}<br />
<br /><span class="errormsg">${c.messages['errors']['email']}</span> </div>
% endif <div id="namefield">
</label><br /> <label for="name">${_('Name:')}
${h.text_field('email', value=request.params.get('email', None))}<br /> % if 'name' in c.messages['errors']:
<label for="username">${_('User name:')} <br />
% if 'username' in c.messages['errors']: <span class="errormsg">${c.messages['errors']['name']}</span>
<br /><span class="errormsg">${c.messages['errors']['username']}</span> % endif
% endif </label><br />
</label><br /> ${h.text_field('name', value=request.params.get('name', None))}<br />
${h.text_field('username', value=request.params.get('username', None))}<br /> </div>
<label for="mode_html">${_('Output format:')}</label><br /> <div id="gpgfpfield">
${_('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 /> <label for="gpgfp">${_('GPG fingerprint:')}
${h.submit(value=_('Build DD Portfolio URLs'))} % if 'gpgfp' in c.messages['errors']:
</fieldset> <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()} ${h.end_form()}
</body> </body>
</html> </html>