# Path: packtools/webapp/forms.py
# class XMLUploadForm(FlaskForm):
#     add_scielo_br_rules = BooleanField(default=True)
#     url_static_file = StringField(label=_("URL to statics files"))
#     file = FileField(label=_("File"), validators=[validators.input_required()])
# 
#     def validate_file(form, field):
#         _file = field.data
#         if _file:
#             if _file.content_type not in ["text/xml", "application/xml"]:
#                 raise validators.ValidationError(
#                     _(u"This type of file is not allowed! Please select another file.")
#                 )
# 
#             # _data = _file.read()
#             # if len(_data) > current_app.config.get('SETTINGS_MAX_UPLOAD_SIZE', 0):
#             #     raise validators.ValidationError(_(u"The file's size is too large! Please select a smaller file."))


from flask import (
    g,
    Blueprint,
    render_template,
    current_app,
    request,
    url_for,
    redirect,
    session,
)
    from urllib.parse import urljoin
    from urlparse import urljoin
from .forms import XMLUploadForm
from .utils import analyze_xml
import packtools
except ImportError:



main = Blueprint("main", __name__)


@main.before_app_request
def add_context_settings():
    setattr(
        g,
        "SETTINGS_MAX_UPLOAD_SIZE",
        current_app.config.get("SETTINGS_MAX_UPLOAD_SIZE"),
    )
    setattr(g, "PACKTOOLS_VERSION", current_app.config.get("PACKTOOLS_VERSION"))


@main.route("/", defaults={"path_file": ""})
@main.route("/<path:path_file>")
def packtools_home(path_file):
    if not path_file:
        return redirect(url_for("main.packtools_stylechecker"))

    url_session = session.get("url_static_file", "http://localhost")
    return redirect(urljoin(url_session, path_file))


@main.route("/stylechecker", methods=["GET", "POST"])
def packtools_stylechecker():


# Path: packtools/webapp/forms.py
# class XMLUploadForm(FlaskForm):
#     add_scielo_br_rules = BooleanField(default=True)
#     url_static_file = StringField(label=_("URL to statics files"))
#     file = FileField(label=_("File"), validators=[validators.input_required()])
# 
#     def validate_file(form, field):
#         _file = field.data
#         if _file:
#             if _file.content_type not in ["text/xml", "application/xml"]:
#                 raise validators.ValidationError(
#                     _(u"This type of file is not allowed! Please select another file.")
#                 )
# 
#             # _data = _file.read()
#             # if len(_data) > current_app.config.get('SETTINGS_MAX_UPLOAD_SIZE', 0):
#             #     raise validators.ValidationError(_(u"The file's size is too large! Please select a smaller file."))


# Path: packtools/webapp/views.py
from flask import (
    g,
    Blueprint,
    render_template,
    current_app,
    request,
    url_for,
    redirect,
    session,
)
    from urllib.parse import urljoin
    from urlparse import urljoin
from .forms import XMLUploadForm
from .utils import analyze_xml
import packtools

except ImportError:



main = Blueprint("main", __name__)


@main.before_app_request
def add_context_settings():
    setattr(
        g,
        "SETTINGS_MAX_UPLOAD_SIZE",
        current_app.config.get("SETTINGS_MAX_UPLOAD_SIZE"),
    )
    setattr(g, "PACKTOOLS_VERSION", current_app.config.get("PACKTOOLS_VERSION"))


@main.route("/", defaults={"path_file": ""})
@main.route("/<path:path_file>")
def packtools_home(path_file):
    if not path_file:
        return redirect(url_for("main.packtools_stylechecker"))

    url_session = session.get("url_static_file", "http://localhost")
    return redirect(urljoin(url_session, path_file))


@main.route("/stylechecker", methods=["GET", "POST"])
def packtools_stylechecker():


    form = XMLUploadForm()