Esempio n. 1
0
def upload_avatar():
    form = UploadAvatarForm()
    if form.validate_on_submit():
        image = form.image.data
        filename = avatars.save_avatar(image)
        current_user.avatar_raw = filename
        db.session.commit()
        flash('图像已上传,请裁剪', 'success')
    flash_errors(form)
    return redirect(url_for('.change_avatar'))
Esempio n. 2
0
def edit_description(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user != photo.author and not current_user.can('MODERATE'):
        abort(403)
    form = DescriptionForm()
    if form.validate_on_submit():
        photo.description = form.description.data
        db.session.commit()
        flash('已更新图片描述', 'success')
    flash_errors(form)                              #flash表单的错误
    return redirect(url_for('.show_photo', photo_id=photo_id))
Esempio n. 3
0
def crop_avatar():
    form = CropAvatarForm()
    if form.validate_on_submit():
        x = form.x.data
        y = form.y.data
        w = form.w.data
        h = form.h.data
        filenames = avatars.crop_avatar(current_user.avatar_raw, x,y,w,h)
        current_user.avatar_s = filenames[0]
        current_user.avatar_m = filenames[1]
        current_user.avatar_l = filenames[2]
        db.session.commit()
        flash('已裁剪', 'success')
    flash_errors(form)
    return redirect(url_for('.change_avatar'))
Esempio n. 4
0
def new_tag(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user != photo.author and not current_user.can('MODERATE'):
        abort(403)

    form = TagForm()
    if form.validate_on_submit():
        for name in form.tag.data.split():
            tag = Tag.query.filter_by(name=name).first()
            if tag is None:
                tag = Tag(name=name)
                db.session.add(tag)
                db.session.commit()
            if tag not in photo.tags:
                photo.tags.append(tag)
                db.session.commit()
        flash('已添加标签', 'success')
    flash_errors(form)
    return redirect(url_for('.show_photo', photo_id=photo_id))
Esempio n. 5
0
def new_post_comment(post_id):
    post = Post.query.get_or_404(post_id)

    page = request.args.get('page', 1, type=int)
    form = CommentForm()
    if form.validate_on_submit():
        body = form.body.data
        author = current_user._get_current_object()
        comment = PostComment(body=body, author=author, post=post)

        replied_id = request.args.get('reply')
        if replied_id:
            comment.replied = PostComment.query.get_or_404(replied_id)
            #提醒功能
        db.session.add(comment)
        db.session.commit()
        flash('已评论', 'success')

    flash_errors(form)
    return redirect(url_for('.show_post', post_id=post_id, page=page))
Esempio n. 6
0
def new_comment(photo_id):
    photo = Photo.query.get_or_404(photo_id)

    page = request.args.get('page', 1, type=int)
    form = CommentForm()
    if form.validate_on_submit():
        body = form.body.data
        author = current_user._get_current_object()
        comment = PhotoComment(body=body, author=author, photo=photo)

        replied_id = request.args.get('reply')
        if replied_id:
            comment.replied = PhotoComment.query.get_or_404(replied_id)
            if current_user.receive_comment_notification:
                push_comment_notification(photo_id=photo.id, receiver=comment.replied.author)
        db.session.add(comment)
        db.session.commit()
        flash('已评论', 'success')
        if current_user != photo.author and current_user.receive_comment_notification:
            push_comment_notification(photo_id, receiver=photo.author, page=page)
    flash_errors(form)
    return redirect(url_for('.show_photo', photo_id=photo_id,page=page))