__author__ = 'RemiZOffAlex'
__copyright__ = '(c) RemiZOffAlex'
__email__ = 'remizoffalex@mail.ru'

from myapp import app
from flask import render_template, Response


@app.route('/')
def index():
    pagedata = {}
    pagedata['title'] = app.config['TITLE']
    pagedata['info'] = 'Привет мир!'
    body = render_template('index.html', pagedata=pagedata)
    return body


@app.route("/robots.txt")
def robots_txt():
    body = render_template("robots.txt")
    return Response(body, mimetype='text/plain')


# noinspection PyUnusedLocal
@app.errorhandler(404)
def error_missing(exception):
    pagedata = {}
    error_message = "Не судьба..."
    return render_template(
        "error.html",
        error_code=404,
        error_message=error_message,
        pagedata=pagedata
    ), 404


# noinspection PyUnusedLocal
@app.errorhandler(403)
def error_unauthorized(exception):
    pagedata = {}
    error_message = "У вас нет прав"
    return render_template(
        "error.html",
        error_code=403,
        error_message=error_message,
        pagedata=pagedata
    ), 403


# noinspection PyUnusedLocal
@app.errorhandler(500)
def error_crash(exception):
    pagedata = {}
    error_message = "Вот незадача..."
    return render_template(
        "error.html",
        error_code=500,
        error_message=error_message,
        pagedata=pagedata
    ), 500
