2016-01-28 17:20:34 +00:00
|
|
|
from flask import (render_template, redirect, url_for, session)
|
2016-01-22 16:46:59 +00:00
|
|
|
from flask_login import login_required, current_user
|
2016-01-13 14:43:21 +00:00
|
|
|
from app.main import main
|
2016-03-29 22:50:40 +01:00
|
|
|
from app import service_api_client
|
|
|
|
|
from app.notify_client.api_client import ServicesBrowsableItem
|
2016-01-13 14:43:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@main.route("/services")
|
|
|
|
|
@login_required
|
2016-01-14 11:12:03 +00:00
|
|
|
def choose_service():
|
2016-01-18 11:15:14 +00:00
|
|
|
return render_template(
|
|
|
|
|
'views/choose-service.html',
|
2016-03-30 11:30:18 +01:00
|
|
|
services=[ServicesBrowsableItem(x) for x in
|
|
|
|
|
service_api_client.get_services({'user_id': current_user.id})['data']]
|
2016-03-29 10:39:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@main.route("/services-or-dashboard")
|
2016-03-29 22:50:40 +01:00
|
|
|
@login_required
|
2016-03-29 10:39:01 +01:00
|
|
|
def show_all_services_or_dashboard():
|
2016-03-30 11:30:18 +01:00
|
|
|
services = service_api_client.get_services({'user_id': current_user.id})['data']
|
2016-03-29 10:39:01 +01:00
|
|
|
|
2016-03-29 22:50:40 +01:00
|
|
|
if 1 == len(services):
|
|
|
|
|
return redirect(url_for('.service_dashboard', service_id=services[0]['id']))
|
|
|
|
|
else:
|
2016-04-04 16:53:52 +01:00
|
|
|
service_id = session.get('service_id', None)
|
|
|
|
|
if any([service_id == x['id'] for x in services]):
|
|
|
|
|
return redirect(url_for('.service_dashboard', service_id=service_id))
|
2016-03-29 22:50:40 +01:00
|
|
|
return redirect(url_for('.choose_service'))
|