<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import request, redirect, url_for, render_template, flash, g, abort
from flask_babel import lazy_gettext,gettext
from flask_login import login_required

from app.utils import admin_required, crypt
from app.data.models import Group, User, U_G_Association
from app.public.forms import EditGroupForm
from . import admin
import json
from app.utils import fake_group


@admin.route('/group/list', methods=['GET', 'POST'])
@admin_required
def group_list():

    from app.data import DataTable
    datatable = DataTable(
        model=Group,
        columns=[],
        sortable=[Group.nazev, Group.created_ts],
        searchable=[Group.nazev],
        filterable=[],
        limits=[25, 50, 100],
        request=request
    )

    if g.pjax:
        return render_template(
            'groups.html',
            datatable=datatable
        )

    return render_template(
        'group-list.html',
        datatable=datatable
    )


@admin.route('/group/edit/<str_hash>', methods=['GET', 'POST'])
@admin_required
def group_edit(str_hash):
    id = int(float(crypt(str_hash, decrypt=True)))
    group = Group.query.filter_by(id=id).first_or_404()
    form = EditGroupForm(obj=group)
    if form.validate_on_submit():
        form.populate_obj(group)
        group.update()
        flash(gettext('Group {nazev} edited').format(nazev=group.nazev),'success')
    return render_template('group-edit.html', form=form, group=group)


@admin.route('/group/delete/<str_hash>', methods=['GET'])
@admin_required
def group_delete(str_hash):
    id = int(float(crypt(str_hash, decrypt=True)))
    group = Group.query.filter_by(id=id).first_or_404()
    group.delete()
    flash(gettext('Group {nazev} deleted').format(nazev=group.nazev),'success')
    return redirect(url_for('.group_list'))


class CustomEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, User) or isinstance(obj, Group):
            return obj.to_json()
        return json.JSONEncoder.default(self, obj)


@admin.route('/group/edit_users/', methods=['GET', 'POST'])
@admin_required
def group_edit_users():
    groups = Group.query.all()
    pole = json.dumps(groups, cls=CustomEncoder)
    return render_template('group_add_users.html', pole=pole)


@admin.route('/group/edit_users_submit/', methods=['POST'])
@admin_required
def group_edit_users_submit():
    if request.method <> "POST":
        return "Only POST requests allowed"
    data = json.loads(request.values.get('data'))
    group = Group.query.filter_by(nazev=data.get('group')).first_or_404()
    userlist = [(x, x.jmeno+" "+x.prijmeni) for x in User.query.join(U_G_Association).join(Group).filter(Group.nazev==data.get('group')).all()]
    userlist = zip(*userlist)
    for user in data.data:
        if user in userlist[1]:
            #no change
            pass
        else:
            #added user
            group.add_user(User.query.filter_by())

    return "ok"


@admin.route('/group/_get_users/<group_name>', methods=['GET', 'POST'])
def get_users(group_name):<commit_msg>Changed <> syntax to !=<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import request, redirect, url_for, render_template, flash, g, abort
from flask_babel import lazy_gettext,gettext
from flask_login import login_required

from app.utils import admin_required, crypt
from app.data.models import Group, User, U_G_Association
from app.public.forms import EditGroupForm
from . import admin
import json
from app.utils import fake_group


@admin.route('/group/list', methods=['GET', 'POST'])
@admin_required
def group_list():

    from app.data import DataTable
    datatable = DataTable(
        model=Group,
        columns=[],
        sortable=[Group.nazev, Group.created_ts],
        searchable=[Group.nazev],
        filterable=[],
        limits=[25, 50, 100],
        request=request
    )

    if g.pjax:
        return render_template(
            'groups.html',
            datatable=datatable
        )

    return render_template(
        'group-list.html',
        datatable=datatable
    )


@admin.route('/group/edit/<str_hash>', methods=['GET', 'POST'])
@admin_required
def group_edit(str_hash):
    id = int(float(crypt(str_hash, decrypt=True)))
    group = Group.query.filter_by(id=id).first_or_404()
    form = EditGroupForm(obj=group)
    if form.validate_on_submit():
        form.populate_obj(group)
        group.update()
        flash(gettext('Group {nazev} edited').format(nazev=group.nazev),'success')
    return render_template('group-edit.html', form=form, group=group)


@admin.route('/group/delete/<str_hash>', methods=['GET'])
@admin_required
def group_delete(str_hash):
    id = int(float(crypt(str_hash, decrypt=True)))
    group = Group.query.filter_by(id=id).first_or_404()
    group.delete()
    flash(gettext('Group {nazev} deleted').format(nazev=group.nazev),'success')
    return redirect(url_for('.group_list'))


class CustomEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, User) or isinstance(obj, Group):
            return obj.to_json()
        return json.JSONEncoder.default(self, obj)


@admin.route('/group/edit_users/', methods=['GET', 'POST'])
@admin_required
def group_edit_users():
    groups = Group.query.all()
    pole = json.dumps(groups, cls=CustomEncoder)
    return render_template('group_add_users.html', pole=pole)


@admin.route('/group/edit_users_submit/', methods=['POST'])
@admin_required
def group_edit_users_submit():
    if request.method != "POST":
        return "Only POST requests allowed"
    data = json.loads(request.values.get('data'))
    group = Group.query.filter_by(nazev=data.get('group')).first_or_404()
    userlist = [(x, x.jmeno+" "+x.prijmeni) for x in User.query.join(U_G_Association).join(Group).filter(Group.nazev==data.get('group')).all()]
    userlist = zip(*userlist)
    for user in data.data:
        if user in userlist[1]:
            #no change
            pass
        else:
            #added user
            group.add_user(User.query.filter_by())

    return "ok"


@admin.route('/group/_get_users/<group_name>', methods=['GET', 'POST'])
def get_users(group_name):
{'fraction_non_alphanumeric': 0.1429948586118252, 'fraction_numerical': 0.005784061696658098, 'mean_word_length': 3.621380846325167, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, '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': '3194731', 'n_tokens_mistral': 2055, 'n_tokens_neox': 1998, 'n_words': 396}