Feedback page working with all tests passing.

Updated to include team id.

Give Feedback -> Give feedback
This commit is contained in:
Nicholas Staples
2016-04-19 13:51:16 +01:00
parent ddec619913
commit da536bbd2e
8 changed files with 169 additions and 4 deletions

View File

@@ -306,3 +306,10 @@ class CreateKeyForm(Form):
def validate_key_name(self, key_name):
if key_name.data.lower() in self.existing_key_names:
raise ValidationError('A key with this name already exists')
class Feedback(Form):
name = StringField('Name')
email_address = StringField('Email address')
feedback = TextAreaField(u'', validators=[DataRequired(message="Cant be empty")])

View File

@@ -1,8 +1,11 @@
import markdown
import os
from flask import render_template, url_for, redirect, Markup
import requests
import json
from flask import (render_template, url_for, redirect, Markup, 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
from mdx_gfm import GithubFlavoredMarkdownExtension
@@ -41,6 +44,40 @@ 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'),
'agent_team_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__))

View File

@@ -78,7 +78,7 @@
<div class="column-one-third">
<h2>Contact</h2>
<ul>
<li><a href="https://docs.google.com/forms/d/1AL8U-xJX_HAFEiQiJszGQw0PcEaEUnYATSntEghNDGo/viewform">Support and feedback</a></li>
<li><a href="{{ url_for('main.feedback') }}">Support and feedback</a></li>
</ul>
</div>
<div class="column-one-third">

View File

@@ -0,0 +1,28 @@
{% extends "withoutnav_template.html" %}
{% from "components/textbox.html" import textbox %}
{% from "components/page-footer.html" import page_footer %}
{% block page_title %}
Feedback GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">
Give feedback
</h1>
<div class="grid-row">
<div class="column-two-thirds">
<p>What went wrong, if anything? What went well? How could we improve this service?</p>
<form method="post">
{{ textbox(form.feedback, width='1-1', hint='', rows=10) }}
<h3 class="heading-medium">Do you want a reply?</h3>
<p>Leave your details below if you'd like a response.</p>
{{ textbox(form.name, width='1-1') }}
{{ textbox(form.email_address, width='1-1') }}
{{ page_footer('Send') }}
</form>
</div>
</div>
{% endblock %}