Files
notifications-admin/app/main/views/feedback.py
T

42 lines
1.6 KiB
Python
Raw Normal View History

2016-04-26 10:32:26 +01:00
import requests
from flask import render_template, url_for, redirect, flash, current_app, abort
from app.main import main
from app.main.forms import Feedback
@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_DEPT_ID'),
2016-05-20 15:58:20 +01:00
'agent_team_id': current_app.config.get('DESKPRO_ASSIGNED_AGENT_TEAM_ID'),
2016-04-26 10:32:26 +01:00
'subject': 'Notify feedback',
2016-04-26 16:29:23 +01:00
'message': 'Environment: {}\n\n{}\n{}\n{}'.format(
url_for('main.index', _external=True),
2016-04-26 10:32:26 +01:00
form.name.data,
form.email_address.data,
2016-04-26 16:29:23 +01:00
form.feedback.data
)
2016-04-26 10:32:26 +01:00
}
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")
2016-05-20 15:58:20 +01:00
flash("Thanks, weve received your feedback", 'default_with_tick')
2016-04-26 10:32:26 +01:00
return redirect(url_for('.feedback'))
2016-04-26 13:31:57 +01:00
return render_template('views/feedback.html', form=form)