Esempio n. 1
0
def command():
    '''
    Print the "Unreleased" section of CHANGELOG.md to stdout.
    '''

    notes = changelog.get_unreleased_notes(changelog.get_contents())
    click.echo(notes.strip())
Esempio n. 2
0
def get_team(team):
    """
        We're asking user for names and address of the rest of the team,
        and append that to a list we got from get_main_organizer
    """
    add_team = click.confirm(click.style(
        "Do you want to add additional team members?", bold=True, fg='yellow'), default=False)
    i = 1
    while add_team:
        i += 1
        name = click.prompt(click.style(
            "First and last name of #{0} member".format(i), bold=True, fg='yellow'))
        email = click.prompt(click.style(
            "E-mail address of #{0} member".format(i), bold=True, fg='yellow'))
        if len(name) > 0:
            try:
                team.append({'first_name': name.split(' ')[
                            0], 'last_name': name.split(' ')[1], 'email': email})
            except IndexError:
                team.append(
                    {'first_name': name, 'last_name': '', 'email': email})
            click.echo("All right, the #{0} team member of Django Girls is {1} ({2})".format(
                i, name, email))
        add_team = click.confirm(click.style(
            "Do you want to add additional team members?", bold=True, fg='yellow'), default=False)

    return team
Esempio n. 3
0
def command():
    """Creates new Django Girls organizer"""
    event_id = click.prompt(click.style(
        "What's the event ID? NOT the event page ID. We want EVENT ID here",
        bold=True, fg='yellow'))
    event = Event.objects.get(id=event_id)
    click.echo("Ok, we're adding to an event in {}, {}".format(
        event.city, event.country))
    team = [get_organizer_data()]

    while click.confirm(
        click.style("Do you want to add additional team members?",
                    bold=True, fg='yellow'), default=False):
        team.append(get_organizer_data())

    click.echo("OK! That's it. Now I'll add your organizers.")

    members = create_users(team, event)

    for member in members:
        click.echo(
                "User {} has been added and notified".format(member.email))

    click.echo(DELIMITER)

    click.echo("You still need to invite people to Google Group!")
Esempio n. 4
0
def command(initial, index):
    if not index.last_update_serial or initial:
        chunk_size = 150  # Number of packages to update per task
        concurrency = 30  # Number of concurrent tasks

        # As we are syncing everything, get the current serial.
        index.last_update_serial = index.client.changelog_last_serial()

        # Get the set of all existing packages. We will discard IDs of updated
        # packages from it and then remove all the remaining packages.
        all_package_ids = set(index.package_set.values_list('id', flat=True))

        # Get all the names of the packages on the selected index.
        click.secho('Fetching list of packages from {}...'.format(index.url),
                    fg='yellow')
        all_packages = index.client.list_packages()

        # Import all packages metadata in different chunks and tasks.
        click.secho('Importing {} packages...'.format(len(all_packages)),
                    fg='yellow')
        # Create a generator of (index.pk, all_packages[i:i+chunk_size]) tuples
        args = iterzip(
            itertools.repeat(index.pk),
            utils.iter_chunks(all_packages, chunk_size),
        )
        # Submit each tuple in args to the workers, but limit it to at most
        # `concurrency` running tasks
        results_iterator = utils.bounded_submitter(
            import_packages,
            concurrency,
            args,
        )
        with click.progressbar(length=len(all_packages), show_pos=True) as bar:
            for succeded, ignored, failed in results_iterator:
                bar.update(len(succeded) + len(ignored) + len(failed))
                all_package_ids -= set(succeded.values())
                if failed:
                    click.echo('')
                    for k, v in six.iteritems(failed):
                        click.secho('Failed to import {} ({})'.format(k, v),
                                    fg='red')

        # Remove the set of not-updated (i.e. not found on the index anymore)
        # packages from the database.
        click.secho('Removing {} outdated packages...'
                    .format(len(all_package_ids)), fg='yellow')
        index.package_set.filter(pk__in=all_package_ids).delete()
        index.save(update_fields=['last_update_serial'])

    # Sync everything since the last serial, also when initial == True, as
    # something might have changed in the meantime...
    events = index.client.changelog_last_serial() - index.last_update_serial
    if events:
        click.secho('Syncing remaining updates...', fg='yellow')
        sync_iter = index.itersync()
        with click.progressbar(sync_iter, length=events, show_pos=True) as bar:
            for event in bar:
                pass
Esempio n. 5
0
def command(user_file, groupname, dryrun):
    '''
    Bulk creates users from email addresses in the the specified text file,
    which should contain one email address per line.
    If the optional "--group <GROUPNAME>" argument is specified, then all the
    users (either found or created) are added to the matching group.
    '''
    if dryrun:
        click.echo('Starting dry run (no database records will be modified).')

    if groupname:
        try:
            group = Group.objects.get(name=groupname)
        except Group.DoesNotExist:
            raise CommandError(
                '"{}" group does not exist. Exiting.'.format(groupname))

    email_addresses = [s.strip() for s in user_file.readlines()]

    try:
        with transaction.atomic():
            users = get_or_create_users(email_addresses)
            click.echo(
                'Created (or found) {} user accounts.'.format(len(users)))
            if group:
                add_users_to_group(group, users)
                click.echo('Added users to "{}" group.'.format(groupname))
            if dryrun:
                raise DryRunFinished()
    except DryRunFinished:
        click.echo("Dry run complete.")
Esempio n. 6
0
def get_main_organizer():
    """
        We're asking user for name and address of main organizer, and return
        a list of dictionary.
    """
    team = []
    click.echo("Now let's talk about the team. First the main organizer:")
    main_name = click.prompt(click.style("First and last name", bold=True, fg="yellow"))
    main_email = click.prompt(click.style("E-mail address", bold=True, fg="yellow"))

    team.append({"name": main_name, "email": main_email})

    click.echo("All right, the main organizer is {0} ({1})".format(main_name, main_email))

    return team
Esempio n. 7
0
def start(path, limit, username, collection):
    """Start an import session"""

    click.secho('--------------------------------------------------------------------', bold=True)
    click.echo('Username:\t {}'.format(username))
    click.echo('Collection:\t {}'.format(collection))
    click.echo('Limit:\t\t {}'.format(limit))
    click.echo('Path:\t\t {}'.format(path))
    click.secho('--------------------------------------------------------------------', bold=True)
    click.echo('')

    if not os.path.isdir(path):
        click.secho('Directory does not exist: {}'.format(path), bold=True, fg='red')
        return

    if not path.endswith('/'):
        path += '/'

    if not User.objects.filter(username=username).exists():
        click.secho('User does not exist: {}'.format(username), bold=True, fg='red')
        return

    if Massimport.objects.filter(directory=path).exists():
        click.secho('Import session already exists: {}'.format(path), bold=True, fg='red')
        return


    massimport = Massimport(
        directory=path,
        user=User.objects.get(username=username),
        collection_name=collection
    )

    massimport.save()

    if click.confirm('Continue with scanning directories?', default='Y'):
        massimport.scan()

    if click.confirm('Continue with enqueuing files?'):

        for item in massimport.files.filter(status=0)[0:limit]:
            item.enqueue()
