forms.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # GNU MediaGoblin -- federated, autonomous media hosting
  2. # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. import wtforms
  17. from wtforms.ext.sqlalchemy.fields import QuerySelectField
  18. from mediagoblin import mg_globals
  19. from mediagoblin.tools.text import tag_length_validator
  20. from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
  21. from mediagoblin.tools.licenses import licenses_as_choices
  22. def get_submit_start_form(form, **kwargs):
  23. max_file_size = kwargs.get('max_file_size')
  24. desc = None
  25. if max_file_size:
  26. desc = _('Max file size: {0} mb'.format(max_file_size))
  27. class SubmitStartForm(wtforms.Form):
  28. file = wtforms.FileField(
  29. _('File'),
  30. description=desc)
  31. title = wtforms.StringField(
  32. _('Title'),
  33. [wtforms.validators.Length(min=0, max=500)])
  34. description = wtforms.TextAreaField(
  35. _('Description of this work'),
  36. description=_("""You can use
  37. <a href="http://daringfireball.net/projects/markdown/basics">
  38. Markdown</a> for formatting."""))
  39. tags = wtforms.StringField(
  40. _('Tags'),
  41. [tag_length_validator],
  42. description=_(
  43. "Separate tags by commas."))
  44. license = wtforms.SelectField(
  45. _('License'),
  46. [wtforms.validators.Optional(),],
  47. choices=licenses_as_choices())
  48. collection = QuerySelectField(
  49. _('Collection'),
  50. allow_blank=True, blank_text=_('-- Select --'), get_label='title',)
  51. max_file_size = wtforms.HiddenField('')
  52. upload_limit = wtforms.HiddenField('')
  53. uploaded = wtforms.HiddenField('')
  54. return SubmitStartForm(form, **kwargs)
  55. class AddCollectionForm(wtforms.Form):
  56. title = wtforms.StringField(
  57. _('Title'),
  58. [wtforms.validators.Length(min=0, max=500), wtforms.validators.InputRequired()])
  59. description = wtforms.TextAreaField(
  60. _('Description of this collection'),
  61. description=_("""You can use
  62. <a href="http://daringfireball.net/projects/markdown/basics">
  63. Markdown</a> for formatting."""))