Put a form on the request to go live page

This commit:
- moves things around a bit on the request to go live page
- sticks a textbox in there

So when someone click the big green button, we will get a support ticket
that looks something like:
```
From Test User <test@user.gov.uk> on behalf of Test Service
(6ce466d0-fd6a-11e5-82f5-e0accb9d11a6)

---

We’ll send about 1000 text messages in the first month, and then 10,000
text messages per month after that. Usage of our service is about 50%
higher in March, at the end of the tax year.
```
This commit is contained in:
Chris Hill-Scott
2016-04-26 13:31:57 +01:00
parent 22fe164711
commit 45241d6232
7 changed files with 167 additions and 44 deletions

View File

@@ -1,10 +1,13 @@
import requests
from flask import (
render_template,
redirect,
request,
url_for,
session,
flash
flash,
abort,
current_app
)
from flask_login import (
@@ -16,7 +19,7 @@ from notifications_python_client.errors import HTTPError
from app import service_api_client
from app.main import main
from app.utils import user_has_permissions, email_safe
from app.main.forms import ConfirmPasswordForm, ServiceNameForm
from app.main.forms import ConfirmPasswordForm, ServiceNameForm, RequestToGoLiveForm
from app import user_api_client
from app import current_service
@@ -86,15 +89,45 @@ def service_name_change_confirm(service_id):
@login_required
@user_has_permissions('manage_settings', admin_override=True)
def service_request_to_go_live(service_id):
if request.method == 'GET':
return render_template(
'views/service-settings/request-to-go-live.html'
form = RequestToGoLiveForm()
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': 'Request to go live',
'message': "From {} <{}> on behalf of {} ({})\n\nUsage estimate\n---\n\n{}".format(
current_user.name,
current_user.email_address,
current_service['name'],
current_service['id'],
form.usage.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
)
elif request.method == 'POST':
flash('Thanks your request to go live is being processed', 'default')
# TODO implement whatever this action would do in the real world
if resp.status_code != 201:
current_app.logger.error(
"Deskpro create ticket request failed with {} '{}'".format(
resp.status_code,
resp.json())
)
abort(500, "Request to go live submission failed")
flash('Weve received your request to go live', 'default')
return redirect(url_for('.service_settings', service_id=service_id))
return render_template('views/service-settings/request-to-go-live.html', form=form)
@main.route("/services/<service_id>/service-settings/switch-live")
@login_required