Exemplo n.º 1
0
 def post(self):
     liked = request.form.getlist("liked[]")
     hated = request.form.getlist("hated[]")
     user = users.get_current_user()
     key = user.user_id()
     saved_names = SavedNames.get_or_insert(key, user=key)
     saved_names.liked = liked
     saved_names.hated = hated
     saved_names.put()
     return jsonify(saved_names.to_dict())
Exemplo n.º 2
0
def list_names():
    """List all liked names for all users."""
    all_saved_names = SavedNames.query().fetch(100)
    me = users.get_current_user()
    if me:
        me = me.user_id()
        my_saved_names = filter(lambda x: x.user == me, all_saved_names)
    else:
        my_saved_names = []
    if len(my_saved_names):
        my_saved_names = my_saved_names[0]
    else:
        my_saved_names = {"liked": [], "hated": []}
    counter = Counter()
    for saved_names in all_saved_names:
        for name in saved_names.liked:
            counter[name] += 1
    top_names = counter.most_common(100)
    return render_template(
        "list_names.html", all_saved_names=all_saved_names, top_names=top_names, my_saved_names=my_saved_names
    )
Exemplo n.º 3
0
 def get(self):
     user = users.get_current_user()
     key = user.user_id()
     saved_names = SavedNames.get_or_insert(key, user=key)
     return jsonify(saved_names.to_dict())