Пример #1
0
def tasting_ratings(id):
    # FIXME: This should only be visible once a tasting has been "published", or
    # to the admin.

    # Validate the ID.
    oid = pymongo.objectid.ObjectId(binascii.unhexlify(id))

    # Get the current object.
    current = current_app.db.tastings.find_one({ '_id' : oid })

    # Get the new JSON object.
    ratings = []
    for item in current_app.db.ratings.find({ 'tasting' : oid }):
        full_rating = current_app.get_full_rating(current, item)

        # Resolve all the labels.
        products = {}
        for v in current['variables']:
            # Get the product label.
            label = full_rating['products'][v['name']]
            product = current_app.db.products.find_one({ 'tasting' : oid,
                                                         'label' : label })
            products[v['name']] = product['name']

        ratings.append({ 'rating' : item['rating'],
                         'products' : products,
                         'user' : item['user'] })

    return flask.jsonify(result = ratings)
Пример #2
0
def full_ratings(id):
    # Validate the ID.
    oid = pymongo.objectid.ObjectId(binascii.unhexlify(id))

    # Get the current object.
    current = current_app.db.tastings.find_one({ '_id' : oid })

    # Get the new JSON object.
    ratings = []
    for item in current_app.db.ratings.find({ 'tasting' : oid }):
        full_rating = current_app.get_full_rating(current, item)

        ratings.append(full_rating)

    return flask.jsonify(result = ratings)