<commit_before>import json

from flask import Blueprint, render_template, abort, redirect, url_for, request, make_response
from flask_login import current_user

from portality import models
from portality.decorators import write_required

from portality.forms.application_forms import ApplicationFormFactory

blueprint = Blueprint('apply', __name__)


@blueprint.route("/", methods=["GET", "POST"])
@write_required()
def public_application(draft_id=None):

    if not current_user.is_authenticated:
        return redirect(url_for("account.login",  redirected="apply"))

    draft_application = None
    if draft_id is not None:
        draft_application = models.DraftApplication.pull(draft_id)
        if draft_application is None:
            abort(404)
        if draft_application.owner != current_user.id:
            abort(404)

    if request.method == "GET":
        fc = ApplicationFormFactory.context("public")
        if draft_application is not None:
            fc.processor(source=draft_application)
        return fc.render_template(obj=draft_application)

    elif request.method == "POST":

        fc = ApplicationFormFactory.context("public")

        draft = request.form.get("draft")
        async_def = request.form.get("async")
        draft_id = request.form.get("draft_id")

        if draft_id != "new_form":
            draft_application = models.DraftApplication.pull(draft_id)
            if draft_application is None:
                abort(404)
            if draft_application.owner != current_user.id:
                abort(404)

        processor = fc.processor(formdata=request.form)

        if draft == "false":
            if processor.validate():
                processor.finalise()
                return redirect(url_for('doaj.application_thanks', _anchor='thanks'))
            else:
                return fc.render_template()

        else:
            the_draft = processor.draft(current_user._get_current_object(), id=draft_id)<commit_msg>change how drafts are checked for save in the back end<commit_after>import json

from flask import Blueprint, render_template, abort, redirect, url_for, request, make_response
from flask_login import current_user

from portality import models
from portality.decorators import write_required

from portality.forms.application_forms import ApplicationFormFactory

blueprint = Blueprint('apply', __name__)


@blueprint.route("/", methods=["GET", "POST"])
@write_required()
def public_application(draft_id=None):

    if not current_user.is_authenticated:
        return redirect(url_for("account.login",  redirected="apply"))

    draft_application = None
    if draft_id is not None:
        draft_application = models.DraftApplication.pull(draft_id)
        if draft_application is None:
            abort(404)
        if draft_application.owner != current_user.id:
            abort(404)

    if request.method == "GET":
        fc = ApplicationFormFactory.context("public")
        if draft_application is not None:
            fc.processor(source=draft_application)
        return fc.render_template(obj=draft_application)

    elif request.method == "POST":

        fc = ApplicationFormFactory.context("public")

        draft = request.form.get("draft")
        async_def = request.form.get("async")
        draft_id = request.form.get("draft_id")

        if draft_id is not None:
            draft_application = models.DraftApplication.pull(draft_id)
            if draft_application is None:
                abort(404)
            if draft_application.owner != current_user.id:
                abort(404)

        processor = fc.processor(formdata=request.form)

        if draft == "false":
            if processor.validate():
                processor.finalise()
                return redirect(url_for('doaj.application_thanks', _anchor='thanks'))
            else:
                return fc.render_template()

        else:
            the_draft = processor.draft(current_user._get_current_object(), id=draft_id)
{'fraction_non_alphanumeric': 0.09274495138369485, 'fraction_numerical': 0.005983545250560957, 'mean_word_length': 2.8651252408477843, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2096591', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1057, 'n_words': 245}