debianmemberportfolio/ddportfolioservice/controllers/ddportfolio.py

198 lines
7.5 KiB
Python
Raw Normal View History

# -*- python -*-
# -*- coding: utf-8 -*-
#
# DDPortfolio service DdportfolioController
2011-01-21 18:34:08 +01:00
# Copyright © 2009, 2010, 2011 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/>.
#
import logging
import simplejson
2010-04-18 21:14:04 +02:00
from pylons import request, tmpl_context as c
from pylons.i18n import N_, _
import formencode.api
import formencode.validators
from ddportfolioservice.lib.base import BaseController, render
from ddportfolioservice.model.form import DDDataRequest, DeveloperData
from ddportfolioservice.model.urlbuilder import build_urls
from ddportfolioservice.model import dddatabuilder
log = logging.getLogger(__name__)
class DdportfolioController(BaseController):
_LABELS = {
'overview' : {
'label' : N_('Overview'),
'ddpo' : N_("Debian Developer's Package Overview"),
'alladdresses' : N_("""Debian Developer's Package Overview
... showing all email addresses"""),
},
'bugs' : {
'label' : N_('Bugs'),
'received' : N_('''bugs received
(note: co-maintainers not listed, see \
<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?\
bug=430986">#430986</a>)'''),
'reported' : N_('bugs reported'),
'bugstats' : N_('bugstats AKA <em>karma</em>'),
'usertags' : N_('user tags'),
'searchall' : N_('all messages (i.e., full text search for \
developer name on all bug logs)'),
'wnpp' : N_('<a href="http://wiki.debian.org/WNPP">WNPP</a>'),
'correspondent' : N_('correspondent for bugs'),
2011-03-06 17:33:33 +01:00
'graph' : N_('one year open bug history graph'),
},
'build' : {
'label' : N_('Build'),
'buildd' : N_('buildd.d.o (note: co-maintainers \
<em>not</em> listed)'),
'igloo' : N_('igloo'),
},
'qa' : {
'label' : N_('Quality Assurance'),
'lintian' : N_('lintian reports'),
'lintianfull' : N_('full lintian reports (i.e. including \
"info"-level messages)'),
'dehs' : N_('DEHS (Debian External Health Status)'),
2010-05-10 21:13:03 +02:00
'piuparts' : N_('piuparts'),
2010-05-10 21:13:57 +02:00
'patchtracker' : N_('Debian patch tracking system'),
},
'upload' : {
'label' : N_('Upload'),
'keylog' : N_('''keylog (per-key upload list)
(note: uses key fingerprint)'''),
},
'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'),
'alioth' : N_('Alioth'),
'wiki' : N_('Wiki'),
'forum' : N_('Forum'),
},
'miscellaneous' : {
'label' : N_('Miscellaneous'),
'debtags' : N_('debtags'),
'links' : N_('links'),
2010-05-10 21:15:46 +02:00
'website' : N_('Debian website'),
2010-05-10 21:17:14 +02:00
'search' : N_('Debian search'),
'gpgfinger' : N_('GPG public key via finger'),
'gpgweb' : N_('GPG public key via HTTP'),
},
'ssh' : {
'label' : N_('Information reachable via ssh (for DDs)'),
'owndndoms' : N_('owned debian.net domains'),
'miainfo' : N_('<a href="http://wiki.debian.org/qa.debian.org/MIATeam">MIA</a> database information'),
'groupinfo' : N_('Group membership information'),
},
2010-05-10 20:15:49 +02:00
'ubuntu' : {
'label' : N_('Ubuntu'),
'ubuntudiff' : N_('Available patches from Ubuntu'),
},
}
def _get_label(self, section, url=None):
if section in self._LABELS:
if url:
if url in self._LABELS[section]:
return self._LABELS[section][url]
elif 'label' in self._LABELS[section]:
return self._LABELS[section]['label']
if url:
return "%s.%s" % (section, url)
return section
def index(self):
# Return a rendered template
# return render('/some/template.mako')
# or, Return a response
return render('/showform.mako')
def urllist(self):
"""Handle the actual data."""
schema = DDDataRequest()
try:
2009-01-21 22:46:59 +01:00
formencode.api.set_stdtranslation(
domain="FormEncode",
languages=[lang[0:2] for lang in request.languages])
form_result = schema.to_python(request.params)
except formencode.validators.Invalid, error:
c.messages = { 'errors' : error.unpack_errors() }
return render('/showform.mako')
fields = dddatabuilder.build_data(form_result['email'])
rp = request.params.copy()
DM_TUPLES = (('name', 'name'),
('gpgfp', 'gpgfp'),
('nonddemail', 'email'))
DD_TUPLES = (('username', 'username'),
('aliothusername', 'username'))
if fields['type'] in (dddatabuilder.TYPE_DD, dddatabuilder.TYPE_DM):
for tuple in DM_TUPLES:
if not tuple[0] in rp or not rp[tuple[0]]:
rp[tuple[0]] = fields[tuple[1]]
if fields['type'] == dddatabuilder.TYPE_DD:
for tuple in DD_TUPLES:
if not tuple[0] in rp or not rp[tuple[0]]:
rp[tuple[0]] = fields[tuple[1]]
schema = DeveloperData()
try:
formencode.api.set_stdtranslation(
domain="FormEncode",
languages=[lang[0:2] for lang in request.languages])
form_result = schema.to_python(rp)
except formencode.validators.Invalid, error:
c.messages = { 'errors' : error.unpack_errors() }
return render('/showform.mako')
if form_result['wikihomepage'] is None:
log.debug('generate wikihomepage from name')
form_result['wikihomepage'] = "".join(
[part.capitalize() for part in form_result['name'].split()])
data = build_urls(form_result)
if form_result['mode'] == 'json':
response.headers['Content-Type'] = 'text/javascript'
return simplejson.dumps(
dict([("%s.%s" % \
(entry[1], entry[2].name), entry[3]) \
for entry in data if entry[0] == 'url']))
for entry in data:
if entry[0] in ('url', 'error'):
entry.append(_(self._get_label(entry[1], entry[2].name)))
elif entry[0] == 'section':
entry.append(_(self._get_label(entry[1])))
c.urldata = data
return render('/showurls.mako')