Esempio n. 8
0
def get_main_organizer():
    """
        We're asking user for name and address of main organizer, and return
        a list of dictionary.
    """
    team = []
    click.echo("Now let's talk about the team. First the main organizer:")
    main_name = click.prompt(click.style(
        "First and last name", bold=True, fg='yellow'))
    main_email = click.prompt(click.style(
        "E-mail address", bold=True, fg='yellow'))
    try:
        team.append({'first_name': main_name.split(' ')[
                    0], 'last_name': main_name.split(' ')[1], 'email': main_email})
    except IndexError:
        team.append({'first_name': main_name,
                     'last_name': '', 'email': main_email})
    click.echo(u"All right, the main organizer is {0} ({1})".format(
        main_name, main_email))

    return team
Esempio n. 9
0
def command(version_to_release):
    '''
    Creates instructions for releasing a specific version of CALC.
    '''

    v = version_to_release

    with RELEASE_MD.open('r', encoding='utf-8') as f:
        md = f.read()

    md = md.replace('0.0.4', v)

    basename = 'release-v%s-instructions' % v
    markdown_filename = '%s.txt' % basename
    html_filename = '%s.html' % basename

    with pathlib.Path(markdown_filename).open('w', encoding='utf-8') as f:
        f.write(md)

    with pathlib.Path(html_filename).open('w', encoding='utf-8') as f:
        f.write(HTML_TEMPLATE % dict(
            version=v,
            html=markdown.markdown(md)
        ))

    click.echo('Wrote plaintext instructions to %s.' % markdown_filename)
    click.echo('Wrote HTML instructions to %s.' % html_filename)
    click.echo('Please open one of these to learn how release v%s.' % v)
Esempio n. 10
0
def gather_information():
    click.echo("Hello there sunshine! We're gonna copy an event website now.")

    event = get_event(
        click.prompt(click.style("First, give me the latest ID of the Event "
        "object you want to copy", bold=True, fg='yellow'))
    )

    while not event:
        event = get_event(click.prompt("Wrong ID! Try again"))

    click.echo("Ok, we're copying {}, {}".format(
        event.city, event.country))

    number = click.prompt(click.style("What is the number of the event in this city? "
        "If this is a second event, write 2. If third, then 3. You got it", bold=True, fg='yellow')
    )

    date = gather_event_date_from_prompt()

    click.echo("The current team is: " + ", ".join(
        str(organizer) for organizer in event.team.all()))

    new_team = click.confirm(click.style(
        "Do you need to change the whole team?", bold=True, fg='yellow'), default=False
    )

    return (event, number, date, new_team)
Esempio n. 11
0
def command(pk, slug, endswith):
    if pk:
        click.echo(repr(pk), nl=False)
    if slug:
        click.echo(repr(slug), nl=False)
    if endswith:
        click.echo(repr(endswith), nl=False)
Esempio n. 12
0
def get_basic_info():
    """
        Here we're asking the user for:
        - city
        - country
        - date
        - url
        - event_email
        And return all these information.
    """
    click.echo(
        "Hello there! Let's create new Django Girls event! So exciting!")
    click.echo("Let's start with some basics.")
    city = click.prompt(click.style(
        "What is the name of the city?", bold=True, fg='yellow'))
    country = click.prompt(click.style(
        "What is the name of the country?", bold=True, fg='yellow'))

    date = gather_event_date_from_prompt()

    url = click.prompt(click.style(
        "What should be the URL of website? djangogirls.org/xxxx", bold=True, fg='yellow'))
    event_mail = click.prompt(click.style(
        "What is the mail adress of the event? [email protected]", bold=True, fg='yellow'))
    click.echo("Ok, got that! Your new event will happen in {0}, {1} on {2}".format(
        city, country, date))

    return (city, country, date, url, event_mail)
Esempio n. 13
0
def gather_information():
    click.echo("Hello there sunshine! We're gonna copy an event website now.")

    event = get_event(
        click.prompt(
            "First, give me the ID of the Event object we're gonna copy. "
            "Don't mix it up with EventPage object. If there is more than "
            "one event in this city already, give me ID of the latest one"
        )
    )

    while not event:
        event = get_event(click.prompt("Wrong ID! Try again"))

    number = click.prompt(
        "What is the number of the event in this city? "
        "If this is a second event, write 2. If third, then 3. You got it"
    )

    date = gather_event_date_from_prompt()

    return (event, number, date)
def command():
    facts = compute_dataset_facts(
        Agency, Stop, settings.NC_KEY, Search=Search,
        override_start_date='Jan 01, 2002'
    )
    for fact in facts:
        click.echo(fact)
    click.echo('')
    click.echo('Very few agencies reported before 2000, so the claimed start date is 2002.')
Esempio n. 15
0
def command():
    '''
    Updates CHANGELOG.md to reflect the new version specified in
    calc/version.py.

    The "Unreleased" section of the changelog will be moved to a
    new release with the given version number.

    The new release will be hyperlinked to a GitHub diff between it and the
    previous release, while the "Unreleased" section will be emptied and
    hyperlinked to a GitHub diff between the new release and HEAD.
    '''

    markdown = changelog.get_contents()
    new_version = Version(__version__)
    old_version = Version(changelog.get_latest_release(markdown))
    base_release_notes = changelog.get_unreleased_notes(markdown).strip()
    release_notes = 'Release ' + str(new_version) + '\n\n' + \
        changelog.replace_heading_leaders(base_release_notes)
    release_notes_filename = 'tag-message-v%s.txt' % new_version

    if new_version <= old_version:
        raise CommandError(
            'Please change calc/version.py to reflect the new '
            'version you\'d like to bump CHANGELOG.md to.')

    if base_release_notes == '':
        raise CommandError(
            'The new release has no release notes! Please add some '
            'under the "Unreleased" section of CHANGELOG.md.')

    click.echo('Modifying CHANGELOG.md to reflect new '
               'release %s.' % new_version)

    new_markdown = changelog.bump_version(markdown, str(new_version))

    with changelog.PATH.open('w', encoding=changelog.ENCODING) as f:
        f.write(new_markdown)

    click.echo('Writing release notes to %s.' % release_notes_filename)

    with open(release_notes_filename, 'w', encoding=changelog.ENCODING) as f:
        f.write(release_notes + '\n')

    click.echo('Done. To undo these changes, run '
               '"git checkout -- CHANGELOG.md".')
Esempio n. 16
0
def command():
    # Just print some things which shall not be found in the output
    click.echo('HELP_CALLED')  # NOCOV
def download_files(report_id, reports_list, file_name, files_encrypted):
    # get report files - CHANGE URL TO HEROKU AFTER DEVELOPMENT
    r = requests.post(
        'http://afternoon-fortress-38321.herokuapp.com/fda_get_files/', {
            'report_id': report_id,
            'file_name': file_name
        })
    if files_encrypted:
        if click.confirm("Do you have the private key?"):
            key_file = click.prompt(
                'Enter the path to the keyfile for this file')
            key = None
            try:
                with open(key_file, 'rb') as f:
                    key = b64decode(f.read())
                out_name = file_name
                if file_name.split('.')[-1] == 'enc':
                    out_name = file_name[:-4]
                    decrypt_file(file_name, key, out_name)
            except FileNotFoundError:
                click.echo('ERROR: Keyfile not found')
                exit()
            click.echo('File saved as {}'.format(out_name))
        else:
            click.echo('You cannot download the file.')
            if click.confirm(
                    "Would you like to view another report's contents?"):
                view_report_contents(reports_list)
            else:
                click.echo('Goodbye then.')
                exit()
    else:
        file = open(file_name, 'wb')
        file.write(r.content)
        file.close()
        click.echo('Success. Your file has been downloaded.')

    if click.confirm("Would you like to view another report's contents?"):
        view_report_contents(reports_list)
    else:
        click.echo('Goodbye then.')
        exit()
