tildetown-admin/ttadmin/help/forms.py

51 lines
1.4 KiB
Python
Raw Permalink Normal View History

2016-12-19 23:22:06 +00:00
from datetime import datetime, timedelta
2016-12-19 06:30:41 +00:00
from django.core.exceptions import ValidationError
from django.forms import Form, CharField, EmailField, Textarea, ChoiceField
2016-12-20 07:03:36 +00:00
from common.forms import CaptchaField, throttler
2016-12-19 07:20:48 +00:00
from .models import ISSUE_TYPE_CHOICES
2016-12-19 06:30:41 +00:00
2016-12-19 23:22:06 +00:00
submission_throttle = {}
2016-12-20 07:03:36 +00:00
throttle_submission = throttler(submission_throttle)
2016-12-19 23:22:06 +00:00
2016-12-19 06:30:41 +00:00
def validate_issue_text(text):
if len(text) == 0:
raise ValidationError('please describe yr issue')
if len(text) > 5000:
2016-12-19 06:30:41 +00:00
raise ValidationError('too long')
2016-12-19 05:15:06 +00:00
class TicketForm(Form):
2016-12-19 06:30:41 +00:00
name = CharField(label='name',
help_text='your tilde.town username if you have one, otherwise just something to address you as'
)
email = EmailField(
help_text='only used to message you about this ticket and nothing else.',
label='e-mail',
)
issue_type = ChoiceField(
choices=ISSUE_TYPE_CHOICES,
label='type of issue',
2017-05-20 20:17:54 +00:00
help_text='the type of issue that best describes your problem.'
2016-12-19 06:30:41 +00:00
)
issue_text = CharField(
widget=Textarea,
label="what's up?",
2017-05-20 20:17:54 +00:00
help_text='describe your issue.',
2016-12-19 06:30:41 +00:00
validators=(validate_issue_text,),
)
captcha = CaptchaField()
def clean(self):
result = super().clean()
2016-12-19 23:22:06 +00:00
2016-12-19 06:30:41 +00:00
if self.errors:
raise ValidationError('oops, looks like there were some problems below.')
throttle_submission(result['email'])
2016-12-19 06:30:41 +00:00
return result