Example #1
0
def key_products(profile_id):

    # products are loaded individually below
    profile = get_user_for_response(profile_id, request, include_products=False)
    resp = []
    if request.method == "GET":
        markup = Markup(profile_id, False)  # profile_id must be a slug...

        board = Pinboard.query.filter_by(profile_id=profile.id).first()
        if board is None:
            board = pinboard.save_new_board(profile.id)

        show_keys = [
            # for rendering biblio
            "biblio",
            "embed_markup",

            "_tiid",
            "tiid",
            "markup",
            "genre",
            "genre_icon"
        ]
        tiids = [address[1] for address in board.contents["one"]]
        products = get_products_from_tiids(tiids)
        for my_product in products:
            my_product_dict = my_product.to_markup_dict(markup, show_keys=show_keys)
            resp.append(my_product_dict)

    elif request.method == 'POST':
        products = request.json["contents"]
        id_tuples = [('product', p["_tiid"]) for p in products]
        resp = {"resp": pinboard.set_key_products(profile.id, id_tuples)}

    return json_resp_from_thing(resp)
Example #2
0
def key_metrics(profile_id):
    resp = []
    profile = get_user_for_response(profile_id, request)

    if request.method == 'GET':
        board = Pinboard.query.filter_by(profile_id=profile.id).first()
        if board is None:
            board = pinboard.save_new_board(profile.id)

        genre_cards = []
        for genre in profile.genres:
            this_genre_cards = genre.cards
            genre_cards += this_genre_cards

        for card_address in board.contents["two"]:
            card_address_parts = card_address.split(".")
            genre_name = card_address_parts[1]
            card_type = card_address_parts[3]
            genre_products = [p for p in profile.display_products if p.genre==genre_name]
            if card_type == "engagement":
                engagement_type = card_address_parts[4]
                card = GenreEngagementSumCard(genre_products, engagement_type, profile.url_slug)
            else:
                provider = card_address_parts[4]
                interaction = card_address_parts[5]
                card = GenreMetricSumCard(genre_products, provider, interaction, profile.url_slug)
            if card.current_value:
                resp.append(card)


    elif request.method == 'POST':
        key_metrics = request.json["contents"]
        card_addresses = [card['genre_card_address'] for card in key_metrics]
        resp = {
            "resp": pinboard.set_key_metrics(profile.id, card_addresses)
        }

    return json_resp_from_thing(resp)