Esempio n. 18
0
def main():
    click.echo('group_command')
Esempio n. 19
0
def command():
    """Clear the database of expired jobs"""
    django_rq.enqueue(tasks.do_clear_jobs)
    click.echo('Enqueued cleaning job')
Esempio n. 20
0
def command():
    """Duplicates Django Girls event with a new date"""

    # Gather data
    (event, number, date, new_team) = gather_information()
    organizers = event.team.all()

    # Remove #{no} from name:
    name = event.name.split('#')[0].strip()
    number = int(number)

    # Change the name of previous event to {name} #{number-1}
    event.name = "{} #{}".format(name, number - 1)
    event.save()

    # Copy event with a name {name} #{number}, new date and empty stats
    new_event = Event.objects.get(id=event.id)
    new_event.pk = None
    new_event.name = "{} #{}".format(name, number)
    new_event.page_title = "{} #{}".format(name, number)
    new_event.date = date
    new_event.is_page_live = False
    new_event.attendees_count = None
    new_event.applicants_count = None
    new_event.save()

    # Edit team and previous email or keep them
    if new_team:
        # Create a new team with a new main organizer
        main_organizer = get_main_organizer()
        team = get_team(main_organizer)
        members = create_users(team, new_event)
        new_event.main_organizer = members[0]
        # Edit previous email account
        event.email = "{}{:02d}{}@djangogirls.org".format(
            event.email.split('@')[0], event.date.month, event.date.year)
    else:
        new_event.team = organizers

    # Change the title and url of previous event page
    event.page_title = "{} #{}".format(name, number - 1)
    event.page_url = "{}{}".format(event.page_url, number - 1)
    event.save()

    # Copy all EventPageContent objects
    for obj in event.content.all():
        new_content = obj
        new_content.id = None
        new_content.event = new_event
        new_content.save()

        new_content.coaches = obj.coaches.all()
        new_content.sponsors = obj.sponsors.all()

    # Copy all EventPageMenu objects
    for obj in event.menu.all():
        new_obj = obj
        new_obj.pk = None
        new_obj.event = new_event
        new_obj.save()

    # Brag on Slack
    brag_on_slack_bang(new_event.city, new_event.country, new_event.team.all())

    click.echo(
        click.style(
            "Website is ready here: https://djangogirls.org/{0}".format(
                new_event.page_url),
            bold=True,
            fg="green"))
    click.echo("Congrats on yet another event!")
Esempio n. 21
0
def proxy_image(url):
    referer = get_referer_of_url(url)
    token = encode_image_url(url, referer)
    click.echo(token)
def status(id, details):
    """Show (current) import session(s) info"""
    if not id:

        massimports = Massimport.objects.order_by('status').all()

        tpl = '''{id}\t{status}\t{num_files}\t{username}\t{directory}'''

        click.secho(
            '--------------------------------------------------------------------',
            bold=True)
        click.secho('ID\tstatus\tfiles\tuser\tdirectory\t', bold=True)
        click.secho(
            '--------------------------------------------------------------------',
            bold=True)

        for item in massimports:
            click.echo(
                tpl.format(
                    id=item.pk,
                    status=item.get_status_display(),
                    username=item.user,
                    num_files=item.files.count(),
                    directory=item.directory,
                ))

        click.echo('')

    else:

        try:
            massimport = Massimport.objects.get(pk=id)
        except Massimport.DoesNotExist as e:
            click.secho(
                'Massimport session with id: {} does not exist.'.format(id),
                bold=True,
                fg='red')
            return

        massimport.update()

        if not details:

            tpl = '''{}:    \t{}'''

            click.secho(
                '--------------------------------------------------------------------',
                bold=True)
            click.secho('Status ({})\tcount'.format(id), bold=True)
            click.secho(
                '--------------------------------------------------------------------',
                bold=True)

            for status in MassimportFile.STATUS_CHOICES:
                count = massimport.files.filter(status=status[0]).count()
                if count:
                    click.echo(tpl.format(status[1], count))

            click.secho(
                '--------------------------------------------------------------------',
                bold=True)
            click.secho(
                ('Total:    \t{}'.format(massimport.files.all().count())),
                bold=True)
            click.echo('')

            return

        if details:

            from importer.models import ImportFile

            status_id = getattr(ImportFile,
                                'STATUS_{}'.format(details.upper()), 0)
            qs = massimport.files.filter(status=status_id)

            tpl = '''{}:    \t{}'''

            click.secho(
                '--------------------------------------------------------------------',
                bold=True)
            click.secho('{} ({})\tcount'.format(details, id), bold=True)
            click.secho(
                '--------------------------------------------------------------------',
                bold=True)

            for item in qs:
                click.echo(tpl.format(item, item.import_file.media))

            click.secho(
                '--------------------------------------------------------------------',
                bold=True)
            click.secho(('Total:    \t{}'.format(qs.count())), bold=True)
            click.echo('')
Esempio n. 23
0
def command(short):
    """Creates new Django Girls event"""
    # Basics
    (city, country, date, url, event_email) = get_basic_info()

    # Main organizer
    main_organizer = get_main_organizer()

    # Team
    team = get_team(main_organizer)

    click.echo("OK! That's it. Now I'll create your event.")

    # Event and EventPage objects
    name = 'Django Girls ' + city
    latlng = get_coordinates_for_city(city, country)
    email = event_email + '@djangogirls.org'
    form = EventForm({
        'city': city,
        'country': country,
        'date': date,
        'email': email,
        'latlng': latlng,
        'name': name,
        'page_title': name,
        'page_url': url})
    if not form.is_valid():
        click.secho(
            "OOPS! Something went wrong!", fg='red')
        for field, errors in form.errors.items():
            for error in errors:
                click.secho(
                    "    {field:10} {error}".format(error=error, field=field),
                    fg='red')
        return
    event = form.save()

    # Create users
    members = create_users(team, event)
    event.main_organizer = members[0]

    # Add random cover picture
    event.set_random_cover()

    event.save()

    click.secho(
        "Website is ready here: http://djangogirls.org/{0}".format(url),
        fg='green')
    click.echo(DELIMITER)

    click.secho("Ok, now follow this:", fg='black', bg='green')
    click.echo("1. Create an email account for the event.")
    click.echo("2. Send e-mail with instructions to a team!")
    click.echo(DELIMITER)
    click.secho(
        "This is a ready, filled out mail to sent to organizers:", fg='green')

    click.echo("SUBJECT: Django Girls {} setup".format(event.city))
    click.echo("TO: {}, {}, [email protected]".format(
        ', '.join([x.email for x in members]),
        event.email
    ))
    click.echo("BODY:")

    if short:
        click.echo(render_to_string('emails/setup-short.txt', {
            'event': event,
        }))
    else:
        click.echo(render_to_string('emails/setup.txt', {
            'event': event,
            'email_password': '******',
            'settings': settings
        }))

    brag_on_slack_bang(city, country, members)
