|
2 | 2 |
|
3 | 3 | import structlog
|
4 | 4 | from django import forms
|
| 5 | +from django.conf import settings |
5 | 6 | from django.contrib.auth.models import User
|
6 | 7 | from django.core.exceptions import NON_FIELD_ERRORS
|
7 | 8 | from django.forms.fields import CharField
|
@@ -183,3 +184,49 @@ def valid_value(self, value):
|
183 | 184 | if ":" not in value:
|
184 | 185 | return False
|
185 | 186 | return True
|
| 187 | + |
| 188 | + |
| 189 | +class SupportForm(forms.Form): |
| 190 | + name = forms.CharField() |
| 191 | + email = forms.EmailField() |
| 192 | + explanation = forms.CharField( |
| 193 | + label=_("Explanation of the issue"), |
| 194 | + help_text=_("Please provide as much detail as possible."), |
| 195 | + widget=forms.Textarea, |
| 196 | + ) |
| 197 | + url = forms.URLField( |
| 198 | + help_text=_("Is there a specific page this happened?"), |
| 199 | + required=False, |
| 200 | + ) |
| 201 | + attachment = forms.FileField( |
| 202 | + label=_("Screenshot or additional file"), |
| 203 | + help_text=_("Anything else that would help us solve this issue?"), |
| 204 | + ) |
| 205 | + severity_level = forms.ChoiceField( |
| 206 | + choices=( |
| 207 | + ("low", _("Low")), |
| 208 | + ("medium", _("Medium")), |
| 209 | + ("high", _("High")), |
| 210 | + ), |
| 211 | + help_text=_("Please rate the severity of this event."), |
| 212 | + required=False, |
| 213 | + ) |
| 214 | + subject = forms.CharField(widget=forms.HiddenInput) |
| 215 | + |
| 216 | + def __init__(self, user): |
| 217 | + super().__init__() |
| 218 | + |
| 219 | + self.fields["name"].initial = user.get_full_name |
| 220 | + self.fields["email"].initial = user.email |
| 221 | + |
| 222 | + if settings.ALLOW_PRIVATE_REPOS: |
| 223 | + self.fields["subject"].initial = "Commercial Support Request" |
| 224 | + else: |
| 225 | + self.fields["subject"].initial = "Community Support Request" |
| 226 | + |
| 227 | + if not (user.gold.exists() or user.goldonce.exists()): |
| 228 | + self.fields["severity_level"].disabled = True |
| 229 | + self.fields["severity_level"].widget.attrs["readonly"] = True |
| 230 | + self.fields["severity_level"].help_text = _( |
| 231 | + "This option is only enabled for Gold users." |
| 232 | + ) |
0 commit comments