# 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
        print("error" + str(error))
        raise


@blueprint.route('/gates/new')
@blueprint.route('/gates/new/')
def new_gate():
    return render_template("new_gate_overlay.html")


@blueprint.route('/holidays/edit')
@blueprint.route('/holidays/edit/')
def edit_holidays():
    holidays = list()
    for holiday in blueprint.mongo.get_future_holidays():
        holidays.append({
            'date': util.from_iso_date_string(holiday["date"]),
            'reason': holiday["reason"],
            'is_develop': is_environment("develop", holiday),
            'is_live': is_environment("live", holiday)
        })
    return render_template("edit_holidays_overlay.html",
                           holidays=holidays)


def is_environment(environment, holiday):
    return ("environments" in holiday) and (environment in holiday["environments"])


def error_page(error):

# 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

        print("error" + str(error))
        raise


@blueprint.route('/gates/new')
@blueprint.route('/gates/new/')
def new_gate():
    return render_template("new_gate_overlay.html")


@blueprint.route('/holidays/edit')
@blueprint.route('/holidays/edit/')
def edit_holidays():
    holidays = list()
    for holiday in blueprint.mongo.get_future_holidays():
        holidays.append({
            'date': util.from_iso_date_string(holiday["date"]),
            'reason': holiday["reason"],
            'is_develop': is_environment("develop", holiday),
            'is_live': is_environment("live", holiday)
        })
    return render_template("edit_holidays_overlay.html",
                           holidays=holidays)


def is_environment(environment, holiday):
    return ("environments" in holiday) and (environment in holiday["environments"])


def error_page(error):

    return view_util.render("error.html",