Skip to content

Commit

Permalink
Issue #317. Add /issues/new route for issue creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Taylor committed Oct 15, 2015
1 parent f6d348d commit 2c85d87
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion webcompat/templates/form.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="wc-Loader js-loader"></div>
<div id="new-report" class="form {% if form.errors %}form-opened{% else %}form-closed{% endif %}">
<div class="wc-content wc-content--body">
<form method="post" enctype="multipart/form-data" class="js-ReportForm wc-ReportForm wc-Form" action="/" novalidate>
<form method="post" enctype="multipart/form-data" class="js-ReportForm wc-ReportForm wc-Form" action="/issues/new" novalidate>
<div class="r-Grid r-Grid--withGutter">
<div class="r-Grid-cell r-all--1of2 r-maxM--2of2">
<fieldset class="wc-Form-group {% if form.problem_category.errors %}wc-Form-error{% endif %}">
Expand Down
61 changes: 33 additions & 28 deletions webcompat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,35 +135,10 @@ def index():
get_user_info()
return render_template('index.html', form=bug_form,
browser=browser_name)
# Form submission.
# Validate, then create issue.
elif bug_form.validate_on_submit():
# copy the form so we can add the full UA string to it.
form = request.form.copy()
# see https://github.com/webcompat/webcompat.com/issues/688
spamlist = ['facebook', 'fb.com']
for spam in spamlist:
if spam in form.get('url'):
msg = (u'Anonymous reporting for Facebook.com is temporarily '
'disabled. Please see https://github.com/webcompat/we'
'bcompat.com/issues/688 for more details.')
flash(msg, 'notimeout')
return redirect(url_for('index'))
form['ua_header'] = ua_header
# Do we have an image ready to be uploaded?
image = request.files['image']
if image:
form['image_upload'] = json.loads(upload()[0])
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')))
return create_issue()

else:
# Validation failed, re-render the form with the errors.
return render_template('index.html', form=bug_form)
Expand All @@ -176,6 +151,36 @@ def show_issues():
get_user_info()
return render_template('issue-list.html')

@app.route('/issues/new', methods=['POST'])
def create_issue():
# copy the form so we can add the full UA string to it.
form = request.form.copy()
# see https://github.com/webcompat/webcompat.com/issues/688
spamlist = ['facebook', 'fb.com']
for spam in spamlist:
if spam in form.get('url'):
msg = (u'Anonymous reporting for Facebook.com is temporarily '
'disabled. Please see https://github.com/webcompat/we'
'bcompat.com/issues/688 for more details.')
flash(msg, 'notimeout')
return redirect(url_for('index'))
form['ua_header'] = request.headers.get('User-Agent')
# Do we have an image ready to be uploaded?
image = request.files['image']
if image:
form['image_upload'] = json.loads(upload()[0])
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')))


@app.route('/issues/<int:number>')
def show_issue(number):
Expand Down

0 comments on commit 2c85d87

Please sign in to comment.