diff --git a/debianmemberportfolio/model/portfolio.ini b/debianmemberportfolio/model/portfolio.ini index c2bcb7a..097042f 100644 --- a/debianmemberportfolio/model/portfolio.ini +++ b/debianmemberportfolio/model/portfolio.ini @@ -83,7 +83,7 @@ webid.optional=true alioth.pattern=https://alioth.debian.org/users/%(aliothusername)s/ alioth.optional=true wiki.pattern=https://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)s forum.optional=true [miscellaneous] diff --git a/debianmemberportfolio/model/urlbuilder.py b/debianmemberportfolio/model/urlbuilder.py index 33178a5..26e786d 100644 --- a/debianmemberportfolio/model/urlbuilder.py +++ b/debianmemberportfolio/model/urlbuilder.py @@ -3,7 +3,7 @@ # # Debian Member Portfolio Service url builder # -# Copyright © 2009-2014 Jan Dittberner +# Copyright © 2009-2015 Jan Dittberner # # This file is part of the Debian Member Portfolio Service. # @@ -26,15 +26,18 @@ URLs using the given information and the URL patterns defined in portfolio.ini. """ -from ConfigParser import ConfigParser, InterpolationMissingOptionError +from configparser import ConfigParser, InterpolationMissingOptionError +from encodings.utf_8 import StreamReader as UTF8StreamReader + import pkg_resources from debianmemberportfolio.model import keyfinder -from urllib import quote_plus -from pylons.i18n.translation import _, N_ +from urllib.parse import quote_plus +from flask.ext.babel import gettext as _, lazy_gettext as N_ my_config = ConfigParser() -my_config.readfp(pkg_resources.resource_stream(__name__, 'portfolio.ini')) +my_config.read_file(UTF8StreamReader( + pkg_resources.resource_stream(__name__, 'portfolio.ini'))) _FIELDNAMES_MAP = { 'email': N_('Email address'), @@ -62,14 +65,15 @@ def _build_quoted_fields(fields): Take a dictionary of raw field values and quote the values if required. """ qfields = {} - for key, value in fields.iteritems(): + for key, value in fields.items(): if value is not None: - if isinstance(value, unicode): + if isinstance(value, str): qfields[key] = quote_plus(value.encode('utf8')) elif isinstance(value, str): qfields[key] = quote_plus(value) else: qfields[key] = value + qfields[key] = qfields[key].replace('%', '%%') if 'gpgfp' not in qfields: fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8')) @@ -97,8 +101,8 @@ def build_urls(fields): data.append( ['url', section, entry, my_config.get(section, entry.name + '.pattern', - False, qfields)]) - except InterpolationMissingOptionError, e: + raw=False, vars=qfields)]) + except InterpolationMissingOptionError as e: if not entry.optional: if e.reference in _FIELDNAMES_MAP: data.append(['error', section, entry, diff --git a/debianmemberportfolio/templates/showurls.html b/debianmemberportfolio/templates/showurls.html new file mode 100644 index 0000000..4b5165b --- /dev/null +++ b/debianmemberportfolio/templates/showurls.html @@ -0,0 +1,61 @@ +{% extends "base.html" %} +{# +Template for the url output page. +Copyright © 2009-2015 Jan Dittberner + +This file is part of Debian Member Portfolio Service. + +Debian Member Portfolio 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. + +Debian Member Portfolio 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 . +#} +{% block title %}{{ super() }} - {{ _('Your personal links') }}{% endblock %} +{% block body %}{{ super() }} +{% if urldata %} +
+ {{ _('Debian Member Porfolio') }} + + + + + + {% for row in urldata %} + {% if row[0] == 'section' %} + + {% set urlclass = 'odd' %} + {% elif row[0] == 'error' %} + + + + + {% else %} + + + + + {% if urlclass == "odd" %}{% set urlclass = "even" %}{% else %}{% set urlclass = "odd" %}{% endif %} + {% endif %} + {% endfor %} + +
{{ _('Usage') }}{{ _('URL') }}
{{ row[4] }}{{ _('Error during URL creation:') }} + {{ row[3]|replace("\n", "
") }}
{{ row[4]|safe }} + {% if row[2].type == 'url' %} + {{ row[3]|truncate(120) }} + {% else %} + {{ row[3] }} + {% endif %} +
+
+{% endif %} +

{{ _('Restart') }}

+{% endblock body %} + diff --git a/debianmemberportfolio/views.py b/debianmemberportfolio/views.py index a8fa654..70455db 100644 --- a/debianmemberportfolio/views.py +++ b/debianmemberportfolio/views.py @@ -1,14 +1,144 @@ +# -*- python -*- +# -*- coding: utf-8 -*- +# +# Debian Member Portfolio Service views +# +# Copyright © 2015 Jan Dittberner +# +# This file is part of the Debian Member Portfolio Service. +# +# Debian Member Portfolio 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. +# +# Debian Member Portfolio 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 . +# import json import logging from debianmemberportfolio import app, babel from flask import g, make_response, request, render_template, abort +from flask.ext.babel import gettext as _, lazy_gettext as N_ from config import LANGUAGES from .forms import DeveloperData, DeveloperDataRequest from .model import dddatabuilder +from .model.urlbuilder import build_urls log = logging.getLogger(__name__) +#: This dictionary defines groups of labeled portfolio items. +_LABELS = { + 'overview': { + 'label': N_('Overview'), + 'ddpo': N_("Debian Member's Package Overview"), + 'alladdresses': N_("""Debian Member's Package Overview +... showing all email addresses"""), + }, + 'bugs': { + 'label': N_('Bugs'), + 'received': N_('''bugs received +(note: co-maintainers not listed, see \ +#430986)'''), + 'reported': N_('bugs reported'), + 'usertags': N_('user tags'), + 'searchall': N_('all messages (i.e., full text search for \ +developer name on all bug logs)'), + 'wnpp': N_('WNPP'), + 'correspondent': N_('correspondent for bugs'), + 'graph': N_('one year open bug history graph'), + }, + 'build': { + 'label': N_('Build'), + 'buildd': N_('buildd.d.o'), + 'igloo': N_('igloo'), + }, + 'qa': { + 'label': N_('Quality Assurance'), + 'dmd': N_('maintainer dashboard'), + 'lintian': N_('lintian reports'), + 'lintianfull': N_('full lintian reports (i.e. including \ +"info"-level messages)'), + 'piuparts': N_('piuparts'), + 'patchtracker': N_('Debian patch tracking system'), + 'duck': N_('Debian Url ChecKer'), + }, + 'lists': { + 'label': N_('Mailing Lists'), + 'dolists': N_('lists.d.o'), + 'adolists': N_('lists.a.d.o'), + 'gmane': N_('gmane'), + }, + 'files': { + 'label': N_('Files'), + 'people': N_('people.d.o'), + 'oldpeople': N_('oldpeople'), + 'alioth': N_('Alioth'), + }, + 'membership': { + 'label': N_('Membership'), + 'nm': N_('NM'), + 'dbfinger': N_('DB information via finger'), + 'db': N_('DB information via HTTP'), + 'webid': N_('FOAF profile'), + 'alioth': N_('Alioth'), + 'wiki': N_('Wiki'), + 'forum': N_('Forum'), + }, + 'miscellaneous': { + 'label': N_('Miscellaneous'), + 'debtags': N_('debtags'), + 'planetname': N_('Planet Debian (name)'), + 'planetuser': N_('Planet Debian (username)'), + 'links': N_('links'), + 'website': N_('Debian website'), + 'search': N_('Debian search'), + 'gpgfinger': N_('GPG public key via finger'), + 'gpgweb': N_('GPG public key via HTTP'), + 'nm': N_('NM, AM participation'), + 'contrib': N_('Contribution information'), + }, + 'ssh': { + 'label': N_('Information reachable via ssh (for Debian Members)'), + 'owndndoms': N_('owned debian.net domains'), + 'miainfo': N_('MIA database information'), + 'groupinfo': N_('Group membership information'), + }, + 'ubuntu': { + 'label': N_('Ubuntu'), + 'ubuntudiff': N_('Available patches from Ubuntu'), + }, +} + +#: list of field name tuples for Debian Maintainers +DM_TUPLES = (('name', 'name'), + ('gpgfp', 'gpgfp'), + ('nonddemail', 'email')) + +#: list of field name tuples for Debian Developers +DD_TUPLES = (('username', 'username'), + ('aliothusername', 'username')) + + +def _get_label(section, url=None): + if section in _LABELS: + if url: + if url in _LABELS[section]: + return _LABELS[section][url] + elif 'label' in _LABELS[section]: + return _LABELS[section]['label'] + if url: + return "%s.%s" % (section, url) + return section + @babel.localeselector def get_locale(): @@ -23,8 +153,6 @@ def before_request(): @app.route('/') def index(): form = DeveloperData() - # TODO: replicate behavior of - # debianmemberportfolio.controllers.portfolio.PortfolioController.index return render_template('showform.html', form=form) @@ -32,7 +160,39 @@ def index(): def urllist(): form = DeveloperData(request.values) if form.validate(): - return render_template('showurls.html') + fields = dddatabuilder.build_data(form.data['email']) + rp = request.values + + if fields['type'] in (dddatabuilder.TYPE_DD, dddatabuilder.TYPE_DM): + for dmtuple in DM_TUPLES: + if not dmtuple[0] in rp or not rp[dmtuple[0]]: + rp[dmtuple[0]] = fields[dmtuple[1]] + if fields['type'] == dddatabuilder.TYPE_DD: + for ddtuple in DD_TUPLES: + if not ddtuple[0] in rp or not rp[ddtuple[0]]: + rp[ddtuple[0]] = fields[ddtuple[1]] + if form.data['wikihomepage'] is None: + log.debug('generate wikihomepage from name') + form.data['wikihomepage'] = "".join([ + part.capitalize() for part in form.data['name'].split() + ]) + + data = build_urls(form.data) + + if form.data['mode'] == 'json': + response = make_response(json.dumps(dict( + [("{}.{}".format(entry[1], entry[2].name), entry[3]) + for entry in data if entry[0] == 'url']))) + response.headers['Content-Type'] = 'application/json' + return response + + for entry in data: + if entry[0] in ('url', 'error'): + entry.append(_get_label(entry[1], entry[2].name)) + elif entry[0] == 'section': + entry.append(_get_label(entry[1])) + + return render_template('showurls.html', urldata=data) return render_template('showform.html', form=form)