From 5c078a6b608633620f2c0584c76eabb0d7b5dcfb Mon Sep 17 00:00:00 2001 From: Karl Dubost Date: Tue, 14 Jul 2020 11:37:29 +0900 Subject: [PATCH] Issue #3380 - Makes WizardForm the default form 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 --- tests/unit/test_form.py | 2 +- webcompat/form.py | 95 ++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 54 deletions(-) diff --git a/tests/unit/test_form.py b/tests/unit/test_form.py index bee3767c3..3e454f96e 100644 --- a/tests/unit/test_form.py +++ b/tests/unit/test_form.py @@ -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') diff --git a/webcompat/form.py b/webcompat/form.py index 0806b8d0e..0c9b0bf5c 100644 --- a/webcompat/form.py +++ b/webcompat/form.py @@ -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'), @@ -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 @@ -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. @@ -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): @@ -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'),