def collect(pid): #判断是否收藏 if current_user.is_favorite(pid): current_user.del_favorite(pid) else: current_user.add_favorite(pid) return jsonify({'result': 'ok'})
def collect(pid): if current_user.is_favorite(pid): # 取消收藏 current_user.del_favorite(pid) else: current_user.add_favorite(pid) return jsonify({'code': 'OK'})
def search_supply(): key_word = request.args.get('key_word') page = request.args.get('page', 1, type=int) if current_user.is_authenticated: current_user.add_favorite(key_word) content = Search(mongo, key_word, PLANTS_COLLECTION, 'name', page) return render_template('main/supply.html', plants=content.cur_page, pagination=content.pagination)
def setFavorite(): result = request.get_json() requires = ["text"] if isValid(requires, result): textToFavorite = result["text"] L = [x[1:-1] for x in textToFavorite[1:-1].split(", ")] textToFavorite = " ".join(L).strip() # Check if the article already exists article = Article.query.filter( Article.content == textToFavorite).first() if article is None: a = Article(textToFavorite) db_session.add(a) if a.id not in current_user.getFavorites(): current_user.add_favorite(a.id) db_session.commit() else: if article.id in current_user.getFavorites(): return "Already favorited!" current_user.add_favorite(article.id) db_session.commit() return "Favorited." return "Not a falid favorite request"
def collect(pid): # 判断是否收藏 if current_user.is_favorite(pid): current_user.del_favorite(pid) else: current_user.add_favorite(pid) favorite_count = Posts.query.get(pid).users.count() return jsonify({'result': 'ok', 'data': favorite_count, 'pid': pid})
def collect(pid): # 收藏逻辑 if current_user.is_favorites(pid): # 已收藏,则取消收藏 current_user.cancel_favorite(pid) else: current_user.add_favorite(pid) return jsonify({'result': 'ok'})
def collect(pid): if current_user.is_favorite(pid): #取消收藏 current_user.del_favorite(pid) else: #添加收藏 current_user.add_favorite(pid) return jsonify({'result':'ok'})
def collect(pid): # 判断是否收藏 if current_user.is_favorite(pid): # 取消收藏 current_user.del_favorite(pid) return jsonify({'status': '收藏'}) else: current_user.add_favorite(pid) return jsonify({'status': '取消收藏'})
def collect(pid): #判断是否已经收藏 if current_user.is_favorite(pid): current_user.del_favorite(pid) status = '收藏' else: current_user.add_favorite(pid) status = '取消收藏' return jsonify({'status': status})
def collections(pid): try: if current_user.is_favorite(pid): current_user.remove_favorite(pid) else: current_user.add_favorite(pid) return jsonify({'res': 200}) except: return jsonify({'res': 401})
def search_purchase(): key_word = request.args.get('key_word') page = request.args.get('page', 1, type=int) if current_user.is_authenticated: current_user.add_favorite(key_word) content = Search(mongo, key_word, DEMAND_COLLECTION, 'kinds', page) current_time = str(datetime.now()) return render_template('main/purchase.html', orders=content.cur_page, pagination=content.pagination, current_time=current_time)
def doFavorite(): try: pid = int(request.args.get('pid')) if current_user.is_favorite(pid): current_user.remove_favorite(pid) else: current_user.add_favorite(pid) return jsonify({'code': 200}) except: return jsonify({'code': 500})
def favorite(pid): try: if current_user.is_favorite(pid): print('取消收藏') current_user.remove_favorite(pid) else: print('添加收藏') current_user.add_favorite(pid) return jsonify({'res': 200}) except: return jsonify({'res': 500})
def favorite(pid): # 如果收藏了 就清除缓存 cache.clear() try: if current_user.is_favorite(pid): current_user.remove_favorite(pid) else: current_user.add_favorite(pid) return jsonify({'stat': 200}) except: return jsonify({'stat': 500})
def add_favorite(id): '''收藏文章''' post = Post.query.filter_by(id=id).first() if post is None: flash(_('Invalid post.'), 'danger') return redirect(url_for('.index')) if current_user.is_favorite(post): flash(_('You are already favorite this post.'), 'warning') return redirect(url_for('.user', username=current_user.username)) current_user.add_favorite(post) flash(_('You are now favorite <%(post)s>.', post=post.title), 'success') return redirect(url_for('.user', username=current_user.username))
def do_favorite(): try: # 获取ajax传递过来的pid pid = int(request.args.get('pid')) # 判断是否收藏了 if current_user.is_favorite(pid): # 调用取消收藏 current_user.delete_favorite(pid) print('取消') else: # 调用执行收藏 current_user.add_favorite(pid) # print('收藏') return jsonify({'res': 200}) except: return jsonify({'res': 500})