You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 line
7.3KB

  1. # -*- python -*-
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Debian Member Portfolio Service views
  5. #
  6. # Copyright © 2015-2017 Jan Dittberner <jan@dittberner.info>
  7. #
  8. # This file is part of the Debian Member Portfolio Service.
  9. #
  10. # Debian Member Portfolio Service is free software: you can redistribute it
  11. # and/or modify it under the terms of the GNU Affero General Public License as
  12. # published by the Free Software Foundation, either version 3 of the License,
  13. # or (at your option) any later version.
  14. #
  15. # Debian Member Portfolio Service is distributed in the hope that it will be
  16. # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  18. # General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. #
  23. import json
  24. import logging
  25. from debianmemberportfolio import app, babel
  26. from flask import g, make_response, request, render_template, abort
  27. # noinspection PyPep8Naming
  28. from flask_babel import lazy_gettext as N_
  29. from config import LANGUAGES
  30. from .forms import DeveloperData, DeveloperDataRequest
  31. from .model import dddatabuilder
  32. from .model.urlbuilder import build_urls
  33. log = logging.getLogger(__name__)
  34. #: This dictionary defines groups of labeled portfolio items.
  35. _LABELS = {
  36. 'overview': {
  37. 'label': N_('Overview'),
  38. 'ddpo': N_("Debian Member's Package Overview"),
  39. 'alladdresses': N_("""Debian Member's Package Overview
  40. ... showing all email addresses"""),
  41. },
  42. 'bugs': {
  43. 'label': N_('Bugs'),
  44. 'received': N_('''bugs received
  45. (note: co-maintainers not listed, see \
  46. <a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?\
  47. bug=430986">#430986</a>)'''),
  48. 'reported': N_('bugs reported'),
  49. 'usertags': N_('user tags'),
  50. 'searchall': N_('all messages (i.e., full text search for \
  51. developer name on all bug logs)'),
  52. 'wnpp': N_('<a href="https://wiki.debian.org/WNPP">WNPP</a>'),
  53. 'correspondent': N_('correspondent for bugs'),
  54. 'graph': N_('one year open bug history graph'),
  55. },
  56. 'build': {
  57. 'label': N_('Build'),
  58. 'buildd': N_('buildd.d.o'),
  59. 'igloo': N_('igloo'),
  60. },
  61. 'qa': {
  62. 'label': N_('Quality Assurance'),
  63. 'dmd': N_('maintainer dashboard'),
  64. 'lintian': N_('lintian reports'),
  65. 'lintianfull': N_('full lintian reports (i.e. including \
  66. "info"-level messages)'),
  67. 'piuparts': N_('piuparts'),
  68. 'patchtracker': N_('Debian patch tracking system'),
  69. 'duck': N_('Debian Url ChecKer'),
  70. 'janitor': N_('Debian Janitor'),
  71. },
  72. 'lists': {
  73. 'label': N_('Mailing Lists'),
  74. 'dolists': N_('lists.d.o'),
  75. 'adolists': N_('lists.a.d.o'),
  76. },
  77. 'files': {
  78. 'label': N_('Files'),
  79. 'people': N_('people.d.o'),
  80. 'oldpeople': N_('oldpeople'),
  81. },
  82. 'membership': {
  83. 'label': N_('Membership'),
  84. 'nm': N_('NM'),
  85. 'dbfinger': N_('DB information via finger'),
  86. 'db': N_('DB information via HTTP'),
  87. 'webid': N_('FOAF profile'),
  88. 'salsa': N_('Salsa'),
  89. 'wiki': N_('Wiki'),
  90. 'forum': N_('Forum'),
  91. },
  92. 'miscellaneous': {
  93. 'label': N_('Miscellaneous'),
  94. 'debtags': N_('debtags'),
  95. 'planetname': N_('Planet Debian (name)'),
  96. 'planetuser': N_('Planet Debian (username)'),
  97. 'links': N_('links'),
  98. 'website': N_('Debian website'),
  99. 'search': N_('Debian search'),
  100. 'gpgfinger': N_('GPG public key via finger'),
  101. 'gpgweb': N_('GPG public key via HTTP'),
  102. 'nm': N_('NM, AM participation'),
  103. 'contrib': N_('Contribution information'),
  104. 'repology': N_('Repology information'),
  105. },
  106. 'ssh': {
  107. 'label': N_('Information reachable via ssh (for Debian Members)'),
  108. 'owndndoms': N_('owned debian.net domains'),
  109. 'miainfo': N_('<a href="https://wiki.debian.org/qa.debian.org/'
  110. 'MIATeam">MIA</a> database information'),
  111. 'groupinfo': N_('Group membership information'),
  112. },
  113. 'ubuntu': {
  114. 'label': N_('Ubuntu'),
  115. 'ubuntudiff': N_('Available patches from Ubuntu'),
  116. },
  117. }
  118. #: list of field name tuples for Debian Maintainers
  119. DM_TUPLES = (('name', 'name'),
  120. ('gpgfp', 'gpgfp'),
  121. ('nonddemail', 'email'))
  122. #: list of field name tuples for Debian Developers
  123. DD_TUPLES = (('username', 'username'),
  124. ('salsausername', 'username'))
  125. def _get_label(section, url=None):
  126. if section in _LABELS:
  127. if url:
  128. if url in _LABELS[section]:
  129. return _LABELS[section][url]
  130. elif 'label' in _LABELS[section]:
  131. return _LABELS[section]['label']
  132. if url:
  133. return "%s.%s" % (section, url)
  134. return section
  135. @babel.localeselector
  136. def get_locale():
  137. return request.accept_languages.best_match(LANGUAGES.keys())
  138. @app.before_request
  139. def before_request():
  140. g.locale = get_locale()
  141. @app.route('/')
  142. def index():
  143. form = DeveloperData()
  144. return render_template('showform.html', form=form)
  145. @app.route('/result')
  146. def urllist():
  147. form = DeveloperData(request.values)
  148. if form.validate():
  149. fields = dddatabuilder.build_data(form.data['email'])
  150. form_data = form.data.copy()
  151. if fields['type'] in (dddatabuilder.TYPE_DD, dddatabuilder.TYPE_DM):
  152. for dmtuple in DM_TUPLES:
  153. if not form_data[dmtuple[0]]:
  154. form_data[dmtuple[0]] = fields[dmtuple[1]]
  155. if fields['type'] == dddatabuilder.TYPE_DD:
  156. for ddtuple in DD_TUPLES:
  157. if not form_data[ddtuple[0]]:
  158. form_data[ddtuple[0]] = fields[ddtuple[1]]
  159. if not form_data['wikihomepage']:
  160. log.debug('generate wikihomepage from name')
  161. form_data['wikihomepage'] = "".join([
  162. part.capitalize() for part in form_data['name'].split()
  163. ])
  164. data = build_urls(form_data)
  165. if form_data['mode'] == 'json':
  166. response = make_response(json.dumps(dict(
  167. [("{}.{}".format(entry[1], entry[2].name), entry[3])
  168. for entry in data if entry[0] == 'url'])))
  169. response.headers['Content-Type'] = 'application/json'
  170. return response
  171. for entry in data:
  172. if entry[0] in ('url', 'error'):
  173. entry.append(_get_label(entry[1], entry[2].name))
  174. elif entry[0] == 'section':
  175. entry.append(_get_label(entry[1]))
  176. return render_template('showurls.html', urldata=data)
  177. return render_template('showform.html', form=form)
  178. @app.route('/htmlformhelper.js')
  179. def formhelper_js():
  180. response = make_response(render_template('showformscript.js'))
  181. response.headers['Content-Type'] = 'text/javascript; charset=utf-8'
  182. return response
  183. @app.route('/showformscripts/fetchdddata/')
  184. def fetchdddata():
  185. form = DeveloperDataRequest(request.values)
  186. if form.validate():
  187. fields = dddatabuilder.build_data(form.data['email'])
  188. log.debug(fields)
  189. response = make_response(json.dumps(fields))
  190. response.headers['Content-Type'] = 'application/json'
  191. return response
  192. abort(
  193. 400,
  194. "\n".join(["%s: %s" % (key, form.errors[key]) for key in form.errors])
  195. )