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:
parent
a50dc731b6
commit
67a945dd49
4 changed files with 99 additions and 44 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -26,25 +26,35 @@ 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])
|
||||
fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8'))
|
||||
if fpr:
|
||||
qfields['gpgfp'] = fpr[0]
|
||||
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]
|
||||
for section in [section.strip() for section in \
|
||||
my_config.get('DEFAULT',
|
||||
'urlbuilder.sections').split(',')]:
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue