mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Move feedback endpoints into own file
Doesn’t make sense to shove more stuff into index.py
This commit is contained in:
@@ -24,5 +24,6 @@ from app.main.views import (
|
||||
manage_users,
|
||||
invites,
|
||||
all_services,
|
||||
tour
|
||||
tour,
|
||||
feedback
|
||||
)
|
||||
|
||||
42
app/main/views/feedback.py
Normal file
42
app/main/views/feedback.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import markdown
|
||||
import requests
|
||||
from flask import render_template, url_for, redirect, flash, current_app, abort
|
||||
from app.main import main
|
||||
from flask_login import login_required
|
||||
from app.main.forms import Feedback
|
||||
|
||||
from flask.ext.login import current_user
|
||||
|
||||
|
||||
@main.route('/feedback', methods=['GET', 'POST'])
|
||||
def feedback():
|
||||
form = Feedback()
|
||||
if form.validate_on_submit():
|
||||
data = {
|
||||
'person_email': current_app.config.get('DESKPRO_PERSON_EMAIL'),
|
||||
'department_id': current_app.config.get('DESKPRO_TEAM_ID'),
|
||||
'subject': 'Notify feedback',
|
||||
'message': '{}\n{}\n{}'.format(
|
||||
form.name.data,
|
||||
form.email_address.data,
|
||||
form.feedback.data)
|
||||
}
|
||||
headers = {
|
||||
"X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'),
|
||||
'Content-Type': "application/x-www-form-urlencoded"
|
||||
}
|
||||
resp = requests.post(
|
||||
current_app.config.get('DESKPRO_API_HOST') + '/api/tickets',
|
||||
data=data,
|
||||
headers=headers)
|
||||
if resp.status_code != 201:
|
||||
current_app.logger.error(
|
||||
"Deskpro create ticket request failed with {} '{}'".format(
|
||||
resp.status_code,
|
||||
resp.json())
|
||||
)
|
||||
abort(500, "Feedback submission failed")
|
||||
flash("Your feedback has been submitted")
|
||||
return redirect(url_for('.feedback'))
|
||||
|
||||
return render_template('views/feedback.html', form=form)
|
||||
@@ -1,11 +1,8 @@
|
||||
import markdown
|
||||
import os
|
||||
import requests
|
||||
import json
|
||||
from flask import (render_template, url_for, redirect, Markup, flash, current_app, abort)
|
||||
from flask import (render_template, url_for, redirect, Markup, current_app, abort)
|
||||
from app.main import main
|
||||
from flask_login import login_required
|
||||
from app.main.forms import Feedback
|
||||
|
||||
from flask.ext.login import current_user
|
||||
from mdx_gfm import GithubFlavoredMarkdownExtension
|
||||
@@ -44,40 +41,6 @@ def terms():
|
||||
return render_template('views/terms-of-use.html')
|
||||
|
||||
|
||||
@main.route('/feedback', methods=['GET', 'POST'])
|
||||
def feedback():
|
||||
form = Feedback()
|
||||
if form.validate_on_submit():
|
||||
data = {
|
||||
'person_email': current_app.config.get('DESKPRO_PERSON_EMAIL'),
|
||||
'department_id': current_app.config.get('DESKPRO_TEAM_ID'),
|
||||
'subject': 'Notify feedback',
|
||||
'message': '{}\n{}\n{}'.format(
|
||||
form.name.data,
|
||||
form.email_address.data,
|
||||
form.feedback.data)
|
||||
}
|
||||
headers = {
|
||||
"X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'),
|
||||
'Content-Type': "application/x-www-form-urlencoded"
|
||||
}
|
||||
resp = requests.post(
|
||||
current_app.config.get('DESKPRO_API_HOST') + '/api/tickets',
|
||||
data=data,
|
||||
headers=headers)
|
||||
if resp.status_code != 201:
|
||||
current_app.logger.error(
|
||||
"Deskpro create ticket request failed with {} '{}'".format(
|
||||
resp.status_code,
|
||||
resp.json())
|
||||
)
|
||||
abort(500, "Feedback submission failed")
|
||||
flash("Your feedback has been submitted")
|
||||
return redirect(url_for('.feedback'))
|
||||
|
||||
return render_template('views/feedback.html', form=form)
|
||||
|
||||
|
||||
@main.route('/documentation')
|
||||
def documentation():
|
||||
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
Reference in New Issue
Block a user