add support for optional patterns

This commit is contained in:
Jan Dittberner 2010-06-03 22:35:37 +02:00
parent cce0d82f56
commit 3a28db9439
2 changed files with 12 additions and 8 deletions

View file

@ -78,6 +78,7 @@ db.pattern=http://db.debian.org/search.cgi?uid=%(username)s&dosearch=Search
alioth.pattern=http://alioth.debian.org/users/%(aliothusername)s/ alioth.pattern=http://alioth.debian.org/users/%(aliothusername)s/
wiki.pattern=http://wiki.debian.org/%(wikihomepage)s wiki.pattern=http://wiki.debian.org/%(wikihomepage)s
forum.pattern=http://forums.debian.net/memberlist.php?mode=viewprofile&u=%(forumsid)d forum.pattern=http://forums.debian.net/memberlist.php?mode=viewprofile&u=%(forumsid)d
forum.optional=true
[miscellaneous] [miscellaneous]
urls=debtags,links,website,search urls=debtags,links,website,search

View file

@ -2,7 +2,7 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
# #
# DDPortfolio service url builder # DDPortfolio service url builder
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info> # Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of DDPortfolio service. # This file is part of DDPortfolio service.
# #
@ -72,17 +72,20 @@ def build_urls(fields):
if my_config.has_option(section, 'urls'): if my_config.has_option(section, 'urls'):
for url in my_config.get(section, 'urls').split(','): for url in my_config.get(section, 'urls').split(','):
if my_config.has_option(section, url + '.pattern'): if my_config.has_option(section, url + '.pattern'):
optional = my_config.has_option(section, url + '.optional') \
and my_config.getboolean(section, url + '.optional') or False
try: try:
data.append( data.append(
['url', section, url, ['url', section, url,
my_config.get(section, url + '.pattern', my_config.get(section, url + '.pattern',
False, qfields)]) False, qfields)])
except InterpolationMissingOptionError, e: except InterpolationMissingOptionError, e:
if e.reference in _FIELDNAMES_MAP: if not optional:
data.append(['error', section, url, if e.reference in _FIELDNAMES_MAP:
_('Missing input: %s') % \ data.append(['error', section, url,
_(_FIELDNAMES_MAP[e.reference])]) _('Missing input: %s') % \
else: _(_FIELDNAMES_MAP[e.reference])])
data.append(['error', section, url, else:
_('Missing input: %s') % e.reference]) data.append(['error', section, url,
_('Missing input: %s') % e.reference])
return data return data