<commit_before># -*- coding: utf8 -*-
from __future__ import division
from __future__ import absolute_import
from past.utils import old_div
import six
import ckan.plugins.toolkit as t
import ckan.lib.mailer as mailer
from datetime import datetime

import click


@click.group()
def apicatalog_admin():
    '''Creates users based on records uploaded to create_user_to_organization endpoint'''
    pass


@apicatalog_admin.command(
    u'create-organization-users',
    help='Creates users based on records uploaded to create_user_to_organization endpoint'
)
@click.pass_context
@click.option(u'--retry', is_flag=True)
def create_organization_users(ctx, retry):
    result = t.get_action('create_organization_users')({'ignore_auth': True}, {'retry': retry}).get('result', {})
    created = result.get('created', [])
    invalid = result.get('invalid', [])
    ambiguous = result.get('ambiguous', [])
    duplicate = result.get('duplicate', [])
    click.echo('Created users: %s' % ', '.join(created))
    click.echo('Duplicate users: %s' % ', '.join(duplicate))
    click.echo('Unknown business ids: %s' % ', '.join(invalid))
    click.echo('Ambiguous business ids: %s' % ', '.join(ambiguous))<commit_msg>Fix request context while inviting users on cli<commit_after># -*- coding: utf8 -*-
from __future__ import division
from __future__ import absolute_import
from past.utils import old_div
import six
import ckan.plugins.toolkit as t
import ckan.lib.mailer as mailer
from datetime import datetime

import click


@click.group()
def apicatalog_admin():
    '''Creates users based on records uploaded to create_user_to_organization endpoint'''
    pass


@apicatalog_admin.command(
    u'create-organization-users',
    help='Creates users based on records uploaded to create_user_to_organization endpoint'
)
@click.pass_context
@click.option(u'--retry', is_flag=True)
def create_organization_users(ctx, retry):

    site_user = t.get_action('get_site_user')({'ignore_auth': True})

    flask_app = ctx.meta["flask_app"]
    with flask_app.test_request_context():
        result = t.get_action('create_organization_users')({'ignore_auth': True, 'user': site_user['name'] }, {'retry': retry}).get('result', {})

    created = result.get('created', [])
    invalid = result.get('invalid', [])
    ambiguous = result.get('ambiguous', [])
    duplicate = result.get('duplicate', [])
    click.echo('Created users: %s' % ', '.join(created))
    click.echo('Duplicate users: %s' % ', '.join(duplicate))
    click.echo('Unknown business ids: %s' % ', '.join(invalid))
    click.echo('Ambiguous business ids: %s' % ', '.join(ambiguous))
{'fraction_non_alphanumeric': 0.1459047619047619, 'fraction_numerical': 0.0007619047619047619, 'mean_word_length': 4.9411764705882355, 'pattern_counts': {'":': 0, '<': 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': '2404404', 'n_tokens_mistral': 821, 'n_tokens_neox': 807, 'n_words': 199}