# Path: app/util.py
# def data_from_request():
# def is_unblocked_by_rule(lt, h, d):
# def get_by_list(dic, keys):
# def to_iso_date_string(date):
# def from_iso_date_string(date):
# 
# Path: app/view_util.py
# def render(html, title, **kwargs):
# def get_url_query():
# def request_wants_json():
# 
# Path: app/gates.py
# def generate_info(config):
# def test_against_global_rules(rules, env, lt):
# def are_gates_open(config, env):
# def gate_is_closed(entry, config, env, ticket_id=None):
# def gate_is_manually_closed(entry, env):
# 
# Path: app/errors.py
# class ConnectionFailure(pymongo.errors.ConnectionFailure):
#     def __init__(self, message):
#         super(ConnectionFailure, self).__init__(message)
#         self.message = "Can not connect to mongodb. Please check configuration"
#         self.status_code = 500
# 
# Path: app/errors.py
# class OperationFailure(pymongo.errors.OperationFailure):
#     def __init__(self, message):
#         super(OperationFailure, self).__init__(message)
#         self.message = "Can not complete operation on database. This could be a authentication error"


from collections import OrderedDict
from delorean import Delorean
from delorean import parse
from flask import Blueprint, render_template
from app import util
from app import view_util
from app import gates
from app.errors import ConnectionFailure
from app.errors import OperationFailure
        today_holiday = blueprint.mongo.get_today_holiday()
        for group in blueprint.mongo.get_groups():
            env_list[group] = set()
            service_list[group] = dict()

            for service_name in blueprint.mongo.get_services_in_group(group):
                service = blueprint.mongo.get_gate(group, service_name)

                for env in service['environments']:
                    env_list[group].add(env)
                    if service['environments'][env]['state_timestamp']:
                        service['environments'][env]['state_age'] = (
                            now - (now - parse(service['environments'][env]['state_timestamp']))).humanize()
                    if service['environments'][env]['message_timestamp']:
                        service['environments'][env]['message_age'] = (
                            now - (now - parse(service['environments'][env]['message_timestamp']))).humanize()

                    service['environments'][env]['api_closed'] = gates.gate_is_closed(service, blueprint.config, env)

                    for t in service['environments'][env]["queue"]:
                        t["age"] = (now - (now - parse(t["updated"]))).humanize()

                    service_list[group][service_name] = service

            env_list[group] = sorted(env_list[group])

        return view_util.render("gates.html",
                                'Gates',
                                env_list=env_list,
                                gate_list=service_list,

# Path: app/util.py
# def data_from_request():
# def is_unblocked_by_rule(lt, h, d):
# def get_by_list(dic, keys):
# def to_iso_date_string(date):
# def from_iso_date_string(date):
# 
# Path: app/view_util.py
# def render(html, title, **kwargs):
# def get_url_query():
# def request_wants_json():
# 
# Path: app/gates.py
# def generate_info(config):
# def test_against_global_rules(rules, env, lt):
# def are_gates_open(config, env):
# def gate_is_closed(entry, config, env, ticket_id=None):
# def gate_is_manually_closed(entry, env):
# 
# Path: app/errors.py
# class ConnectionFailure(pymongo.errors.ConnectionFailure):
#     def __init__(self, message):
#         super(ConnectionFailure, self).__init__(message)
#         self.message = "Can not connect to mongodb. Please check configuration"
#         self.status_code = 500
# 
# Path: app/errors.py
# class OperationFailure(pymongo.errors.OperationFailure):
#     def __init__(self, message):
#         super(OperationFailure, self).__init__(message)
#         self.message = "Can not complete operation on database. This could be a authentication error"


# Path: app/views.py
from collections import OrderedDict
from delorean import Delorean
from delorean import parse
from flask import Blueprint, render_template
from app import util
from app import view_util
from app import gates
from app.errors import ConnectionFailure
from app.errors import OperationFailure

        today_holiday = blueprint.mongo.get_today_holiday()
        for group in blueprint.mongo.get_groups():
            env_list[group] = set()
            service_list[group] = dict()

            for service_name in blueprint.mongo.get_services_in_group(group):
                service = blueprint.mongo.get_gate(group, service_name)

                for env in service['environments']:
                    env_list[group].add(env)
                    if service['environments'][env]['state_timestamp']:
                        service['environments'][env]['state_age'] = (
                            now - (now - parse(service['environments'][env]['state_timestamp']))).humanize()
                    if service['environments'][env]['message_timestamp']:
                        service['environments'][env]['message_age'] = (
                            now - (now - parse(service['environments'][env]['message_timestamp']))).humanize()

                    service['environments'][env]['api_closed'] = gates.gate_is_closed(service, blueprint.config, env)

                    for t in service['environments'][env]["queue"]:
                        t["age"] = (now - (now - parse(t["updated"]))).humanize()

                    service_list[group][service_name] = service

            env_list[group] = sorted(env_list[group])

        return view_util.render("gates.html",
                                'Gates',
                                env_list=env_list,
                                gate_list=service_list,

                                info_list=gates.generate_info(blueprint.config),