From 3a28db943932572c3a9e32eb22b359cada104734 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Thu, 3 Jun 2010 22:35:37 +0200 Subject: [PATCH] add support for optional patterns --- ddportfolioservice/model/ddportfolio.ini | 1 + ddportfolioservice/model/urlbuilder.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ddportfolioservice/model/ddportfolio.ini b/ddportfolioservice/model/ddportfolio.ini index 939de89..d4af662 100644 --- a/ddportfolioservice/model/ddportfolio.ini +++ b/ddportfolioservice/model/ddportfolio.ini @@ -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/ wiki.pattern=http://wiki.debian.org/%(wikihomepage)s forum.pattern=http://forums.debian.net/memberlist.php?mode=viewprofile&u=%(forumsid)d +forum.optional=true [miscellaneous] urls=debtags,links,website,search diff --git a/ddportfolioservice/model/urlbuilder.py b/ddportfolioservice/model/urlbuilder.py index 72db643..4c398b1 100644 --- a/ddportfolioservice/model/urlbuilder.py +++ b/ddportfolioservice/model/urlbuilder.py @@ -2,7 +2,7 @@ # -*- coding: utf8 -*- # # DDPortfolio service url builder -# Copyright (c) 2009 Jan Dittberner +# Copyright © 2009, 2010 Jan Dittberner # # This file is part of DDPortfolio service. # @@ -72,17 +72,20 @@ def build_urls(fields): if my_config.has_option(section, 'urls'): for url in my_config.get(section, 'urls').split(','): 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: data.append( ['url', section, url, my_config.get(section, url + '.pattern', False, qfields)]) except InterpolationMissingOptionError, e: - if e.reference in _FIELDNAMES_MAP: - data.append(['error', section, url, - _('Missing input: %s') % \ - _(_FIELDNAMES_MAP[e.reference])]) - else: - data.append(['error', section, url, - _('Missing input: %s') % e.reference]) + if not optional: + if e.reference in _FIELDNAMES_MAP: + data.append(['error', section, url, + _('Missing input: %s') % \ + _(_FIELDNAMES_MAP[e.reference])]) + else: + data.append(['error', section, url, + _('Missing input: %s') % e.reference]) return data