Skip to content

Commit e7631a3

Browse files
authored
Support: create a form to render it nicely in ext-theme (#11193)
* Support: create a form to render it nicely in ext-theme Use a Django form and crispy filter to render the form on the support page. Also moves the logic from the template to the form itself. * Use a `FileField` to upload an attachment * Disable field correctly * Remove the form rendered on ext-theme We moved the template over there. * Typo * Revert to origin/main
1 parent 7880e85 commit e7631a3

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

readthedocs/core/forms.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import structlog
44
from django import forms
5+
from django.conf import settings
56
from django.contrib.auth.models import User
67
from django.core.exceptions import NON_FIELD_ERRORS
78
from django.forms.fields import CharField
@@ -183,3 +184,49 @@ def valid_value(self, value):
183184
if ":" not in value:
184185
return False
185186
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+
)

readthedocs/core/views/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from django.urls import reverse
1313
from django.views.generic import TemplateView, View
1414

15+
from readthedocs.core.forms import SupportForm
1516
from readthedocs.core.mixins import CDNCacheControlMixin, PrivateViewMixin
1617

1718
log = structlog.get_logger(__name__)
@@ -69,12 +70,17 @@ def get(self, request, *args, **kwargs):
6970

7071

7172
class SupportView(PrivateViewMixin, TemplateView):
73+
form_class = SupportForm
7274
template_name = "support/index.html"
7375

7476
def get_context_data(self, **kwargs):
7577
"""Pass along endpoint for support form."""
7678
context = super().get_context_data(**kwargs)
7779
context["SUPPORT_FORM_ENDPOINT"] = settings.SUPPORT_FORM_ENDPOINT
80+
81+
if settings.RTD_EXT_THEME_ENABLED:
82+
context["form"] = self.form_class(self.request.user)
83+
7884
return context
7985

8086

0 commit comments

Comments
 (0)