Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

74 linhas
2.6KB

  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. from __future__ import unicode_literals
  24. from flask_babel import gettext as _
  25. from flask_wtf import FlaskForm
  26. from wtforms import IntegerField, StringField, RadioField
  27. from wtforms.validators import (
  28. AnyOf, DataRequired, Email, Length, Optional, Regexp
  29. )
  30. from string import hexdigits
  31. class FingerPrint(Regexp):
  32. def __init__(self, **kwargs):
  33. super(FingerPrint, self).__init__(r'^[a-fA-F0-9]*$', **kwargs)
  34. class PlainText(Regexp):
  35. def __init__(self):
  36. super(PlainText, self).__init__(r'^[a-zA-Z\-0-9]*$')
  37. def gpg_fingerprint(data):
  38. if data is not None:
  39. return "".join([
  40. char for char in str(data) if char.lower() in hexdigits])
  41. return data
  42. class DeveloperData(FlaskForm):
  43. email = StringField('email', validators=[DataRequired(), Email()])
  44. name = StringField('name', validators=[Optional(), DataRequired()])
  45. gpgfp = StringField('gpgfp', filters=[gpg_fingerprint], validators=[
  46. Optional(), FingerPrint(), Length(min=32, max=40)
  47. ])
  48. username = StringField('username', validators=[Optional(), PlainText()])
  49. nonddemail = StringField('nonddemail', validators=[Optional(), Email()])
  50. salsausername = StringField('salsausername', validators=[
  51. Optional(), PlainText()
  52. ])
  53. mode = RadioField(
  54. 'mode', default='html', choices=[
  55. ('json', _('JSON')), ('html', _('HTML'))
  56. ], validators=[AnyOf(['json', 'html'])]
  57. )
  58. forumsid = IntegerField('forumsid', default=None, validators=[Optional()])
  59. wikihomepage = StringField('wikihomepage', default=None, validators=[
  60. Optional()])
  61. class DeveloperDataRequest(FlaskForm):
  62. email = StringField('email', validators=[DataRequired(), Email()])