Add result view implementation

This commit implements the result view and template.

- fix Python3 configparser interpolation error in portfolio.ini
- debianmemberportfolio.model.urlbuilder ported to Python3
- add showurls.html as a direct Jinja port of showurls.mako
- implement functionality in debianmemberportfolio.views.result
This commit is contained in:
Jan Dittberner 2015-11-12 21:11:48 +01:00
parent 43ade2d35e
commit b7fe1328bb
4 changed files with 238 additions and 13 deletions

View file

@ -83,7 +83,7 @@ webid.optional=true
alioth.pattern=https://alioth.debian.org/users/%(aliothusername)s/ alioth.pattern=https://alioth.debian.org/users/%(aliothusername)s/
alioth.optional=true alioth.optional=true
wiki.pattern=https://wiki.debian.org/%(wikihomepage)s 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 forum.optional=true
[miscellaneous] [miscellaneous]

View file

@ -3,7 +3,7 @@
# #
# Debian Member Portfolio Service url builder # Debian Member Portfolio Service url builder
# #
# Copyright © 2009-2014 Jan Dittberner <jan@dittberner.info> # Copyright © 2009-2015 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of the Debian Member Portfolio Service. # 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. portfolio.ini.
""" """
from ConfigParser import ConfigParser, InterpolationMissingOptionError from configparser import ConfigParser, InterpolationMissingOptionError
from encodings.utf_8 import StreamReader as UTF8StreamReader
import pkg_resources import pkg_resources
from debianmemberportfolio.model import keyfinder from debianmemberportfolio.model import keyfinder
from urllib import quote_plus from urllib.parse import quote_plus
from pylons.i18n.translation import _, N_ from flask.ext.babel import gettext as _, lazy_gettext as N_
my_config = ConfigParser() 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 = { _FIELDNAMES_MAP = {
'email': N_('Email address'), '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. Take a dictionary of raw field values and quote the values if required.
""" """
qfields = {} qfields = {}
for key, value in fields.iteritems(): for key, value in fields.items():
if value is not None: if value is not None:
if isinstance(value, unicode): if isinstance(value, str):
qfields[key] = quote_plus(value.encode('utf8')) qfields[key] = quote_plus(value.encode('utf8'))
elif isinstance(value, str): elif isinstance(value, str):
qfields[key] = quote_plus(value) qfields[key] = quote_plus(value)
else: else:
qfields[key] = value qfields[key] = value
qfields[key] = qfields[key].replace('%', '%%')
if 'gpgfp' not in qfields: if 'gpgfp' not in qfields:
fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8')) fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8'))
@ -97,8 +101,8 @@ def build_urls(fields):
data.append( data.append(
['url', section, entry, ['url', section, entry,
my_config.get(section, entry.name + '.pattern', my_config.get(section, entry.name + '.pattern',
False, qfields)]) raw=False, vars=qfields)])
except InterpolationMissingOptionError, e: except InterpolationMissingOptionError as e:
if not entry.optional: if not entry.optional:
if e.reference in _FIELDNAMES_MAP: if e.reference in _FIELDNAMES_MAP:
data.append(['error', section, entry, data.append(['error', section, entry,

View file

@ -0,0 +1,61 @@
{% extends "base.html" %}
{#
Template for the url output page.
Copyright © 2009-2015 Jan Dittberner <jan@dittberner.info>
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 <https://www.gnu.org/licenses/>.
#}
{% block title %}{{ super() }} - {{ _('Your personal links') }}{% endblock %}
{% block body %}{{ super() }}
{% if urldata %}
<fieldset id="portfolio">
<legend>{{ _('Debian Member Porfolio') }}</legend>
<table id="urltable">
<thead>
<tr><th>{{ _('Usage') }}</th><th>{{ _('URL') }}</th></tr>
</thead>
<tbody>
{% for row in urldata %}
{% if row[0] == 'section' %}
<tr class="section"><th class="sectionlabel" colspan="2">{{ row[2] }}</th></tr>
{% set urlclass = 'odd' %}
{% elif row[0] == 'error' %}
<tr class="error">
<td>{{ row[4] }}</td>
<td>{{ _('Error during URL creation:') }}
<span class="errormsg">{{ row[3]|replace("\n", "<br />") }}</span></td>
</tr>
{% else %}
<tr class="url {{ urlclass }}">
<td>{{ row[4]|safe }}</td>
<td>
{% if row[2].type == 'url' %}
<a href="{{ row[3] }}">{{ row[3]|truncate(120) }}</a>
{% else %}
<tt>{{ row[3] }}</tt>
{% endif %}
</td>
</tr>
{% if urlclass == "odd" %}{% set urlclass = "even" %}{% else %}{% set urlclass = "odd" %}{% endif %}
{% endif %}
{% endfor %}
</tbody>
</table>
</fieldset>
{% endif %}
<p><a href="{{ url_for('urllist') }}">{{ _('Restart') }}</a></p>
{% endblock body %}

View file

@ -1,14 +1,144 @@
# -*- python -*-
# -*- coding: utf-8 -*-
#
# Debian Member Portfolio Service views
#
# Copyright © 2015 Jan Dittberner <jan@dittberner.info>
#
# 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 <https://www.gnu.org/licenses/>.
#
import json import json
import logging import logging
from debianmemberportfolio import app, babel from debianmemberportfolio import app, babel
from flask import g, make_response, request, render_template, abort 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 config import LANGUAGES
from .forms import DeveloperData, DeveloperDataRequest from .forms import DeveloperData, DeveloperDataRequest
from .model import dddatabuilder from .model import dddatabuilder
from .model.urlbuilder import build_urls
log = logging.getLogger(__name__) 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 \
<a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?\
bug=430986">#430986</a>)'''),
'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_('<a href="https://wiki.debian.org/WNPP">WNPP</a>'),
'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_('<a href="https://wiki.debian.org/qa.debian.org/'
'MIATeam">MIA</a> 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 @babel.localeselector
def get_locale(): def get_locale():
@ -23,8 +153,6 @@ def before_request():
@app.route('/') @app.route('/')
def index(): def index():
form = DeveloperData() form = DeveloperData()
# TODO: replicate behavior of
# debianmemberportfolio.controllers.portfolio.PortfolioController.index
return render_template('showform.html', form=form) return render_template('showform.html', form=form)
@ -32,7 +160,39 @@ def index():
def urllist(): def urllist():
form = DeveloperData(request.values) form = DeveloperData(request.values)
if form.validate(): 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) return render_template('showform.html', form=form)