Esempio n. 24
0
def command():
    """Generate "Next events" section for the Dispatch."""
    now = timezone.now()
    raw_dispatch_date = click.prompt(click.style(
        "What is the date of the previous Dispatch? (Format: YYYY-MM-DD)",
        bold=True, fg='yellow'))
    dispatch_date = (datetime.datetime
                     .strptime(raw_dispatch_date, "%Y-%m-%d")
                     .replace(tzinfo=datetime.timezone.utc))

    # Get the events that happened since the last Dispatch.
    click.echo(click.style("PREVIOUS EVENTS", bold=True))

    previous_events = Event.objects.filter(
        date__gt=dispatch_date.strftime("%Y-%m-%d"),
        date__lt=now.strftime("%Y-%m-%d"))
    result_previous = generate_html_content(previous_events)

    num_events = len(result_previous)

    if result_previous:
        click.echo(
            "%s event%s happened since the last dispatch: " %
            (apnumber(num_events), "s" if num_events > 1 else "") +
            ", ".join(result_previous) + ".")
    else:
        click.echo("No event took place since the last Dispatch.")

    # Get the events that were created since the last Dispatch.

    click.echo(click.style("NEXT EVENTS", bold=True))
    next_events = Event.objects.all().filter(
        created_at__range=(dispatch_date, now)).order_by("date")

    sorted_event = groupby(next_events, key=lambda event: event.date.month)

    if next_events:
        for month, events in sorted_event:
            month_list = generate_html_content(events)
            click.echo(calendar.month_name[
                       month] + ": " + ", ".join(month_list) + "." + "<br />")
    else:
        click.echo(
            "There's no new event to announce. Don't forget to check our "
            "<a href='https://djangogirls.org/events/'>website</a> to get a "
            "list of our events planned for the next few months.")

    # Get the events with open registration.

    click.echo("OPEN REGISTRATION")
    open_events = Event.objects.all().filter(
        form__open_from__lte=now,
        form__open_until__gte=now)
    result_open = generate_html_content(open_events)

    if result_open:
        click.echo("Registrations are still open for: " +
                   ", ".join(result_open) + ".")
    else:
        click.echo("There's no event with open registration.")
Esempio n. 25
0
def command(short):
    """Creates new Django Girls event"""
    # Basics
    (city, country, date, url, event_mail) = get_basic_info()

    # Main organizer
    main_organizer = get_main_organizer()

    # Team
    team = get_team(main_organizer)

    click.echo("OK! That's it. Now I'll create your event.")

    # Event and EventPage objects
    name = 'Django Girls ' + city
    latlng = get_coordinates_for_city(city, country)
    mail = event_mail + '@djangogirls.org'
    event = Event.objects.create(name=name,
                                 city=city,
                                 country=country,
                                 latlng=latlng,
                                 email=mail,
                                 date=date,
                                 is_on_homepage=False,
                                 page_url=url,
                                 page_title=name)

    # Create users
    members = create_users(team, event)
    event.main_organizer = members[0]
    event.save()

    # Default content
    add_default_content(event)
    add_default_menu(event)

    click.secho(
        "Website is ready here: http://djangogirls.org/{0}".format(url),
        fg='green')
    click.echo(DELIMITER)

    click.secho("Ok, now follow this:", fg='black', bg='green')
    click.echo(
        "1. Find a photo of a city with CC license on Flickr. Download it.")
    click.echo(
        "2. Go here: http://djangogirls.org/admin/core/event/{0}/".format(
            event.id))
    click.echo(
        "3. Upload a photo of city, add credits and tick 'is on homepage' checkbox. Save."
    )
    click.echo("4. Send e-mail with instructions to a team!")
    click.echo(DELIMITER)
    click.secho("This is a ready, filled out mail to sent to organizers:",
                fg='green')

    click.echo("SUBJECT: Django Girls {} setup".format(event.city))
    click.echo("TO: {}, {}, [email protected]".format(
        ', '.join([x.email for x in members]), event.email))
    click.echo("BODY:")

    if short:
        click.echo(
            render_to_string('emails/setup-short.txt', {
                'event': event,
            }))
    else:
        click.echo(
            render_to_string(
                'emails/setup.txt', {
                    'event': event,
                    'email_password': '******',
                    'settings': settings
                }))

    brag_on_slack_bang(city, country, members)
def echo(text, value):
    click.echo(click.style(text, fg="green") + "{0}".format(value))
Esempio n. 27
0
def print_result(name, created, action="imported"):
    if created > 0:
        click.echo(f"{action.title()} {created} new {name}(s)")
    else:
        click.echo(f"No new {name} {action}")
Esempio n. 28
0
def list(ctx):
    for feed in models.Feed.objects.all():
        click.echo(f"{feed.id}. {feed.url} {feed.title}")
Esempio n. 29
0
def command():
    """Creates new Django Girls organizer"""
    event_id = click.prompt(click.style(
        "What's the event ID? NOT the event page ID. We want EVENT ID here",
        bold=True, fg='yellow'))
    event = Event.objects.get(id=event_id)
    click.echo("Ok, we're adding to an event in {}, {}".format(
        event.city, event.country))

    team = [get_organizer_data()]

    while click.confirm(
        click.style("Do you want to add additional team members?",
                    bold=True, fg='yellow'), default=False):
        team.append(get_organizer_data())

    click.echo("OK! That's it. Now I'll add your organizers.")

    members, members_as_list = create_users(team)

    for member in members:
        event.team.add(member)

    event.save()

    for member in members_as_list:
        if 'password' in member:
            click.echo("{} - email: {} password {}".format(
                member['first_name'], member['email'], member['password']))
        else:
            click.echo(
                "{} - email: {} already has account".format(
                    member['first_name'], member['email']))

    click.echo(DELIMITER)

    invite_team_to_slack(members)

    click.echo(DELIMITER)

    click.echo("You still need to invite people to Google Group!")
Esempio n. 30
0
def status(id, details):

    """Show (current) import session(s) info"""
    if not id:

        massimports = Massimport.objects.order_by('status').all()

        tpl = '''{id}\t{status}\t{num_files}\t{username}\t{directory}'''

        click.secho('--------------------------------------------------------------------', bold=True)
        click.secho('ID\tstatus\tfiles\tuser\tdirectory\t', bold=True)
        click.secho('--------------------------------------------------------------------', bold=True)

        for item in massimports:
            click.echo(tpl.format(
                id=item.pk,
                status=item.get_status_display(),
                username=item.user,
                num_files=item.files.count(),
                directory=item.directory,
            ))

        click.echo('')


    else:

        try:
            massimport = Massimport.objects.get(pk=id)
        except Massimport.DoesNotExist as e:
            click.secho('Massimport session with id: {} does not exist.'.format(id), bold=True, fg='red')
            return


        massimport.update()

        if not details:


            tpl = '''{}:    \t{}'''

            click.secho('--------------------------------------------------------------------', bold=True)
            click.secho('Status ({})\tcount'.format(id), bold=True)
            click.secho('--------------------------------------------------------------------', bold=True)

            for status in MassimportFile.STATUS_CHOICES:
                count = massimport.files.filter(status=status[0]).count()
                if count:
                    click.echo(tpl.format(
                        status[1],
                        count
                    ))

            click.secho('--------------------------------------------------------------------', bold=True)
            click.secho(('Total:    \t{}'.format(massimport.files.all().count())), bold=True)
            click.echo('')

            return

        if details:

            from importer.models import ImportFile

            status_id = getattr(ImportFile, 'STATUS_{}'.format(details.upper()), 0)
            qs = massimport.files.filter(status=status_id)


            tpl = '''{}:    \t{}'''

            click.secho('--------------------------------------------------------------------', bold=True)
            click.secho('{} ({})\tcount'.format(details, id), bold=True)
            click.secho('--------------------------------------------------------------------', bold=True)

            for item in qs:
                click.echo(tpl.format(item, item.import_file.media))

            click.secho('--------------------------------------------------------------------', bold=True)
            click.secho(('Total:    \t{}'.format(qs.count())), bold=True)
            click.echo('')
