form.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # encoding=utf-8
  2. from wtforms import validators
  3. from wtforms.fields.core import StringField, BooleanField, FloatField, Field, \
  4. IntegerField, RadioField
  5. from wtforms.fields.simple import PasswordField, TextAreaField
  6. from wtforms.widgets.core import TextInput
  7. from wtforms_tornado import Form
  8. class NumListField(Field):
  9. widget = TextInput()
  10. def _value(self):
  11. if self.data:
  12. return ' '.join([str(data) for data in self.data])
  13. else:
  14. return ''
  15. def process_formdata(self, valuelist):
  16. if valuelist:
  17. self.data = [int(x.strip()) for x in valuelist[0].split()]
  18. else:
  19. self.data = []
  20. class LoginForm(Form):
  21. username = StringField(
  22. 'Username:',
  23. [
  24. validators.Length(min=3, max=30),
  25. validators.Regexp(r'^[a-z0-9_-]+$')
  26. ]
  27. )
  28. password = PasswordField('Password:', [validators.Length(min=8, max=100)])
  29. class AddUserForm(LoginForm):
  30. pass
  31. class ChangePasswordForm(LoginForm):
  32. password = PasswordField(
  33. 'New password:',
  34. [validators.Length(min=8, max=100)]
  35. )
  36. class ConfirmForm(Form):
  37. confirm = BooleanField('Yes, proceed.', [validators.InputRequired()])
  38. class AddProjectForm(Form):
  39. name = StringField(
  40. 'Name:',
  41. [
  42. validators.Length(min=3, max=30),
  43. validators.Regexp(r'^[a-z0-9_-]+$')
  44. ]
  45. )
  46. class ProjectSettingsForm(Form):
  47. min_version = IntegerField('Minimum library version:', [validators.Optional()])
  48. min_client_version = IntegerField('Minimum pipeline version:', [validators.Optional()])
  49. alphabet = StringField('Alphabet:', [validators.InputRequired()])
  50. url_template = StringField(
  51. 'URL template:',
  52. [
  53. validators.InputRequired(),
  54. validators.Regexp(
  55. '^https?://.+{shortcode}',
  56. message='Template does not look like a URL template.'),
  57. ]
  58. )
  59. request_delay = FloatField(
  60. 'Time between requests (seconds)',
  61. [validators.InputRequired()]
  62. )
  63. method = RadioField(
  64. 'HTTP method (get/head):',
  65. [validators.InputRequired()],
  66. choices=[('head', 'head'), ('get', 'get')]
  67. )
  68. redirect_codes = NumListField(
  69. 'Redirect status codes:',
  70. [validators.InputRequired()]
  71. )
  72. no_redirect_codes = NumListField(
  73. 'No redirect status codes:',
  74. [validators.InputRequired()]
  75. )
  76. unavailable_codes = NumListField(
  77. 'Unavailable status codes:',
  78. )
  79. banned_codes = NumListField(
  80. 'Banned status codes:',
  81. )
  82. body_regex = StringField('Content body regular expression:')
  83. location_anti_regex = StringField('Location header reject regular expression:')
  84. class BlockUsernameForm(Form):
  85. username = StringField(
  86. 'Usernames or IP addresses:', [validators.InputRequired()]
  87. )
  88. class UnblockUsernameForm(Form):
  89. pass
  90. class QueueEnableForm(Form):
  91. enabled = BooleanField('Enabled')
  92. class QueueSettingsForm(Form):
  93. autoqueue = BooleanField('AutoQueue')
  94. num_count_per_item = IntegerField('Number of URLs per item:')
  95. max_num_items = IntegerField('Maximum number of items in todo queue:')
  96. lower_sequence_num = IntegerField(
  97. 'Lower sequence number:', [validators.Optional()]
  98. )
  99. autorelease_time = IntegerField(
  100. 'AutoRelease items after minutes:', [validators.Optional()]
  101. )
  102. class AddItemsForm(Form):
  103. items = TextAreaField('Sequence numbers:')
  104. class ReleaseClaimForm(Form):
  105. hours = IntegerField('Release claims older than minutes:')
  106. class ItemActionForm(Form):
  107. pass
  108. class DeleteOneErrorReportForm(Form):
  109. pass
  110. class DeleteAllErrorReportsForm(Form):
  111. pass
  112. class AutoDeleteErrorReportsForm(Form):
  113. enabled = BooleanField('Automatically delete orphaned error reports.')
  114. class CalculatorForm(Form):
  115. number_1 = StringField(
  116. 'Number', [validators.Length(min=0, max=100)]
  117. )
  118. alphabet_1 = StringField(
  119. 'Alphabet', [validators.Length(min=1, max=100)],
  120. default='0123456789'
  121. )
  122. number_2 = StringField(
  123. 'Number', [validators.Length(min=0, max=100)]
  124. )
  125. alphabet_2 = StringField(
  126. 'Alphabet', [validators.Length(min=1, max=100)],
  127. default='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
  128. )