Exemple #1
0
def collect(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        flash('Already collected.', 'info')
        return redirect(url_for('.show_photo', photo_id=photo_id))
    current_user.collect(photo)
    if current_user != photo.author and current_user.receive_collect_notification:
        push_collect_notification(collector=current_user, photo_id=photo_id, receiver=photo.author)
    flash('Photo collected.', 'success')
    return redirect(url_for('.show_photo', photo_id=photo_id))
Exemple #2
0
def collect(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        flash('This photo already collected', 'warning')
        return redirect(url_for('main.show_photo', photo_id=photo_id))

    current_user.collect(photo)
    flash('Collect successful', 'success')
    if current_user != photo.author and photo.author.receive_collect_notification:
        push_collect_notification(current_user, photo.id, photo.author)
    return redirect(url_for('main.show_photo', photo_id=photo_id))
Exemple #3
0
def collect(photo_id):
    if not current_user.is_authenticated:
        return jsonify(message='Login required.'), 403

    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        return jsonify(message='Already collected.'), 400

    current_user.collect(photo)
    if current_user != photo.author and photo.author.receive_collect_notification:
        push_collect_notification(collector=current_user, photo_id=photo_id, receiver=photo.author)
    return jsonify(message='Photo collected.')
Exemple #4
0
def collect(photo_id):
	photo = Photo.query.get_or_404(photo_id)
	if current_user.is_collecting(photo):
		flash('Already collected.', 'info')
		return render_template(url_for('.show_photo', photo_id=photo_id))

	current_user.collect(photo)
	flash('Photo collected.', 'success')
	if current_user != photo.author:
		push_collect_notification(current_user, photo_id, photo.author)

	return redirect(url_for('.show_photo', photo_id=photo_id))
Exemple #5
0
def collect(photo_id):
    if request.method.lower() == 'get':
        return redirect(url_for('.show_photo', photo_id=photo_id))
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        flash('Already collected.', 'info')
        return redirect(url_for('.show_photo', photo_id=photo_id))

    current_user.collect(photo)
    flash('Photo collected.', 'success')
    if current_user != photo.author and photo.author.receive_collect_notification:
        push_collect_notification(current_user, photo_id, photo.author)
    return redirect(url_for('.show_photo', photo_id=photo_id))
Exemple #6
0
def collect(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        flash('已经收藏了。', 'info')
        return redirect(url_for('.show_photo', photo_id=photo_id))

    current_user.collect(photo)
    flash('收藏成功。', 'success')
    if current_user != photo.author:
        push_collect_notification(collector=current_user,
                                  photo_id=photo_id,
                                  receiver=photo.author)
    return redirect(url_for('.show_photo', photo_id=photo_id))
Exemple #7
0
def collect(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        flash("Already collected", "info")
        return redirect(url_for("main.show_photo", photo_id=photo_id))

    current_user.collect(photo)
    flash("Photo collected.", "success")
    if current_user != photo.author and photo.author.receive_collect_notification:
        push_collect_notification(collector=current_user,
                                  photo_id=photo_id,
                                  receiver=photo.author)
    return redirect(url_for("main.show_photo", photo_id=photo_id))
Exemple #8
0
def collect(photo_id):
    if not current_user.is_authenticated:
        return jsonify(message="Login required."), 403
    if not current_user.confirmed:
        return jsonify(message="Confirm account required."), 403
    if not current_user.can("FOLLOW"):
        return jsonify(message="No permission."), 403
    
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        return jsonify(message="Already collected."), 400
    
    current_user.collect(photo)
    if current_user != photo.author and photo.author.receive_collect_notification:
        push_collect_notification(collector=current_user, photo_id=photo_id, receiver=photo.author)
    return jsonify(message="Photo collected")
Exemple #9
0
def collect(photo_id):
    if not current_user.is_authenticated:
        return jsonify(message='Login required.'), 403
    if not current_user.confiremd:
        return jsonify(message='Confirm account required.'), 400
    if not current_user.can('COLLECT'):
        return jsonify(message='No permission.'), 403

    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        return jsonify(message='Already collected.'), 400

    current_user.collect(photo)
    if current_user != photo.author and photo.author.receive_collect_notification:
        push_collect_notification(collector=current_user,
                                  photo_id=photo_id,
                                  receiver=photo)
Exemple #10
0
def collect(photo_id):
    if not current_user.is_authenticated:
        return jsonify(message='请先登录!'), 403
    if not current_user.confirmed:
        return jsonify(message='请先确认邮箱地址!'), 403
    if not current_user.can('COLLECT'):
        return jsonify(message='没有收藏的权限。'), 403

    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        return jsonify(message='已经收藏过啦。'), 400

    current_user.collect(photo)
    if current_user != photo.author and photo.author.receive_collect_notification:
        push_collect_notification(collector=current_user,
                                  photo_id=photo_id,
                                  receiver=photo.author)
    return jsonify(message='收藏成功。')
Exemple #11
0
def collect(photo_id):
	"""
	收藏图片
	:param photo_id: 图片id
	"""
	logger.info('url = ' + str(request.url))
	logger.info('收藏者的用户名: {},收藏的图片ID: {}'.format(current_user.username, photo_id))
	photo = Photo.query.get_or_404(photo_id)
	# 调用User的is_collecting函数,判断是否已经收藏过该图片
	if current_user.is_collecting(photo):
		flash("该图片已经收藏过了!", "info")
		return redirect(url_for(".show_photo", photo_id=photo_id))
	# 收藏图片
	current_user.collect(photo)
	flash("收藏成功!", "success")
	# 根据判断条件,是否需要发出提醒消息
	if current_user != photo.author and photo.author.receive_collect_notification:
		push_collect_notification(
			collector=current_user, photo_id=photo_id, receiver=photo.author
		)
	return redirect(url_for(".show_photo", photo_id=photo_id))