Esempio n. 31
0
def run(  # pylint: disable=too-many-locals
    force=False,
    start_id=None,
    end_id=None,
    color_variants=True,
    **kwargs,
):
    items = {}

    compiled_items = GameFile.objects.get(
        folder="assets/archetypes", filename="compileditems.msgpack").content

    items_query = Item.objects.all()
    if start_id is not None:
        items_query = items_query.filter(game_id__gte=start_id)

    if end_id is not None:
        items_query = items_query.filter(game_id__lte=end_id)

    click.echo("Attaching localization and images data to items...")
    with click.progressbar(
            items_query.iterator(),
            show_percent=True,
            show_pos=True,
            length=items_query.count(),
    ) as pbar:
        for item in pbar:
            pbar.label = str(item.game_id)
            pbar.render_progress()

            items[item.game_id] = item
            list_type = compiled_items[str(item.game_id)].get("listTypeName")

            if list_type:
                item.list_type = LocalizedString.objects.filter(
                    string_id=list_type).first()
            item.description = LocalizedString.objects.filter(
                string_id=f"{item.string_id}_DESCRIPTION").first()
            _create_icons(item, pbar, force, color_variants)
            item.save()

    click.echo("Purging CDN cache...")
    purge_static_cache(["items"])

    click.echo("Creating AltItems...")
    with click.progressbar(compiled_items.items()) as pbar:
        for item_id, item_data in pbar:
            item_id = int(item_id)

            if item_id in items:
                continue

            string_id = item_data["stringID"]
            if "ITEM_TYPE_ASH_RECLAIM" in string_id:
                string_id = "ITEM_TYPE_ASH_DEFAULT_BASE"

            item = Item.objects.filter(string_id=string_id).first()

            if item is not None:
                alt_item, _ = AltItem.objects.get_or_create(
                    game_id=int(item_data["id"]),
                    name=item_data["name"],
                    base_item=item)

                items[alt_item.game_id] = item

    compiled_blocks = GameFile.objects.get(
        folder="assets/archetypes", filename="compiledblocks.msgpack").content

    _blocks(compiled_blocks, items)
    _liquids(compiled_blocks, items)
Esempio n. 32
0
def command():
    """Creates new Django Girls event"""
    # Basics
    (city, country, date, url, event_mail) = get_basic_info()

    # Main organizer
    main_organizer = get_main_organizer()

    # Team
    team = get_team(main_organizer)

    click.echo("OK! That's it. Now I'll create your event.")

    # Event and EventPage objects
    name = "Django Girls " + city
    latlng = get_coordinates_for_city(city, country)
    mail = event_mail + "@djangogirls.org"
    event = Event.objects.create(
        name=name, city=city, country=country, latlng=latlng, email=mail, date=date, is_on_homepage=False
    )

    page = EventPage.objects.create(event=event, url=url, title=name)

    # Create users
    members = create_users(team, event)
    event.main_organizer = members[0]
    event.save()

    # Default content
    add_default_content(page)
    add_default_menu(page)

    click.secho("Website is ready here: http://djangogirls.org/{0}".format(url), fg="green")
    click.echo(DELIMITER)

    click.secho("Ok, now follow this:", fg="black", bg="green")
    click.echo("1. Find a photo of a city with CC license on Flickr. Download it.")
    click.echo("2. Go here: http://djangogirls.org/admin/core/event/{0}/".format(event.id))
    click.echo("3. Upload a photo of city, add credits and tick 'is on homepage' checkbox. Save.")
    click.echo("4. Send e-mail with instructions to a team!")
    click.echo(DELIMITER)
    click.secho("This is a ready, filled out mail to sent to organizers:", fg="green")

    click.echo("SUBJECT: Django Girls {} setup".format(event.city))
    click.echo("TO: {}, {}, [email protected]".format(", ".join([x.email for x in members]), event.email))
    click.echo("BODY:")
    click.echo(
        render_to_string("emails/setup.txt", {"event": event, "email_password": "******", "settings": settings})
    )

    brag_on_slack_bang(city, country, members)
def command():
    try:
        User.objects.get(email='*****@*****.**')
    except User.DoesNotExist:
        User.objects.create_superuser('*****@*****.**', 'simpl')
    click.echo("Created superuser '*****@*****.**' with password 'simpl'.")
Esempio n. 34
0
def command(short):
    """Creates new Django Girls event"""
    # Basics
    (city, country, date, url, event_email) = get_basic_info()

    # Main organizer
    main_organizer = get_main_organizer()

    # Team
    team = get_team(main_organizer)

    click.echo("OK! That's it. Now I'll create your event.")

    # Event and EventPage objects
    name = 'Django Girls ' + city
    latlng = get_coordinates_for_city(city, country)
    email = event_email + '@ng-boat.pl'
    form = EventForm({
        'city': city,
        'country': country,
        'date': date,
        'email': email,
        'latlng': latlng,
        'name': name,
        'page_title': name,
        'page_url': url
    })
    if not form.is_valid():
        click.secho("OOPS! Something went wrong!", fg='red')
        for field, errors in form.errors.items():
            for error in errors:
                click.secho("    {field:10} {error}".format(error=error,
                                                            field=field),
                            fg='red')
        return
    event = form.save()

    # Create users
    members = create_users(team, event)
    event.main_organizer = members[0]

    # Add random cover picture
    event.set_random_cover()

    event.save()

    click.secho("Website is ready here: http://ng-boat.pl/{0}".format(url),
                fg='green')
    click.echo(DELIMITER)

    click.secho("Ok, now follow this:", fg='black', bg='green')
    click.echo("1. Create an email account for the event.")
    click.echo("2. Send e-mail with instructions to a team!")
    click.echo(DELIMITER)
    click.secho("This is a ready, filled out mail to sent to organizers:",
                fg='green')

    click.echo("SUBJECT: Django Girls {} setup".format(event.city))
    click.echo("TO: {}, {}, [email protected]".format(
        ', '.join([x.email for x in members]), event.email))
    click.echo("BODY:")

    if short:
        click.echo(
            render_to_string('emails/setup-short.txt', {
                'event': event,
            }))
    else:
        click.echo(
            render_to_string(
                'emails/setup.txt', {
                    'event': event,
                    'email_password': '******',
                    'settings': settings
                }))

    brag_on_slack_bang(city, country, members)
