mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 07:46:23 -04:00
Page for adding a new service
This page is exactly the same as the page for adding your first service, save the heading text. So all this commit does is: - set up two routes (`/add-service`, `/add-service/first`) for each of the two journeys and change the existing journeys to use the `/add-service/first` route - add logic to show different heading text depending on the journey - add a link to the new (`/add-service`) route in the service chooser dropdown
This commit is contained in:
@@ -161,8 +161,12 @@ class AddServiceForm(Form):
|
||||
self.service_names = service_names
|
||||
super(AddServiceForm, self).__init__(*args, **kwargs)
|
||||
|
||||
service_name = StringField(validators=[
|
||||
DataRequired(message='Service name can not be empty')])
|
||||
service_name = StringField(
|
||||
'Service name',
|
||||
validators=[
|
||||
DataRequired(message='Service name can not be empty')
|
||||
]
|
||||
)
|
||||
|
||||
def validate_service_name(self, a):
|
||||
if self.service_name.data in self.service_names:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import render_template, jsonify, redirect, session, url_for
|
||||
from flask import request, render_template, jsonify, redirect, session, url_for, abort
|
||||
from flask_login import login_required
|
||||
from app.main import main
|
||||
from app.main.dao import services_dao, users_dao
|
||||
@@ -6,13 +6,25 @@ from app.main.forms import AddServiceForm
|
||||
|
||||
|
||||
@main.route("/add-service", methods=['GET', 'POST'])
|
||||
@main.route("/add-service/<string:first>", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def add_service():
|
||||
def add_service(first=False):
|
||||
if first:
|
||||
if first == 'first':
|
||||
heading = 'Set up notifications for your service'
|
||||
else:
|
||||
abort(404)
|
||||
else:
|
||||
heading = 'Add a new service'
|
||||
|
||||
form = AddServiceForm(services_dao.find_all_service_names())
|
||||
if form.validate_on_submit():
|
||||
|
||||
user = users_dao.get_user_by_id(session['user_id'])
|
||||
services_dao.insert_new_service(form.service_name.data, user)
|
||||
return redirect(url_for('.dashboard', service_id=123))
|
||||
else:
|
||||
return render_template('views/add-service.html', form=form)
|
||||
return render_template(
|
||||
'views/add-service.html',
|
||||
form=form,
|
||||
heading=heading
|
||||
)
|
||||
|
||||
@@ -20,5 +20,5 @@ def verify():
|
||||
verify_codes_dao.use_code_for_user_and_type(user_id=user.id, code_type='sms')
|
||||
users_dao.activate_user(user.id)
|
||||
login_user(user)
|
||||
return redirect(url_for('.add_service'))
|
||||
return redirect(url_for('.add_service', first='first'))
|
||||
return render_template('views/verify.html', form=form)
|
||||
|
||||
Reference in New Issue
Block a user