<commit_before>import datetime
from flask import Blueprint, render_template, redirect, url_for, request, flash
from flask_login import current_user, login_required
from werkzeug.datastructures import CombinedMultiDict
from fernet import app, db, images, forms, teknologkoren_se
from fernet.views.auth import verify_email
from fernet.models import User, Tag
from fernet.util import tag_required

mod = Blueprint('admin', __name__, url_prefix='/admin')

app.jinja_env.add_extension('jinja2.ext.do')


@mod.before_request
@login_required
def before_request():
    """Make sure user is logged in before request.

    This function does nothing, but the decorators do.
    """
    pass


@mod.route('/')
@tag_required('Webmaster', 'PRoletär')
def admin():
    """Show administration page."""
    return render_template('admin/admin.html')


@mod.route('/edit-user/<int:id>/', methods=['GET', 'POST'])
@tag_required('Webmaster')
def full_edit_user(id):
    """Edit all user attributes.

    Allows for editing of all user attributes, including name and tags.
    Tags are in an encapsulated form generated dynamically in this view.
    """
    user = User.query.get_or_404(id)

    tags = Tag.query.order_by(Tag.name).all()
    form = forms.TagForm.extend_form(forms.FullEditUserForm, tags, user)

    form = form(user)

    if form.validate_on_submit():
        if form.email.data != user.email:
            verify_email(user, form.email.data)
            flash("A verification link has been sent to {}"
                  .format(form.email.data), 'info')

        user.phone = form.phone.data

        user.first_name = form.first_name.data
        user.last_name = form.last_name.data

        form.set_user_tags()

        db.session.commit()

        return redirect(url_for('.member', id=id))
    else:
        forms.flash_errors(form)

    return render_template('admin/full_edit_user.html',
                           user=user,
                           form=form)


@mod.route('/adduser/', methods=['GET', 'POST'])
@tag_required('Webmaster')
def adduser():
    """Add a user."""
    tags = Tag.query.order_by(Tag.name).all()
    Form = forms.TagForm.extend_form(forms.AddUserForm, tags)

    form = Form()

    if form.validate_on_submit():
        user = User(email=form.email.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    phone=form.phone.data)

        forms.TagForm.set_user_tags(form, user)

        db.session.commit()
<commit_msg>fix full edit user redirect<commit_after>import datetime
from flask import Blueprint, render_template, redirect, url_for, request, flash
from flask_login import current_user, login_required
from werkzeug.datastructures import CombinedMultiDict
from fernet import app, db, images, forms, teknologkoren_se
from fernet.views.auth import verify_email
from fernet.models import User, Tag
from fernet.util import tag_required

mod = Blueprint('admin', __name__, url_prefix='/admin')

app.jinja_env.add_extension('jinja2.ext.do')


@mod.before_request
@login_required
def before_request():
    """Make sure user is logged in before request.

    This function does nothing, but the decorators do.
    """
    pass


@mod.route('/')
@tag_required('Webmaster', 'PRoletär')
def admin():
    """Show administration page."""
    return render_template('admin/admin.html')


@mod.route('/edit-user/<int:id>/', methods=['GET', 'POST'])
@tag_required('Webmaster')
def full_edit_user(id):
    """Edit all user attributes.

    Allows for editing of all user attributes, including name and tags.
    Tags are in an encapsulated form generated dynamically in this view.
    """
    user = User.query.get_or_404(id)

    tags = Tag.query.order_by(Tag.name).all()
    form = forms.TagForm.extend_form(forms.FullEditUserForm, tags, user)

    form = form(user)

    if form.validate_on_submit():
        if form.email.data != user.email:
            verify_email(user, form.email.data)
            flash("A verification link has been sent to {}"
                  .format(form.email.data), 'info')

        user.phone = form.phone.data

        user.first_name = form.first_name.data
        user.last_name = form.last_name.data

        form.set_user_tags()

        db.session.commit()

        return redirect(url_for('profile.member', id=id))
    else:
        forms.flash_errors(form)

    return render_template('admin/full_edit_user.html',
                           user=user,
                           form=form)


@mod.route('/adduser/', methods=['GET', 'POST'])
@tag_required('Webmaster')
def adduser():
    """Add a user."""
    tags = Tag.query.order_by(Tag.name).all()
    Form = forms.TagForm.extend_form(forms.AddUserForm, tags)

    form = Form()

    if form.validate_on_submit():
        user = User(email=form.email.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    phone=form.phone.data)

        forms.TagForm.set_user_tags(form, user)

        db.session.commit()

{'fraction_non_alphanumeric': 0.11906169919179972, 'fraction_numerical': 0.001576976148235758, 'mean_word_length': 2.979607843137255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6573298', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1530, 'n_words': 360}