# Path: src/config.py
# UPLOAD_CHUNK_LENGTH = 8 * _1MB
# 
# UPLOAD_UNSAVORY_EXTS = ['bat', 'cmd', 'exe', 'iso', 'php', 'vbs']
# 
# UPLOADED_FILES_DEST = '/tmp'
# 
# Path: src/forms.py
# class UserForm(ModelForm):
#     class Meta:
#         model = Users
#         exclude = common_exclusions
#         #~ only = tuple('''
#             #~ name email timezone desc
#         #~ '''.split())
#         only = tuple('name email timezone desc'.split())
# 
# Path: src/logcfg.py
# DEBUG_TEMPL = '  %(levelname)-7.7s %(funcName)s: %(message)s'
# PROD_TEMPL  = '%(asctime)s %(levelname)-7.7s %(funcName)s: %(message)s'
# DEBUG = logging.DEBUG
# class ColorFmtr(Formatter):
#     def __init__(self, *args, **kwargs):
#     def format(self, record):
# def makefunc(level):
#         def tb_func(msg, *args, **kwargs):
#     def thefunc(msg, *args, **kwargs):
# 
# Path: src/main.py
# def on_shutdown():


from os.path import join, splitext
from http_status import name as http_status_text
from http_status import description as http_status_description
from flask import (
    #~ abort,
    flash,      # flash categories: success, (blank) info, warning, error
    #~ g,
    jsonify,
    redirect,
    render_template as render,
    request,
    url_for,
)
from flask_login import current_user
from sqlalchemy.exc import SQLAlchemyError
from werkzeug.utils import secure_filename
from .config import (UPLOAD_CHUNK_LENGTH, UPLOAD_UNSAVORY_EXTS,
                     UPLOADED_FILES_DEST)
from .forms import UserForm
from .logcfg import log
from .main import app, db
from . import utils
def routes():
    rules = list(app.url_map.iter_rules())
    rules.sort(key=lambda r: r.rule)

    return render('routes.html', title='Routes configured', routes=rules)


@app.route('/status/<int:code>', methods=('DELETE', 'GET', 'HEAD', 'OPTIONS',
                                          'POST', 'PUT'))
def status(code):
    ''' For client debugging purposes. '''
    title = http_status_text.get(code, 'Unknown')
    desc  = http_status_description.get(code, 'Unknown')
    category = utils.get_status_category(code)

    # if this was an ajax request, return json instead of html
    if request.accept_mimetypes.best == 'application/json':
        log.debug('client prefers json, skipping page render.')
        return jsonify(status=title, category=category, code=code,
                       desc=desc)
    else:
        return render('status.html', category=category, code=code,
                                     title=title, desc=desc), code


@app.route('/profile', methods=('GET', 'POST'))
def show_profile():
    # How to query models
    #~ user = Users.query.filter_by(id=uid).first_or_404()
    user = current_user

# Path: src/config.py
# UPLOAD_CHUNK_LENGTH = 8 * _1MB
# 
# UPLOAD_UNSAVORY_EXTS = ['bat', 'cmd', 'exe', 'iso', 'php', 'vbs']
# 
# UPLOADED_FILES_DEST = '/tmp'
# 
# Path: src/forms.py
# class UserForm(ModelForm):
#     class Meta:
#         model = Users
#         exclude = common_exclusions
#         #~ only = tuple('''
#             #~ name email timezone desc
#         #~ '''.split())
#         only = tuple('name email timezone desc'.split())
# 
# Path: src/logcfg.py
# DEBUG_TEMPL = '  %(levelname)-7.7s %(funcName)s: %(message)s'
# PROD_TEMPL  = '%(asctime)s %(levelname)-7.7s %(funcName)s: %(message)s'
# DEBUG = logging.DEBUG
# class ColorFmtr(Formatter):
#     def __init__(self, *args, **kwargs):
#     def format(self, record):
# def makefunc(level):
#         def tb_func(msg, *args, **kwargs):
#     def thefunc(msg, *args, **kwargs):
# 
# Path: src/main.py
# def on_shutdown():


# Path: src/views.py
from os.path import join, splitext
from http_status import name as http_status_text
from http_status import description as http_status_description
from flask import (
    #~ abort,
    flash,      # flash categories: success, (blank) info, warning, error
    #~ g,
    jsonify,
    redirect,
    render_template as render,
    request,
    url_for,
)
from flask_login import current_user
from sqlalchemy.exc import SQLAlchemyError
from werkzeug.utils import secure_filename
from .config import (UPLOAD_CHUNK_LENGTH, UPLOAD_UNSAVORY_EXTS,
                     UPLOADED_FILES_DEST)
from .forms import UserForm
from .logcfg import log
from .main import app, db
from . import utils

def routes():
    rules = list(app.url_map.iter_rules())
    rules.sort(key=lambda r: r.rule)

    return render('routes.html', title='Routes configured', routes=rules)


@app.route('/status/<int:code>', methods=('DELETE', 'GET', 'HEAD', 'OPTIONS',
                                          'POST', 'PUT'))
def status(code):
    ''' For client debugging purposes. '''
    title = http_status_text.get(code, 'Unknown')
    desc  = http_status_description.get(code, 'Unknown')
    category = utils.get_status_category(code)

    # if this was an ajax request, return json instead of html
    if request.accept_mimetypes.best == 'application/json':
        log.debug('client prefers json, skipping page render.')
        return jsonify(status=title, category=category, code=code,
                       desc=desc)
    else:
        return render('status.html', category=category, code=code,
                                     title=title, desc=desc), code


@app.route('/profile', methods=('GET', 'POST'))
def show_profile():
    # How to query models
    #~ user = Users.query.filter_by(id=uid).first_or_404()
    user = current_user

    form = UserForm(obj=user)