def dislike(ecocup): username = session["username"] like = Like.query.filter_by(user=username, ecocup=ecocup).first() if like is None: like = Like(user=username, ecocup=ecocup, valeur=-1) db.session.add(like) else: like.valeur = -1 ecocup = Ecocup.query.get(ecocup) if ecocup is None: return jsonify({"error": True}) db.session.commit() ecocup.appreciation = sum(map(lambda l: l.valeur, Like.query.filter_by(ecocup=ecocup.id).all())) db.session.commit() return jsonify({"appreciation": ecocup.appreciation, "error": False})
def dislike(ecocup): username = session["username"] like = Like.query.filter_by(user=username, ecocup=ecocup).first() if like is None: like = Like(user=username, ecocup=ecocup, valeur=-1) db.session.add(like) else: like.valeur = -1 ecocup = Ecocup.query.get(ecocup) if ecocup is None: return jsonify({"error": True}) db.session.commit() ecocup.appreciation = sum( map(lambda l: l.valeur, Like.query.filter_by(ecocup=ecocup.id).all())) db.session.commit() return jsonify({"appreciation": ecocup.appreciation, "error": False})
def like(good, value=1): like_item = Like.query.filter_by(user=session["username"], good=good).first() if like_item is None: like_item = Like(user=session["username"], good=good, valeur=1) db.session.add(like_item) else: like_item.valeur = value good = Good.query.get(good) if good is None: return jsonify({"error": True}) db.session.commit() good.appreciation = sum( map(lambda l: l.valeur, Like.query.filter_by(good=good.id).all())) db.session.commit() return jsonify({"appreciation": good.appreciation, "error": False})