def process()

in app/blueprints/sell/blueprint.py [0:0]


def process(auth_context, form):
    """
    View function for processing sell requests.

    Parameters:
       auth_context (dict): The authentication context of request.
                            See middlewares/auth.py for more information.
       form (SellForm): A validated sell form.
                        See middlewares/form_validation.py for more
                        information.
    Output:
       Rendered HTML page.
    """

    product = product_catalog.Product(name=form.name.data,
                                      description=form.description.data,
                                      image=form.image.data,
                                      labels=[],
                                      price=form.price.data,
                                      created_at=int(time.time()))
    product_id = product_catalog.add_product(product)
    # Publish an event to the topic for new products.
    # Cloud Function detect_labels subscribes to the topic and labels the
    # product using Cloud Vision API upon arrival of new events.
    # Cloud Function streamEvents (or App Engine service stream-event)
    # subscribes to the topic and saves the event to BigQuery for
    # data analytics upon arrival of new events.
    eventing.stream_event(
        topic_name=PUBSUB_TOPIC_NEW_PRODUCT,
        event_type='label_detection',
        event_context={
            'product_id': product_id,
            'product_image': product.image
        })

    return redirect(url_for('product_catalog_page.display'))