示例#1
0
def collect(id):
    post = Post.query.get(id)
    if post is None:
        flash('the post_id is not valid')
        return redirect(url_for('main.index'))
    current_user.collect(post)
    return redirect(request.referrer)
示例#2
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')
    return redirect(url_for('.show_photo', photo_id=photo_id))
示例#3
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)
    flash('Photo collected.', 'success')
    return redirect(url_for('.show_photo', photo_id=photo_id))
示例#4
0
def collect(post_id):
    post = Post.query.get_or_404(post_id)
    if current_user.is_collecting(post):
        flash('该文章已收藏!', 'info')
        return redirect_back()

    current_user.collect(post)
    return redirect_back()
示例#5
0
def collect_post(post_id: int):
    if not current_user.is_authenticated:
        return jsonify(message="Login required."), 401
    post = Post.query.get_or_404(post_id)
    current_user.collect(post)
    if current_user.is_collecting(post):
        return {"message": "ok"}, 200
    return {"message": "failed"}, 400
示例#6
0
def collect(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        flash("Already collected.", category="info")
        return redirect(url_for("main.show_photo", photo_id=photo_id))
    current_user.collect(photo)
    flash("Photo collected.", category="success")
    return redirect(url_for("main.show_photo", photo_id=photo_id))
示例#7
0
def collect(post_id):
    post = Post.query.get_or_404(post_id)
    if current_user.is_collecting(post):
        flash('你已收藏过了该博文。', 'info')
        return redirect(url_for('.show_post', post_id=post_id))

    current_user.collect(post)
    flash('博文已收藏。', 'success')
    return redirect(url_for('.show_post', post_id=post_id))
def collect(post_id):
    post = Post.query.filter_by(id=post_id).first()
    if current_user.is_collecting(post):
        current_user.uncollect(post)
        db.session.commit()
        return jsonify(count=post.collectors.count(), collection_type=0)
    current_user.collect(post)
    db.session.commit()
    return jsonify(count=post.collectors.count(), collection_type=1)
示例#9
0
文件: main.py 项目: guoxy2016/Albumy
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)
    if photo.author.receive_collect_notification:
        push_collect_notification(current_user, photo_id, photo.author)
    flash('收藏成功!', 'success')
    return redirect(url_for('.show_photo', photo_id=photo_id))
示例#10
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))
示例#11
0
文件: main.py 项目: zgfhill/albumy-na
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))
示例#12
0
def collect(blog_id):
    blog = Blog.query.get_or_404(blog_id)
    if current_user.is_collecting(blog):
        flash('已经收藏了.', 'info')
        return redirect(url_for('.show_photo', blog_id=blog_id))

    current_user.collect(blog)
    flash('已收藏该贴.', 'success')
    if current_user != blog.user and blog.user.receive_collect_notification:
        push_collect_notification(collector=current_user, blog_id=blog_id, receiver=blog.user, type=blog.type)
    return redirect(url_for('blog.show_photo', blog_id=blog_id))
示例#13
0
def collect(topic_id):
    topic = Topic.query.get_or_404(topic_id)
    if current_user.is_collecting(topic):
        flash('已收藏过此帖子', 'info')
        return redirect(url_for('main.show_topic', topic_id=topic_id))

    current_user.collect(topic)
    flash('收藏成功', 'success')
    if current_user != topic.author and topic.author.receive_collect_notification:
        push_collect_notification(topic=topic, user=current_user)
    return redirect(url_for('main.show_topic', topic_id=topic.id))
示例#14
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 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))
示例#15
0
def collect(id):
	article=Article.query.get_or_404(id)
	if article is None:
		flash('没有该文章')
		return redirect(url_for('main.index'))
	if current_user.is_collect(article):
		flash('已经收藏过文章了')
		return redirect(url_for('main.index'))
	current_user.collect(article)
	flash('收藏成功')
	return redirect(url_for('main.article',id=id))