Esempio n. 35
0
def command():
    click.echo("=== Setup Simpl API ===")
    click.echo("")

    # Deal with super users
    superusers = find_super_users()
    if not superusers:
        click.echo("We found no superusers, please set one up below")
        create_super_user()
    else:
        click.echo(
            "We found the following superusers that were already setup:")
        for u in superusers:
            click.echo(f" - {u}")
        click.echo("")
        click.echo(
            "If you would like to setup another super user for yourself run `./manage.py createsuperuser`"
        )

    click.echo("")

    # Deal with staff users
    staffusers = find_staff_users()
    if not staffusers:
        click.echo(
            "We found no staff users, you will need one of these for your model service to connect to the Simpl API"
        )
        click.echo(
            "This is typically setup as a setting `SIMPL_GAMES_AUTH` from the environment variables `SIMPL_USER` and `SIMPL_PASS`"
        )
        click.echo("")
        create_staff_user()
    else:
        click.echo(
            "We found the following staff users that are already setup:")
        for u in staffusers:
            click.echo(f" - {u}")
        click.echo("")

        if click.confirm("Would you like to setup another staff user?"):
            create_staff_user()
Esempio n. 36
0
def repair_durations(limit_range, dump_to, load_from, tolerance, log_file):
    """
    Repair/reprocess master durations.
    """
    from base.audio.fileinfo import FileInfoProcessor

    items_to_reprocess = []
    affected_playlists = []
    affected_playlist_ids = []

    # invalidate cache for Media
    invalidate_model(Media)

    if load_from:

        if limit_range:
            raise NotImplementedError('--limit-range option not allowed in combination with --load-from')

        # using `set` to remove duplicate ids
        item_ids = set([
            int(l.strip().split(',')[0]) for l in load_from.readlines() if float(l.strip().split(',')[1]) > tolerance
        ])


        click.echo('loaded {} ids from dump file'.format(len(item_ids)))

        items_to_reprocess = Media.objects.filter(pk__in=item_ids)

    else:

        # mysql does not support remote/streaming cursors
        # to save memory items are loaded from db individually
        values = Media.objects.order_by('pk').values('id').nocache()

        if limit_range:
            _limits = limit_range.split(':')
            values = values[_limits[0]:_limits[1]]

        item_ids = [i['id'] for i in values]

        with click.progressbar(item_ids, show_pos=True, width=48, label='Reprocessing {} tracks'.format(len(item_ids))) as bar:

            for item_pk in bar:

                close_old_connections()

                item = Media.objects.get(pk=item_pk)

                if item.master and item.master.path:

                    p = FileInfoProcessor(item.master.path)

                    current_duration = item.master_duration
                    new_duration = p.duration

                    try:
                        diff = abs(current_duration - new_duration)
                    except TypeError:
                        diff = 100.0

                    if diff > tolerance:
                        items_to_reprocess.append(item)

                    # add to csv log
                    if diff > tolerance and dump_to:
                        dump_to.write('{pk},{diff}\n'.format(pk=item.pk, diff=diff))
                        dump_to.flush()


    click.echo('{} tracks have differences in duration'.format(len(items_to_reprocess)))


    if click.confirm('Do you want to update/repair the durations on {} tracks?'.format(len(items_to_reprocess))):

        base_url = 'http://{}'.format(Site.objects.get_current().domain)


        tpl = u'''id: {id} - "{name}"
{url}
old: {current_duration} new: {new_duration} diff: {diff}
        '''


        tpl_log = u'{ct},{pk},{type},{current_duration},{new_duration},{diff},{url}\n'

        # write column header
        if log_file:
            log_file.write(tpl_log.format(
                ct='content-type',
                pk='id',
                url='url',
                type='type',
                #
                current_duration='old_duration',
                new_duration='new_duration',
                diff='diff',
            ))


        # loop affected media, fix durations, get playlist appearances & print/log info
        for item in items_to_reprocess:

            p = FileInfoProcessor(item.master.path)

            current_duration = item.master_duration
            new_duration = p.duration

            try:
                diff = current_duration - new_duration
            except TypeError:
                diff = '-'


            click.echo(tpl.format(
                id=item.id,
                name=item.name,
                url=base_url + item.get_absolute_url(),
                #
                current_duration=current_duration,
                new_duration=new_duration,
                diff=diff
            ))

            if log_file:
                log_file.write(tpl_log.format(
                    ct='media',
                    pk=item.pk,
                    url=base_url + item.get_absolute_url(),
                    type=item.get_mediatype_display(),
                    #
                    current_duration=current_duration,
                    new_duration=new_duration,
                    diff=diff
                ))
                log_file.flush()

            for p in item.get_appearances():
                if not p.pk in affected_playlist_ids:
                    affected_playlist_ids.append(p.pk)
                    # we need to store the 'current' value of the duration
                    affected_playlists.append({
                        'obj': p,
                        'current_duration': p.get_duration()
                    })

            # update media duration
            Media.objects.filter(pk=item.pk).update(master_duration=new_duration)
            invalidate_obj(item)


        # loop playlists & print/log info
        for item in affected_playlists:

            invalidate_obj(item['obj'])

            current_duration = float(item['current_duration']) / 1000
            new_duration = float(item['obj'].get_duration()) / 1000

            try:
                diff = current_duration - new_duration
            except TypeError:
                diff = '-'

            click.echo(tpl.format(
                id=item['obj'].id,
                name=item['obj'].name,
                url=base_url + item['obj'].get_absolute_url(),
                #
                current_duration=current_duration,
                new_duration=new_duration,
                diff=diff
            ))

            if log_file:
                log_file.write(tpl_log.format(
                    ct='playlist',
                    pk=item['obj'].pk,
                    url=base_url + item['obj'].get_absolute_url(),
                    type=item['obj'].get_type_display(),
                    #
                    current_duration=current_duration,
                    new_duration=new_duration,
                    diff=diff
                ))
                log_file.flush()

            # update playlist duration
            Playlist.objects.filter(pk=item['obj'].pk).update(duration=new_duration * 1000)
            invalidate_obj(item)
Esempio n. 37
0
def command():
    click.echo(testapp2.FLAG, nl=False)
Esempio n. 38
0
def command():
    facts = compute_dataset_facts(Agency, Stop, settings.MD_KEY)
    for fact in facts:
        click.echo(fact)
