# Path: automlk/context.py
# def get_uploads_folder():
#     """
#     folder to store file uploads
# 
#     :return: folder name
#     """
#     folder = get_data_folder() + '/uploads'
#     if not os.path.exists(folder):
#         os.makedirs(folder)
#     return folder


from app import app
from flask import render_template, send_file, redirect, request, abort, flash, send_from_directory, jsonify
from .form import *
from automlk.textset import *
from automlk.context import get_uploads_folder
@app.route('/textset_list', methods=['GET', 'POST'])
def text_list():
    # list of text sets
    textset_list = get_textset_list()
    del_form = DeleteTextsetForm()
    reset_form = ResetTextsetForm()
    return render_template('text_list.html', textset_list=textset_list, del_form=del_form, reset_form=reset_form,
                           refresher=int(time.time()), config=get_config())


@app.route('/textset/<string:textset_id>', methods=['GET', 'POST'])
def text_set(textset_id):
    # detail of a text set
    textset = get_textset(textset_id)
    return render_template('text.html', textset=textset, refresher=int(time.time()), config=get_config())


@app.route('/create_text', methods=['GET', 'POST'])
def create_text():
    # form to create a new textset
    form = CreateTextsetForm()
    if request.method == 'POST':
        if form.validate():
            # try:
            if form.mode_file.data == 'upload':
                # check and upload a file
                filename = form.file_text.data.filename
                if filename == '' or filename.split('.')[-1].lower() != 'txt':
                    flash('file %s type must be txt' % filename)
                else:

# Path: automlk/context.py
# def get_uploads_folder():
#     """
#     folder to store file uploads
# 
#     :return: folder name
#     """
#     folder = get_data_folder() + '/uploads'
#     if not os.path.exists(folder):
#         os.makedirs(folder)
#     return folder


# Path: web/app/views_textset.py
from app import app
from flask import render_template, send_file, redirect, request, abort, flash, send_from_directory, jsonify
from .form import *
from automlk.textset import *
from automlk.context import get_uploads_folder

@app.route('/textset_list', methods=['GET', 'POST'])
def text_list():
    # list of text sets
    textset_list = get_textset_list()
    del_form = DeleteTextsetForm()
    reset_form = ResetTextsetForm()
    return render_template('text_list.html', textset_list=textset_list, del_form=del_form, reset_form=reset_form,
                           refresher=int(time.time()), config=get_config())


@app.route('/textset/<string:textset_id>', methods=['GET', 'POST'])
def text_set(textset_id):
    # detail of a text set
    textset = get_textset(textset_id)
    return render_template('text.html', textset=textset, refresher=int(time.time()), config=get_config())


@app.route('/create_text', methods=['GET', 'POST'])
def create_text():
    # form to create a new textset
    form = CreateTextsetForm()
    if request.method == 'POST':
        if form.validate():
            # try:
            if form.mode_file.data == 'upload':
                # check and upload a file
                filename = form.file_text.data.filename
                if filename == '' or filename.split('.')[-1].lower() != 'txt':
                    flash('file %s type must be txt' % filename)
                else:

                    form.filename.data = get_uploads_folder() + '/' + str(uuid.uuid4()) + '.' + filename.split('.')[