Beispiel #1
0
def command(ctx, username, create, batch):
    """
    Update or optionally create password, name and type of a user.

    USERNAME : The username of the user to process.

    """
    User = rt.models.users.User
    UserTypes = rt.models.users.UserTypes
    try:
        user = User.objects.get(username=username)
        if create:
            raise click.UsageError(
                "Cannot create existing user named '{}'".format(username))
    except User.DoesNotExist:
        if create:
            user = User(username=username)
            click.echo("Creating new user")
        else:
            raise click.UsageError(
                "We have no user named '{}'".format(username))

    dut = user.user_type or UserTypes.user
    if not batch:
        user.first_name = click.prompt("First name",
                                       default=user.first_name or username)
        user.last_name = click.prompt("Last name",
                                      default=user.last_name or username)
        user_type = click.prompt("User type",
                                 type=click.Choice([
                                     ut.name
                                     for ut in UserTypes.get_list_items()
                                     if ut.name
                                 ]),
                                 default=dut.name)
        if user_type:
            user.user_type = UserTypes.get_by_name(user_type)
        else:
            user.user_type = None
        passwd = click.prompt(
            "Password (leave blank to deactivate user account)",
            hide_input=True,
            confirmation_prompt=True,
            default='')
        if passwd:
            user.set_password(passwd)
        else:
            user.set_unusable_password()
    user.full_clean()
    if batch or yes_or_no('Going to save {}. Are you sure?'.format(user)):
        user.save()
        click.echo("User {} has been saved.".format(user))
Beispiel #2
0
import djclick as click

from django.core.files import File

from remark.users.models import User
from remark.projects.models import Project, Spreadsheet, Spreadsheet2, Campaign, CampaignModel
from remark.projects.spreadsheets.activators import ModelingActivator
from remark.projects.spreadsheets import get_importer_for_kind, SpreadsheetKind


@click.command()
@click.option(
    "-k",
    "--kind",
    required=True,
    type=click.Choice([k[0] for k in SpreadsheetKind.CHOICES]),
    help="The kind of spreadsheet file to import.",
)
@click.option(
    "-p",
    "--project",
    required=True,
    type=click.Choice(
        list(Project.objects.all().values_list("public_id", flat=True))),
    help="public_id of the project",
)
@click.option(
    "-c",
    "--campaign",
    required=False,
    type=click.Choice(
import djclick as click

from ...models import Account, AccountType


@click.command()
@click.argument('email', type=str)
@click.option('--type',
              default=AccountType.RESEARCHER.value,
              type=click.Choice([
                  AccountType.RESEARCHER.value,
                  AccountType.ADMIN.value,
              ]))
def command(email, type):
    """Create account of a given type."""

    try:
        Account.objects.get(email=email)

    except Account.DoesNotExist:
        Account.objects.create(email=email, type=type)

    else:
        raise click.ClickException('Account with that email already exists')

    click.secho(
        f'Successfully create an account with email: {email} and type: {type}',
        fg='green')
Beispiel #4
0

def create_list_kpi(result, campaign, prefix, kpis, health):
    result[f"{prefix}_1"] = list_kpi(kpis[0], campaign, health)
    if len(kpis) > 1:
        result[f"{prefix}_2"] = list_kpi(kpis[1], campaign, health)
    if len(kpis) > 2:
        result[f"{prefix}_3"] = list_kpi(kpis[2], campaign, health)


@click.command()
@click.option(
    "-p",
    "--project_id",
    required=True,
    type=click.Choice(
        list(Project.objects.all().values_list("public_id", flat=True))),
    help="The project id.",
)
@click.option(
    "-s",
    "--start",
    required=True,
    type=click.DateTime(formats=("%m/%d/%Y", )),
    help="Start of reporting period",
)
@click.option("-c", "--client", required=True, type=str, help="Name of client")
@click.option("-h",
              "--health",
              required=True,
              type=click.Choice(("0", "1", "2")),
              help="Health of campaign. Must be 0,1,2")
Beispiel #5
0
              help=HELPS['url'])
@click.option('--realm', '-r', default='realm1', help=HELPS['realm'])
@click.option('--module',
              '-m',
              default='modelservice.profiles',
              help=HELPS['module'])
@click.option('--workers', '-w', type=int, default=1, help=HELPS['workers'])
@click.option('--groups', '-g', type=int, default=1, help=HELPS['groups'])
@click.option('--name',
              '-n',
              envvar='WORKER_NAME',
              default=None,
              help=HELPS['name'])
@click.option('--user-email', 'email', default=None, help=HELPS['user-email'])
@click.option('--log-level',
              'log_level',
              default='info',
              help=HELPS['log_level'],
              type=click.Choice(['debug', 'info', 'warn', 'error',
                                 'critical']))
def command(url, realm, module, workers, groups, name, email, log_level):
    class WorkerComponent(_WorkerComponent):
        user_email = email
        worker_name = name or user_email or 'worker'
        workers_count = workers
        groups_count = groups
        profile_module = module

    runner = ApplicationRunner(url=url, realm=realm)
    runner.run(WorkerComponent, log_level=log_level)
import json

import djclick as click

from django.core.serializers.json import DjangoJSONEncoder

from remark.projects.spreadsheets import get_importer_for_kind, SpreadsheetKind


@click.command()
@click.option(
    "-k",
    "--kind",
    required=True,
    type=click.Choice([k[0] for k in SpreadsheetKind.CHOICES]),
    help="The kind of spreadsheet file to import.",
)
@click.argument("file", required=True, type=click.File("rb"))
def command(kind, file):
    """
    Load a spreadsheet file, validate it, and (if valid), pretty-print an
    intermediate JSON representation of its contents.
    """

    importer = get_importer_for_kind(kind, file)

    if importer is None:
        raise click.BadParameter(
            f"kind must be a currently importable spreadsheet kind, not '{kind}'"
        )
import djclick as click

from remark.geo.models import Zipcode, USACensusZip
from remark.lib.logging import getLogger
from remark.geo.usa_census import get_usa_census_data

logger = getLogger(__name__)


@click.command()
@click.option(
    "-s",
    "--state",
    required=False,
    type=click.Choice(list(Zipcode.objects.values_list("state", flat=True).distinct())),
    help="State to import (UPPERCASED)",
)
@click.option(
    "-z",
    "--zipcode",
    required=False,
    type=str,
    help="Zipcode to import",
)
def command(state, zipcode):
    """Pull all of the census data from Statistical Atlas"""

    # process zipcodes which is already identified to have population
    # check identify_dead_zipcodes.py command
    query = dict(has_population=True)