Skip to content

Commit

Permalink
Issue webcompat#3380 - Makes WizardForm the default form
Browse files Browse the repository at this point in the history
So this is doing a couple of things.

- It removes the duplicate problem_choices list of 2 items tuples.
- it removes the IssueForm class
- it transfers the IssueForm attributes into FormWizard
- it reorders in some broad categories the fields  for the form
- it switches getform to FormWizard. (it was not the case!)
- it adjusts the tests
  • Loading branch information
karlcow committed Jul 14, 2020
1 parent fb8931c commit 5c078a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 54 deletions.
2 changes: 1 addition & 1 deletion tests/unit/test_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_get_form(self):
actual = form.get_form(form_data)
expected_browser = 'Firefox 48.0'
expected_os = 'Mac OS X 10.11'
self.assertIsInstance(actual, form.IssueForm)
self.assertIsInstance(actual, form.FormWizard)
self.assertEqual(actual.browser.data, expected_browser)
self.assertEqual(actual.os.data, expected_os)
self.assertEqual(actual.reported_with.data, 'desktop-reporter')
Expand Down
95 changes: 42 additions & 53 deletions webcompat/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@
}
]

problem_choices = [
('detection_bug', 'Desktop site instead of mobile site'),
('site_bug', 'Site is not usable'),
('layout_bug', 'Design is broken'),
('video_bug', 'Video or audio doesn\'t play'),
('unknown_bug', 'Something else')
]

problem_choices_wizard = [
('detection_bug', 'svg-problem-mobile-vs-desktop.svg',
'Desktop site instead of mobile site'),
Expand Down Expand Up @@ -191,57 +183,51 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)


class IssueForm(FlaskForm):
"""Define form fields and validation for our bug reporting form."""

url = StringField(url_label,
[InputRequired(message=url_message)])
browser = StringField('Is this information correct?', [Optional()])
os = StringField('Operating System', [Optional()])
# A dummy field to trap common bots. Users do not see that.
username = StringField('Username',
[Length(max=0, message=username_message)])
# Field for people who want to be contacted, but do not want to login
# regex for GitHub usernames
username_pattern = r"^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$"
# Field definition
class FormWizard(FlaskForm):
"""IssueForm to a multi step wizard form.
Attributes notes:
* contact:
Field for people who want to be contacted,
but do not want to login
github_username_pattern defines regex for GitHub usernames
* image:
We filter allowed type in uploads.py
We don't use the label programatically for this input[type=file],
any changes here need to be updated in form.html.
* username:
A dummy field to trap common bots. Users do not see that.
"""
steps = NEW_ISSUE_STEPS
github_username_pattern = r"^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$"
# Hidden Form Fields
console_logs_url = HiddenField()
description = HiddenField()
details = HiddenField()
extra_labels = HiddenField()
reported_with = HiddenField()
submit_type = HiddenField()
ua_header = HiddenField()
# Visible Form Fields
browser = StringField(
u'Browser',
[Optional()]
)
browser_test = RadioField(browser_test_label, [Optional()],
choices=tested_elsewhere)
contact = StringField(
contact_label,
[Regexp(username_pattern,
[Regexp(github_username_pattern,
flags=re.IGNORECASE,
message=contact_message)])
description = StringField(desc_label,
[InputRequired(message=desc_message)])

steps_reproduce = TextAreaField(textarea_label, [Optional()])
problem_category = RadioField([InputRequired(message=radio_message)],
choices=problem_choices)
browser_test = RadioField(browser_test_label, [Optional()],
choices=tested_elsewhere)
# we filter allowed type in uploads.py
# Note, we don't use the label programtically for this input[type=file],
# any changes here need to be updated in form.html.
image = FileField('Attach a screenshot image',
[Optional(),
FileAllowed(ImageUpload.ALLOWED_FORMATS,
image_message)])
details = HiddenField()
reported_with = HiddenField()
ua_header = HiddenField()
submit_type = HiddenField()
extra_labels = HiddenField()
console_logs_url = HiddenField()


class FormWizard(IssueForm):
"""Re-designed version of IssueForm to a multi step wizard form."""

steps = NEW_ISSUE_STEPS

browser = StringField(u'Browser', [Optional()])
os = StringField('Operating System', [Optional()])
description = HiddenField()

steps_reproduce = TextAreaField(textarea_label, [Optional()])
url = StringField(url_label, [InputRequired(message=url_message)])
# Steps Form Fields
problem_category = PrefixedRadioField(
[InputRequired(message=radio_message)],
choices=problem_choices_wizard
Expand Down Expand Up @@ -270,9 +256,12 @@ class FormWizard(IssueForm):
[InputRequired(message=radio_message)],
choices=browser_choices
)
# Bots Trap
username = StringField('Username',
[Length(max=0, message=username_message)])


def get_form(form_data, form=IssueForm):
def get_form(form_data, form=FormWizard):
"""Return an instance of flask_wtf.FlaskForm.
It receives a dictionary of everything which needs to be fed to the form.
Expand Down Expand Up @@ -346,7 +335,7 @@ def get_problem_summary(category):
else:
# Return the usual message in lowercase
# because it is not at the start of the summary.
return get_radio_button_label(category, problem_choices).lower()
return get_radio_button_label(category, problem_choices_wizard).lower()


def wrap_metadata(metadata):
Expand Down Expand Up @@ -521,7 +510,7 @@ def build_formdata(form_object):
'browser': normalize_metadata(form_object.get('browser')),
'os': normalize_metadata(form_object.get('os')),
'problem_type': get_radio_button_label(
form_object.get('problem_category'), problem_choices),
form_object.get('problem_category'), problem_choices_wizard),
'browser_test_type': get_radio_button_label(form_object.get(
'browser_test'), tested_elsewhere),
'description': form_object.get('description'),
Expand Down

0 comments on commit 5c078a6

Please sign in to comment.