Example #1
0
def submission_process():
    client = SubmissionsTrelloClient()
    list_id = TrelloList().first(list_symbolic_name="HOWDOESTHISWORK").list_id
    how_does_this_work_list = client.board.get_list(list_id)

    return render_template(
        "submission_process.html",
        how_does_this_work_cards=how_does_this_work_list.list_cards())
Example #2
0
def submit():
    """Submission form page.

    Renders the submission application form and handles form POSTs as well.

    Returns:
        render_template: if page is being called by GET, or form had errors
        redirect: when form is successfully ingested (this redirects and clears form)

    Todo:
        * add Title to Submission object (waiting on update to model)
        * need simple notification for successful form POST, currently no feedback
    """
    form = SubmissionForm()

    if form.validate_on_submit():
        client = SubmissionsTrelloClient()
        labels = client.labels

        card = client.new_submissions_list.add_card(
            name=form.data["title"],
            desc=f"""#DESCRIPTION
{form.data['description']}

#PITCH
{form.data['pitch']}""",
            labels=[
                labels[form.data["format"]], labels[form.data["audience"]]
            ],
            position="bottom",
            assign=[current_app.config["TRELLO_ASSIGNEE"]],
        )

        submission = Submission().create(
            title=form.data["title"],
            email=form.data["email"],
            card_id=card.id,
            card_url=card.url,
            description=form.data["description"],
            pitch=form.data["pitch"],
            notes=form.data["notes"],
        )

        # message Celery to create the webhook
        create_hook.apply_async(args=[submission.id, submission.card_id])

        # message Celery to fetch the card email address
        extract_card_email.apply_async(args=[submission.id])

        # reset form by redirecting back and apply url params
        return redirect(
            url_for("bp.submit", success=1, id=card.id, url=card.url))

    return render_template("submit.html", form=form)
Example #3
0
def create_hook(_id, card):
    """Create Webhook for Trello Card.

    When a card is created after a submission, we need to fix it with a webhook back to  our app.

    Args:
        _id (int): the submission id
        card(str): the trello id for the card

    Todo:
        * No Exception handling!
        * should this handle submission not found?
    """
    client = SubmissionsTrelloClient()
    submission = Submission().get_by_id(_id)
    webhook = client.create_hook(current_app.config["TRELLO_HOOK"], card)
    Submission().update(submission, hook=webhook.id)

    # send confirmation email
    send_email.apply_async(
        args=[submission.id,
              Status(submission.status).name.lower()])
Example #4
0
def init_labels():
    """Populates a Trello board with the default labels."""
    client = SubmissionsTrelloClient()
    board = client.board
    all_label_names = set(map(lambda x: x.name, board.get_labels()))

    for default_labels_by_category in app.config[
            "DEFAULT_TRELLO_LABELS"].values():
        for label in default_labels_by_category.values():
            default_caption = label["default_caption"]

            if default_caption not in all_label_names:
                click.echo(f' * Adding label "{default_caption}"...')
                board.add_label(default_caption, label["default_color"])
            else:
                click.echo(f' * "{default_caption}" label already exists...')

    # all done
    click.secho(" * DONE", fg="green")
Example #5
0
def init_lists():
    """Populates a Trello board with the default lists."""
    client = SubmissionsTrelloClient()
    board = client.board

    if not board:
        click.secho("TRELLO_BOARD must be specified in the app configuration.",
                    fg="red")
        sys.exit(1)

    # We iterate the list in reverse order because by default the Trello client inserts new lists
    # at the beginning.  So in a sense, we need to create them from right-to-left.
    for default_list_options in reversed(app.config["DEFAULT_TRELLO_LISTS"]):

        default_list_name = default_list_options["name"]
        default_list_caption = default_list_options["default_caption"]

        # Verity that this list is already in our database and that it points to a valid list on
        # the trello board.
        local_list = None
        matching_lists = TrelloList().find(
            list_symbolic_name=default_list_name).all()

        if matching_lists:
            local_list = matching_lists[0]

            # Verify that this list ID is on the trello board
            try:
                trello_list = board.get_list(local_list.list_id)

                # Reopen the list if it was accidentally closed.
                if trello_list.closed:
                    trello_list.open()

            except ResourceUnavailable:
                trello_list = None

            if trello_list:
                # All good.
                click.echo(
                    f' * "{default_list_name}" list present in both database and Trello.'
                )
                continue

        # No entry or a mismatched ID in the database.  See if the list already exists on the
        # board (with the default caption).
        for existing_list in board.open_lists():
            if existing_list.name == default_list_caption:
                # There it is!
                click.echo(
                    f' * Found existing Trello list for "{default_list_name}"...'
                )
                trello_list = existing_list
                break
        else:
            # No matching trello list found.  Create it.
            click.echo(f' * Creating Trello list for "{default_list_name}"...')
            trello_list = board.add_list(default_list_caption)

        if local_list:
            # Just need to update the local entry.
            click.echo(
                f' * Updating list ID in database for "{default_list_name}"...'
            )

            local_list.list_id = trello_list.id
            TrelloList().save(local_list)
        else:
            # Need to create a new local entry.
            click.echo(
                f' * Adding list ID to database for "{default_list_name}"...')

            TrelloList().create(list_symbolic_name=default_list_name,
                                list_id=trello_list.id)

    # all done
    click.secho(" * DONE", fg="green")