<commit_before># -*- coding: utf-8 -*-

from flask import render_template, redirect, request
from coaster.views import load_models
from baseframe import _
from baseframe.forms import render_form, render_delete_sqla

from .. import app, lastuser
from ..models import db, Profile, User, UserGroup, ProposalSpace
from ..forms import UserGroupForm


@app.route('/<space>/users', subdomain='<profile>')
@lastuser.requires_login
@load_models(
    (Profile, {'name': 'profile'}, 'g.profile'),
    (ProposalSpace, {'name': 'space', 'profile': 'profile'}, 'space'),
    permission='view-usergroup')
def usergroup_list(profile, space):
    return render_template('usergroups.html', space=space, usergroups=space.usergroups)


@app.route('/<space>/users/<group>', subdomain='<profile>')
@lastuser.requires_login
@load_models(
    (Profile, {'name': 'profile'}, 'g.profile'),
    (ProposalSpace, {'name': 'space', 'profile': 'profile'}, 'space'),
    (UserGroup, {'name': 'group', 'proposal_space': 'space'}, 'usergroup'),
    permission='view-usergroup')
def usergroup_view(profile, space, usergroup):
    return render_template('usergroup.html', space=space, usergroup=usergroup)


@app.route('/<space>/users/new', defaults={'group': None}, endpoint='usergroup_new', methods=['GET', 'POST'], subdomain='<profile>')
@app.route('/<space>/users/<group>/edit', methods=['GET', 'POST'], subdomain='<profile>')
@lastuser.requires_login
@load_models(
    (Profile, {'name': 'profile'}, 'g.profile'),
    (ProposalSpace, {'name': 'space', 'profile': 'profile'}, 'space'),
    permission='new-usergroup')
def usergroup_edit(profile, space, kwargs):
    group = kwargs.get('group')
    form = UserGroupForm(model=UserGroup, parent=space)
    if group is not None:
        usergroup = UserGroup.query.filter_by(name=group, proposal_space=space).first_or_404()
        form.edit_id = usergroup.id
        if request.method == 'GET':
            form.name.data = usergroup.name
            form.title.data = usergroup.title
            form.users.data = '\r\n'.join([u.email or u.username or '' for u in usergroup.users])
    if form.validate_on_submit():
        if group is None:
            usergroup = UserGroup(proposal_space=space)
        usergroup.name = form.name.data
        usergroup.title = form.title.data
        formdata = [line.strip() for line in
            form.users.data.replace('\r', '\n').replace(',', '\n').split('\n') if line]
        usersdata = lastuser.getusers(names=formdata)
        users = []
        for userdata in usersdata or []:
            user = User.query.filter_by(userid=userdata['userid']).first()<commit_msg>Fix for user edit view.<commit_after># -*- coding: utf-8 -*-

from flask import render_template, redirect, request
from coaster.views import load_models
from baseframe import _
from baseframe.forms import render_form, render_delete_sqla

from .. import app, lastuser
from ..models import db, Profile, User, UserGroup, ProposalSpace
from ..forms import UserGroupForm


@app.route('/<space>/users', subdomain='<profile>')
@lastuser.requires_login
@load_models(
    (Profile, {'name': 'profile'}, 'g.profile'),
    (ProposalSpace, {'name': 'space', 'profile': 'profile'}, 'space'),
    permission='view-usergroup')
def usergroup_list(profile, space):
    return render_template('usergroups.html', space=space, usergroups=space.usergroups)


@app.route('/<space>/users/<group>', subdomain='<profile>')
@lastuser.requires_login
@load_models(
    (Profile, {'name': 'profile'}, 'g.profile'),
    (ProposalSpace, {'name': 'space', 'profile': 'profile'}, 'space'),
    (UserGroup, {'name': 'group', 'proposal_space': 'space'}, 'usergroup'),
    permission='view-usergroup')
def usergroup_view(profile, space, usergroup):
    return render_template('usergroup.html', space=space, usergroup=usergroup)


@app.route('/<space>/users/new',
    defaults={'group': None},
    endpoint='usergroup_new',
    methods=['GET', 'POST'],
    subdomain='<profile>')
@app.route('/<space>/users/<group>/edit', methods=['GET', 'POST'], subdomain='<profile>')
@lastuser.requires_login
@load_models(
    (Profile, {'name': 'profile'}, 'g.profile'),
    (ProposalSpace, {'name': 'space', 'profile': 'profile'}, 'space'),
    permission='new-usergroup', kwargs=True)
def usergroup_edit(profile, space, kwargs):
    group = kwargs.get('group')
    form = UserGroupForm(model=UserGroup, parent=space)
    if group is not None:
        usergroup = UserGroup.query.filter_by(name=group, proposal_space=space).first_or_404()
        form.edit_id = usergroup.id
        if request.method == 'GET':
            form.name.data = usergroup.name
            form.title.data = usergroup.title
            form.users.data = '\r\n'.join([u.email or u.username or '' for u in usergroup.users])
    if form.validate_on_submit():
        if group is None:
            usergroup = UserGroup(proposal_space=space)
        usergroup.name = form.name.data
        usergroup.title = form.title.data
        formdata = [line.strip() for line in
            form.users.data.replace('\r', '\n').replace(',', '\n').split('\n') if line]
        usersdata = lastuser.getusers(names=formdata)
        users = []
        for userdata in usersdata or []:
            user = User.query.filter_by(userid=userdata['userid']).first()
{'fraction_non_alphanumeric': 0.16927722211738064, 'fraction_numerical': 0.0015097188148707303, 'mean_word_length': 4.110896817743491, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '7117342', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1627, 'n_words': 362}