Esempio n. 39
0
def command(create, delete, update, folder):
    if delete:
        click.secho("deleting existing results...")
        Result.objects.all().delete()

    missing = []
    filenames = Path(folder).glob("*.json")
    for filename in filenames:
        data = json.loads(filename.read_text())

        date = parse(data["date"].split("@")[0])
        did = data["did"]
        distance = data["distance"]
        formattime = data["formattime"]
        gender = data["gender"]
        gender_place = data["gender_place"]
        place = data["place"]

        place_data = []

        if gender_place in [1, 2, 3]:
            if gender.upper() in ["F", "W"]:
                if place in [1, 2, 3]:
                    place_data.append(
                        titlecase(f"{num2words(place, ordinal=True)} Place Overall.")
                    )
                place_data.append(
                    titlecase(f"{num2words(gender_place, ordinal=True)} Place Womens.")
                )
            elif gender.upper() in ["M"]:
                place_data.append(
                    titlecase(f"{num2words(gender_place, ordinal=True)} Place Mens.")
                )
            else:
                place_data.append(
                    titlecase(f"{num2words(gender_place, ordinal=True)} Place Overall.")
                )

        if len(place_data):
            place_data = " ".join(place_data)
        else:
            place_data = ""

        try:
            title = f"{data['title']} {date.strftime('%Y')}"
            race_defaults = {
                "slug": slugify(title),
                "start_datetime": date,
                "title": title,
            }
            if create:
                race, _ = Race.objects.get_or_create(
                    ultrasignup_id=did,
                    defaults=race_defaults,
                )
            elif update:
                race, _ = Race.objects.update_or_create(
                    ultrasignup_id=did,
                    defaults=race_defaults,
                )
            else:
                race = Race.objects.get(ultrasignup_id=did)

            # TODO: Fix slugs
            race_type, _ = RaceType.objects.get_or_create(name=distance)
            # race_type, _ = RaceType.objects.get_or_create(
            #     slug=slugify(distance), defaults={"name": distance}
            # )

            racer, _ = Racer.objects.update_or_create(
                first_name=data["firstname"],
                last_name=data["lastname"],
                defaults={
                    "city": data["city"],
                    "country": "USA",
                    "gender": Racer.MALE if data["gender"] == "M" else Racer.FEMALE,
                    "state": data["state"],
                },
            )

            if len(formattime) in [1, 2]:
                formattime = ""
            elif len(formattime) == 7:
                formattime = f"0{formattime}"

            try:
                result, _ = Result.objects.update_or_create(
                    race=race,
                    racer=racer,
                    race_type=race_type,
                    defaults={
                        "bib_number": data["bib"] or None,
                        "dnf": data["status"] == 3,
                        "dns": data["status"] == 2,
                        "import_data": data,
                        "place": place_data,
                        # "race_type": race_type,
                        "time": formattime,
                    },
                )
            except Result.MultipleObjectsReturned as e:
                click.secho(f"{e}", bold=True, fg="red")
                click.echo(f"race: {race}")
                click.echo(f"race_type: {race_type}")
                click.echo(f"racer: {racer}")

        except (Race.DoesNotExist, Race.MultipleObjectsReturned) as e:
            ultrasignup_url = f"https://ultrasignup.com/results_event.aspx?did={did}"
            click.secho(
                f"{e}:{ultrasignup_url}",
                bold=True,
                fg="red",
            )
            if ultrasignup_url not in missing:
                missing.append(ultrasignup_url)

    for filename in missing:
        click.echo(f"{filename}")
Esempio n. 40
0
def command(url, email, password, game):
    """
    Verify SIMPL API deployment is in good working order.
    """

    ANY_FAILURES = False

    click.echo(click.style("=== Verifying SIMPL API at: ", fg='green') + url)

    # Check DNS
    try:
        click.secho("- Checking DNS... ", fg='green', nl=False)
        check_dns(url)
        click.secho('OK', fg='green')
    except Exception:
        ANY_FAILURES = True
        click.secho('FAILED', fg='red')

    # Check HTTPS
    try:
        click.secho("- Checking HTTP/HTTPS Connectivity... ",
                    fg='green',
                    nl=False)
        check_http_connection(url)
        click.secho('OK', fg='green')
    except Exception:
        ANY_FAILURES = True
        click.secho('FAILED', fg='red')

    # Check admin and API if we're supposed to
    click.secho("- Checking admin login... ", fg='green', nl=False)

    try:
        check_admin_login(url, email, password)
        click.secho('OK', fg='green')
    except Exception:
        ANY_FAILURES = True
        click.secho('FAILED', fg='red')

    # Check API endpoint
    try:
        click.secho("- Checking API endpoints... ", fg='green', nl=False)
        check_game_api(url, email, password)
        click.secho('OK', fg='green')
    except Exception:
        ANY_FAILURES = True
        click.secho('FAILED', fg='red')

    # Check API for Game
    try:
        click.secho("- Checking for game '{}' in API... ".format(game),
                    fg='green',
                    nl=False)
        check_for_game_in_api(url, game, email, password)
        click.secho('OK', fg='green')
    except Exception:
        ANY_FAILURES = True
        click.secho('FAILED', fg='red')

    # Exit with a non-zero exit code on any failures
    if ANY_FAILURES:
        click.secho("=== NOT OK ===", fg='red')
        sys.exit(1)
    else:
        click.secho("=== ALL OK YAY! ===", fg='green')
Esempio n. 41
0
def echo_report():
    click.echo(f'Assets: {stale_assets().count()}')
    click.echo('AssetBlobs: Coming soon')
    click.echo('Uploads: Coming soon')
    click.echo('S3 Blobs: Coming soon')
Esempio n. 42
0
def subcmd2():
    click.echo('SUB2')
Esempio n. 43
0
def subcmd1():
    click.echo("SUB1")
Esempio n. 44
0
def subcmd1():
    click.echo('SUB1')
Esempio n. 45
0
def command(short):
    """Creates new Django Girls event"""
    # Basics
    (city, country, date, url, event_email) = get_basic_info()

    # Main organizer
    main_organizer = get_main_organizer()

    # Team
    team = get_team(main_organizer)

    click.echo("OK! That's it. Now I'll create your event.")

    # Event and EventPage objects
    name = 'Django Girls ' + city
    latlng = get_coordinates_for_city(city, country)
    email = event_email + '@djangogirls.org'
    form = EventForm({
        'city': city,
        'country': country,
        'date': date,
        'email': email,
        'latlng': latlng,
        'name': name,
        'page_title': name,
        'page_url': url
    })
    if not form.is_valid():
        click.secho("OOPS! Something went wrong!", fg='red')
        for field, errors in form.errors.items():
            for error in errors:
                click.secho("    {field:10} {error}".format(error=error,
                                                            field=field),
                            fg='red')
        return
    event = form.save()

    # Create users
    members = create_users(team, event)
    event.main_organizer = members[0]
    event.save()

    click.secho(
        "Website is ready here: http://djangogirls.org/{0}".format(url),
        fg='green')
    click.echo(DELIMITER)

    click.secho("Ok, now follow this:", fg='black', bg='green')
    click.echo(
        "1. Find a photo of a city with CC license on Flickr. Download it.")
    click.echo(
        "2. Go here: http://djangogirls.org/admin/core/event/{0}/".format(
            event.id))
    click.echo(
        "3. Upload a photo of city, add credits and tick 'is on homepage' checkbox. Save."
    )
    click.echo("4. Send e-mail with instructions to a team!")
    click.echo(DELIMITER)
    click.secho("This is a ready, filled out mail to sent to organizers:",
                fg='green')

    click.echo("SUBJECT: Django Girls {} setup".format(event.city))
    click.echo("TO: {}, {}, [email protected]".format(
        ', '.join([x.email for x in members]), event.email))
    click.echo("BODY:")

    if short:
        click.echo(
            render_to_string('emails/setup-short.txt', {
                'event': event,
            }))
    else:
        click.echo(
            render_to_string(
                'emails/setup.txt', {
                    'event': event,
                    'email_password': '******',
                    'settings': settings
                }))

    brag_on_slack_bang(city, country, members)
Esempio n. 46
0
def command(instance):
    # Just print some things which shall not be found in the output
    click.echo(instance, nl=False)
