1414from wtforms import RadioField
1515from wtforms import StringField
1616from wtforms import TextAreaField
17+ from wtforms .validators import InputRequired
1718from wtforms .validators import Length
1819from wtforms .validators import Optional
19- from wtforms .validators import Required
2020
2121AUTH_REPORT = 'github-auth-report'
2222PROXY_REPORT = 'github-proxy-report'
2323SCHEMES = ('http://' , 'https://' )
2424
25- owner_choices = [(u'True' , u'Yes' ), (u'False' , u'No' )]
26- problem_choices = [(u'browser_bug' , u'Looks like the browser has a bug' ),
27- (u'site_bug' , u'Looks like the website has a bug.' ),
28- (u'unknown_bug' , u'Don\' t know but something\' s wrong.' )]
25+ problem_choices = [
26+ (u'detection_bug' , u'Desktop site instead of mobile site' ),
27+ (u'mobile_site_bug' , u'Mobile site is not usable' ),
28+ (u'video_bug' , u'Video doesn\' t play' ),
29+ (u'layout_bug' , u'Layout is messed up' ),
30+ (u'text_bug' , u'Text is not visible' ),
31+ (u'unknown_bug' , u'Somethign else - I\' ll add details below' )
32+ ]
2933url_message = u'A URL is required.'
30- summary_message = u'Please give a summary .'
34+ radio_message = u'Problem type required .'
3135username_message = u'A valid username must be {0} characters long' .format (
3236 random .randrange (0 , 99 ))
3337
4145
4246class IssueForm (Form ):
4347 '''Define form fields and validation for our bug reporting form.'''
44- url = StringField (u'Site URL*' , [Required (message = url_message )])
48+ url = StringField (u'Site URL*' , [InputRequired (message = url_message )])
4549 browser = StringField (u'Browser / Version' , [Optional ()])
4650 os = StringField (u'Operating System' , [Optional ()])
47- summary = StringField (u'Problem in 5 words*' ,
48- [Required (message = summary_message )])
4951 username = StringField (u'Username' ,
5052 [Length (max = 0 , message = username_message )])
51- description = TextAreaField (u'How can we replicate this? ' , [Optional ()],
53+ description = TextAreaField (u'Give more details ' , [Optional ()],
5254 default = desc_default )
53- site_owner = RadioField (u'Is this your website?' , [Optional ()],
54- choices = owner_choices )
55- problem_category = RadioField (u'What seems to be the trouble?' ,
56- [Optional ()], choices = problem_choices )
55+ problem_category = RadioField (u'What seems to be the trouble?*' ,
56+ [InputRequired (message = radio_message )],
57+ choices = problem_choices )
5758
5859
5960def get_problem (category ):
@@ -65,14 +66,12 @@ def get_problem(category):
6566 return u'Unknown'
6667
6768
68- def get_owner (is_site_owner ):
69- '''Return human-readable language (Y/N) for site owner form value.'''
70- if is_site_owner == 'True' :
71- return u'Yes'
72- elif is_site_owner == 'False' :
73- return u'No'
69+ def get_problem_summary (category ):
70+ '''Allows us to special case the "Other" radio choice summary.'''
71+ if category == 'unknown_bug' :
72+ return u'see bug description'
7473 else :
75- return u'Unknown'
74+ return get_problem ( category ). lower ()
7675
7776
7877def wrap_label (label ):
@@ -127,7 +126,6 @@ def build_formdata(form_object):
127126 URL -> part of body
128127 Description -> part of body
129128 Category -> labels
130- Owner -> labels
131129
132130 We'll try to parse the Browser and come up with a browser label, as well
133131 as labels like mobile, desktop, tablet.
@@ -150,27 +148,28 @@ def build_formdata(form_object):
150148 normalized_url = normalize_url (url )
151149 # Domain extraction
152150 domain = domain_name (normalized_url )
151+ problem_summary = get_problem_summary (form_object .get ('problem_category' ))
153152 if domain :
154- summary = '{0} - {1}' .format (domain , form_object . get ( 'summary' ) )
153+ summary = '{0} - {1}' .format (domain , problem_summary )
155154 else :
156- summary = '{0}' .format (form_object . get ( 'summary' ) )
155+ summary = '{0} - {1} ' .format (normalized_url , problem_summary )
157156 # Preparing the body
158- body = u'''{0}{1}
159- **URL**: {2}
160- **Browser / Version**: {3}
161- **Operating System**: {4}
162- **Problem type**: {5}
163- **Site owner**: {6}
157+ body = u'''{browser_label}{ua_label}
158+ **URL**: {url}
159+ **Browser / Version**: {browser}
160+ **Operating System**: {os}
161+ **Problem type**: {problem_type}
164162
165163**Steps to Reproduce**
166- {7}''' .format (get_labels (form_object .get ('browser' )),
167- wrap_label (('ua_header' , form_object .get ('ua_header' ))),
168- form_object .get ('url' ),
169- form_object .get ('browser' ),
170- form_object .get ('os' ),
171- get_problem (form_object .get ('problem_category' )),
172- get_owner (form_object .get ('site_owner' )),
173- form_object .get ('description' ))
164+ {description}''' .format (
165+ browser_label = get_labels (form_object .get ('browser' )),
166+ ua_label = wrap_label (('ua_header' , form_object .get ('ua_header' ))),
167+ url = form_object .get ('url' ),
168+ browser = form_object .get ('browser' ),
169+ os = form_object .get ('os' ),
170+ problem_type = get_problem (form_object .get ('problem_category' )),
171+ description = form_object .get ('description' )
172+ )
174173 result = {}
175174 result ['title' ] = summary
176175 result ['body' ] = body
0 commit comments