Jan Dittberner
709f2067cd
- add translatable labels for HTML output (not used for JSON yet) - add oldpeople URL - modify the output template to use one table - add styles - rename action from handle_post to urllist to reflect its use - use a property to determine the order of url sections - use a list with a type to aggregate the urlbuilder results - use textilize to display labels
63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
# -*- python -*-
|
|
# -*- coding: utf8 -*-
|
|
#
|
|
# DDPortfolio service url builder
|
|
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info>
|
|
#
|
|
# This file is part of DDPortfolio service.
|
|
#
|
|
# DDPortfolio service is free software: you can redistribute it and/or
|
|
# modify it under the terms of the GNU Affero General Public License
|
|
# as published by the Free Software Foundation, either version 3 of
|
|
# the License, or (at your option) any later version.
|
|
#
|
|
# DDPortfolio service is distributed in the hope that it will be
|
|
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public
|
|
# License along with this program. If not, see
|
|
# <http://www.gnu.org/licenses/>.
|
|
#
|
|
"""
|
|
This module provides the function build_urls to build personalized
|
|
URLs using the given information and the URL patterns defined in
|
|
ddportfolio.ini.
|
|
"""
|
|
|
|
import ConfigParser
|
|
import pkg_resources
|
|
from ddportfolioservice.model import keyfinder
|
|
from urllib import quote_plus
|
|
|
|
|
|
my_config = ConfigParser.ConfigParser()
|
|
my_config.readfp(pkg_resources.resource_stream(__name__, 'ddportfolio.ini'))
|
|
|
|
|
|
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 section in [section.strip() for section in \
|
|
my_config.get('DEFAULT',
|
|
'urlbuilder.sections').split(',')]:
|
|
data.append(['section', section])
|
|
if my_config.has_option(section, 'urls'):
|
|
for url in my_config.get(section, 'urls').split(','):
|
|
if my_config.has_option(section, url + '.pattern'):
|
|
try:
|
|
data.append(
|
|
['url', section, url,
|
|
my_config.get(section, url + '.pattern',
|
|
False, qfields)])
|
|
except Exception, e:
|
|
data.append(['error', section, url, str(e)])
|
|
return data
|