Esempio n. 47
0
def command():
    """Generate "Next events" section for the Dispatch."""

    now = timezone.now()
    raw_dispatch_date = click.prompt(click.style(
        "What is the date of the previous Dispatch? (Format: YYYY-MM-DD)",
        bold=True, fg='yellow'))
    dispatch_date = (datetime.datetime
                     .strptime(raw_dispatch_date, "%Y-%m-%d")
                     .replace(tzinfo=datetime.timezone.utc))

    # Get the events that happened since the last Dispatch.
    click.echo(click.style("PREVIOUS EVENTS", bold=True))

    previous_events = Event.objects.filter(
        date__gt=dispatch_date.strftime("%Y-%m-%d"),
        date__lt=now.strftime("%Y-%m-%d"),
        eventpage__isnull=False)
    result_previous = generate_html_content(previous_events)

    num_events = len(result_previous)

    if result_previous:
        click.echo(
            "%s event%s happened since the last dispatch: " %
            (apnumber(num_events), "s" if num_events > 1 else "") +
            ", ".join(result_previous) + ".")
    else:
        click.echo("No event took place since the last Dispatch.")

    # Get the events that were created since the last Dispatch.

    click.echo(click.style("NEXT EVENTS", bold=True))
    next_events = Event.objects.all().filter(
        created_at__range=(dispatch_date, now), eventpage__isnull=False)

    sorted_event = groupby(next_events, key=lambda event: event.date.month)

    if next_events:
        for month, events in sorted_event:
            month_list = generate_html_content(events)
            click.echo(calendar.month_name[
                       month] + ": " + ", ".join(month_list) + "." + "<br />")
    else:
        click.echo(
            "There's no new event to announce. Don't forget to check our "
            "<a href='https://djangogirls.org/events/'>website</a> to get a "
            "list of our events planned for the next few months.")

    # Get the events with open registration.

    click.echo("OPEN REGISTRATION")
    open_events = Event.objects.all().filter(
        eventpage__form__open_from__lte=now,
        eventpage__form__open_until__gte=now,
        eventpage__isnull=False)
    result_open = generate_html_content(open_events)

    if result_open:
        click.echo("Registrations are still open for: " +
                   ", ".join(result_open) + ".")
    else:
        click.echo("There's no event with open registration.")
Esempio n. 48
0
def main():
    click.echo("group_command")
Esempio n. 49
0
def command():
    _thumbs()
    _missing()

    click.echo("Purging CDN cache...")
    purge_static_cache(["worlds"])
Esempio n. 50
0
def command(ctx):
    assert isinstance(ctx.verbosity, int)
    click.echo(ctx.verbosity, nl=False)
def command(slug):
    """Print count of game's model objects."""

    phase_count = models.Phase.objects.filter(game__slug=slug).count()
    role_count = models.Role.objects.filter(game__slug=slug).count()
    run_count = models.Run.objects.filter(game__slug=slug).count()

    runuser_count = models.RunUser.objects.filter(run__game__slug=slug).count()
    world_count = models.World.objects.filter(run__game__slug=slug).count()

    runuser_scenario_count = models.Scenario.objects.filter(
        runuser__run__game__slug=slug).count()
    world_scenario_count = models.Scenario.objects.filter(
        world__run__game__slug=slug).count()
    scenario_count = runuser_scenario_count + world_scenario_count

    runuser_period_count = models.Period.objects.filter(
        scenario__runuser__run__game__slug=slug).count()
    world_period_count = models.Period.objects.filter(
        scenario__world__run__game__slug=slug).count()
    period_count = runuser_period_count + world_period_count

    runuser_decision_count = models.Decision.objects.filter(
        period__scenario__runuser__run__game__slug=slug).count()
    world_decision_count = models.Decision.objects.filter(
        period__scenario__world__run__game__slug=slug).count()
    decision_count = runuser_decision_count + world_decision_count

    runuser_result_count = models.Result.objects.filter(
        period__scenario__runuser__run__game__slug=slug).count()
    world_result_count = models.Result.objects.filter(
        period__scenario__world__run__game__slug=slug).count()
    result_count = runuser_result_count + world_result_count

    click.echo("Phase count: {0}".format(phase_count))
    click.echo("Role count: {0}".format(role_count))
    click.echo("Run count: {0}".format(run_count))
    click.echo("RunUser count: {0}".format(runuser_count))
    click.echo("World count: {0}".format(world_count))
    click.echo("Scenario count: {0}".format(scenario_count))
    click.echo("Period count: {0}".format(period_count))
    click.echo("Decision count: {0}".format(decision_count))
    click.echo("Result count: {0}".format(result_count))
Esempio n. 52
0
def label(query):

    click.echo(u'query: {}'.format(query))

    from datetime import date

    from elasticsearch_dsl import FacetedSearch, TermsFacet, DateHistogramFacet

    from alibrary.documents import LabelDocument

    class LabelSearch(FacetedSearch):
        doc_types = [LabelDocument]
        # fields that should be searched
        fields = [
            'tags',
            'name',
        ]

        facets = {
            # use bucket aggregations to define facets
            #'tags': TermsFacet(field='tags', size=5),
            'country': TermsFacet(field='country'),
            #'publishing_frequency': DateHistogramFacet(field='published_from', interval='month')
        }

        # def search(self, *args, **kwargs):
        #     # override methods to add custom pieces
        #     # s = super().search()
        #     s = super(BlogSearch, self).search(*args, **kwargs)
        #     return s.filter('range', publish_from={'lte': 'now/h'})

        def query(self, search, query):
            """
            Add query part to ``search``.

            Override this if you wish to customize the query used.
            """
            if query:
                return search.update_from_dict(query)
            return search

    #bs = BlogSearch('python web', {'publishing_frequency': date(2015, 6)})

    _query = {
        "query": {
            "match": {
                "autocomplete": {
                    "query": query,
                    "fuzziness": "AUTO",
                    "operator": "and"
                }
            }
        },
        # "highlight" : {
        #     "fields" : {
        #         "name" : {}
        #     }
        # }
    }

    s = LabelSearch(query=_query, filters={'country': ['CH', 'JP']})
Esempio n. 53
0
def ip2city(ctx, ipaddress):
    from mautic.utils import resolve_ipaddress
    click.echo(resolve_ipaddress(ipaddress))
Esempio n. 54
0
def command(verbosity):
    assert isinstance(verbosity, int)
    click.echo(verbosity, nl=False)
def view_report_contents(reports_list):
    report_name = click.prompt('Which report would you like to display?')
    # get report ID
    check = False
    report_id = 0
    for r in reports_list:
        if r['report_title'] == report_name:
            report_id = r['report_id']
            check = True
    if check is False:
        click.echo(
            'No existing report with that name. Please enter another report.')
        view_report_contents(reports_list)
    else:
        # get report contents - CHANGE URL TO HEROKU AFTER DEVELOPMENT
        r = requests.post(
            'http://afternoon-fortress-38321.herokuapp.com/fda_view_report_contents/',
            {'report_id': report_id})
        if r.status_code == 200:
            json_str = r.text
            r_info = json.loads(json_str)
            report_info = r_info['report_info']
            # display report contents
            click.echo('Title: ' + report_info['title'])
            click.echo('Owner: ' + report_info['owner'])
            click.echo('Short Description: ' + report_info['short_desc'])
            click.echo('Summary: ' + report_info['long_desc'])
            click.echo('Shared With: ' + report_info['shared_with'])
            click.echo('Created: ' + report_info['timestamp'])

            click.echo('Files: ')
            for r in report_info['files']:
                click.echo(r)

            if report_info['files'] == []:
                if click.confirm(
                        "Would you like to view another report's contents?"):
                    view_report_contents(reports_list)
                else:
                    click.echo('Goodbye then.')
                    exit()
            else:
                check_download(report_info['files'], report_id, reports_list,
                               report_info['files_encrypted'])
        elif r.status_code == 404:
            click.echo('You do not currently have any reports. Goodbye.')
        else:
            click.echo('Error. Please contact site manager.')
            exit()