示例#16
0
def collect(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        flash("Already Collected", 'warning')
        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_notifications:
        push_collect_notification(collector=current_user, photo_id=photo_id, receiver=photo.author)
    return redirect(url_for('.show_photo', photo_id=photo_id))
示例#17
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.')
示例#18
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))
示例#19
0
def collect(id):
    post = Post.query.get_or_404(id)
    if current_user.is_authenticated:
        if current_user.collecting(post):
            flash('你已经收藏了这篇文章!')
            return redirect(url_for('public.details', id=post.id))
    else:
        flash('登录后才能收藏哦!')
        return redirect(url_for('public.details', id=post.id))

    current_user.collect(post)
    flash('收藏成功!')
    return redirect(url_for('public.details', id=post.id))
示例#20
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))
示例#21
0
def collect(post_id):
    post = Post.query.get_or_404(post_id)
    if current_user.is_collecting(post):
        flash('你已经收藏过了', 'info')
        return redirect(url_for('main.show_post', post_id=post_id))

    current_user.collect(post)
    flash('文章已成功收藏.', 'success')
    if current_user != post.user:
        push_collect_notification(collector=current_user,
                                  post_id=post.id,
                                  receiver=post.user)
    return redirect(url_for('main.show_post', post_id=post_id))
示例#22
0
文件: main.py 项目: gweid/PhotoSocial
def collect(photo_id):
    """收藏"""
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        flash('图片已经收藏过.', 'info')
        return redirect(url_for('main.show_photo', photo_id=photo_id))

    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 redirect_back()
示例#23
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))
示例#24
0
文件: main.py 项目: bbbbx/flask-notes
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))
示例#25
0
文件: ajax.py 项目: guoxy2016/Albumy
def collect(photo_id):
    if not current_user.is_authenticated:
        return jsonify(message='用户未登录'), 401
    if not current_user.confirmed:
        return jsonify(message='请验证邮箱后操作'), 400
    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)
    return jsonify(message='收藏图片成功')
示例#26
0
def collect(travel_id):
    travel = Travels.query.get_or_404(travel_id)
    if current_user.is_collecting(travel):
        flash('游记已收藏', 'info')
        return redirect(url_for('main.show_travels', travel_id=travel_id))

    current_user.collect(travel)
    flash('收藏成功', 'success')
    if current_user != travel.author and travel.author.receive_collect_notification:
        push_collect_notification(collector=current_user,
                                  travel_id=travel_id,
                                  receiver=travel.author)
    return redirect(url_for('main.show_travels', travel_id=travel_id))
示例#27
0
def collect(id):
    post = Post.query.get_or_404(id)
    if current_user.is_collecting(post):
        flash('你已经收藏了此文章。', 'info')
        return redirect_back()
    current_user.collect(post)
    flash('文章已收藏!', 'success')

    if current_user != post.author:
        push_collect_notification(collector=current_user,
                                  id=id,
                                  receiver=post.author)

    return redirect_back()
示例#28
0
文件: ajax.py 项目: haichong98/albumy
def collect(photo_id):
    if not current_user.is_authenticated:
        return jsonify(message='需要登录'), 403
    if not current_user.confirmed:
        return jsonify(message='需要确认用户邮箱'), 400
    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='图片收藏成功')
示例#29
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='Confirmed 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 photo.author.receive_collect_notification and current_user != photo.author:
        push_collect_notification(collector=current_user, photo_id=photo_id, receiver=photo.author)
    return jsonify(message='User collected')
示例#30
0
def collect(blog_id):
    if not current_user.is_authenticated:
        return jsonify(message='Login required.'), 403
    if not current_user.confirmed:
        return jsonify(message='Confirm account required.'), 400
    if not current_user.can('COLLECT'):
        return jsonify(message='No permission.'), 403

    blog = Blog.query.get_or_404(blog_id)
    if current_user.is_collecting(blog):
        return jsonify(message='Already collected.'), 400

    current_user.collect(blog)
    if current_user != blog.user and blog.user.receive_collect_notification:
        push_collect_notification(collector=current_user, photo_id=blog_id, receiver=blog.user)
    return jsonify(message='Photo collected.')
示例#31
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")