def get_form(ua_header): """Return an instance of flask_wtf.FlaskForm with browser and os info.""" bug_form = IssueForm() # add browser and version to bug_form object data bug_form.browser.data = get_browser(ua_header) bug_form.os.data = get_os(ua_header) return bug_form
def index(): '''Main view where people come to report issues.''' bug_form = IssueForm(request.form) # add browser and version to bug_form object data ua_header = request.headers.get('User-Agent') bug_form.browser.data = get_browser(ua_header) bug_form.os.data = get_os(ua_header) browser_name = get_browser_name(ua_header) # GET means you want to file a report. if request.method == 'GET': if g.user: get_user_info() return render_template('index.html', form=bug_form, browser=browser_name) # Form submission. elif request.method == 'POST' and bug_form.validate(): # copy the form so we can add the full UA string to it. form = request.form.copy() form['ua_header'] = ua_header if form.get('submit-type') == AUTH_REPORT: if g.user: # If you're already authed, submit the bug. response = report_issue(form) return redirect(url_for('thanks', number=response.get('number'))) else: # Stash form data into session, go do GitHub auth session['form_data'] = form return redirect(url_for('login')) elif form.get('submit-type') == PROXY_REPORT: response = report_issue(form, proxy=True).json() return redirect(url_for('thanks', number=response.get('number'))) else: # Validation failed, re-render the form with the errors. return render_template('index.html', form=bug_form)
def index(): '''Main view where people come to report issues.''' bug_form = IssueForm(request.form) # add browser and version to bug_form object data ua_header = request.headers.get('User-Agent') bug_form.browser.data = get_browser(ua_header) bug_form.os.data = get_os(ua_header) browser_name = get_browser_name(ua_header) # GET means you want to file a report. if request.method == 'GET': if g.user: get_user_info() return render_template('index.html', form=bug_form, browser=browser_name) # Form submission. elif request.method == 'POST' and bug_form.validate(): # copy the form so we can add the full UA string to it. form = request.form.copy() form['ua_header'] = ua_header if form.get('submit-type') == AUTH_REPORT: if g.user: # If you're already authed, submit the bug. response = report_issue(form) return redirect( url_for('thanks', number=response.get('number'))) else: # Stash form data into session, go do GitHub auth session['form_data'] = form return redirect(url_for('login')) elif form.get('submit-type') == PROXY_REPORT: response = report_issue(form, proxy=True).json() return redirect(url_for('thanks', number=response.get('number'))) else: # Validation failed, re-render the form with the errors. return render_template('index.html', form=bug_form)
def index(): '''Main view where people come to report issues.''' bug_form = IssueForm() # add browser and version to bug_form object data ua_header = request.headers.get('User-Agent') bug_form.browser.data = get_browser(ua_header) bug_form.os.data = get_os(ua_header) browser_name = get_browser_name(ua_header) # GET means you want to file a report. if request.method == 'GET': if g.user: get_user_info() return render_template('index.html', form=bug_form, browser=browser_name) # Validate, then create issue. elif bug_form.validate_on_submit(): return create_issue() else: # Validation failed, re-render the form with the errors. return render_template('index.html', form=bug_form)