2016-01-28 17:20:34 +00:00
|
|
|
from flask import (abort, render_template, session)
|
2016-01-06 16:40:38 +00:00
|
|
|
from flask_login import login_required
|
2015-12-18 10:26:56 +00:00
|
|
|
from app.main import main
|
2016-01-15 16:10:24 +00:00
|
|
|
from app.main.dao.services_dao import get_service_by_id
|
2016-02-02 09:38:58 +00:00
|
|
|
from app.main.dao import templates_dao
|
2016-02-11 15:27:08 +00:00
|
|
|
from notifications_python_client.errors import HTTPError
|
2016-02-03 14:43:16 +00:00
|
|
|
from app import job_api_client
|
2015-12-18 10:26:56 +00:00
|
|
|
|
2016-02-19 16:38:04 +00:00
|
|
|
from app.utils import user_has_permissions
|
|
|
|
|
|
2015-12-18 10:26:56 +00:00
|
|
|
|
2016-02-02 14:24:08 +00:00
|
|
|
@main.route("/services/<service_id>/dashboard")
|
2016-01-06 16:40:38 +00:00
|
|
|
@login_required
|
2016-01-15 17:46:09 +00:00
|
|
|
def service_dashboard(service_id):
|
2016-02-02 09:38:58 +00:00
|
|
|
try:
|
|
|
|
|
templates = templates_dao.get_service_templates(service_id)['data']
|
2016-02-03 14:43:16 +00:00
|
|
|
jobs = job_api_client.get_job(service_id)['data']
|
2016-02-02 09:38:58 +00:00
|
|
|
except HTTPError as e:
|
|
|
|
|
if e.status_code == 404:
|
|
|
|
|
abort(404)
|
|
|
|
|
else:
|
|
|
|
|
raise e
|
2016-01-15 16:10:24 +00:00
|
|
|
try:
|
|
|
|
|
service = get_service_by_id(service_id)
|
2016-01-28 17:20:34 +00:00
|
|
|
session['service_name'] = service['data']['name']
|
2016-02-29 14:57:07 +00:00
|
|
|
session['service_id'] = service['data']['id']
|
2016-01-15 16:10:24 +00:00
|
|
|
except HTTPError as e:
|
|
|
|
|
if e.status_code == 404:
|
|
|
|
|
abort(404)
|
|
|
|
|
else:
|
|
|
|
|
raise e
|
2015-12-18 10:26:56 +00:00
|
|
|
return render_template(
|
2016-01-15 17:46:09 +00:00
|
|
|
'views/service_dashboard.html',
|
2016-02-04 17:13:57 +00:00
|
|
|
jobs=list(reversed(jobs))[:5],
|
|
|
|
|
more_jobs_to_show=(len(jobs) > 5),
|
2016-02-04 12:20:24 +00:00
|
|
|
free_text_messages_remaining='250,000',
|
2016-01-13 12:10:29 +00:00
|
|
|
spent_this_month='0.00',
|
2016-02-02 13:38:39 +00:00
|
|
|
template_count=len(templates),
|
2016-02-02 14:24:08 +00:00
|
|
|
service_id=str(service_id))
|