Пример #1
0
def crop_avatar():
    form = CropAvatarForm()
    if form.validate_on_submit():
        useless_photos = [
            current_user.avatar_s, current_user.avatar_m,
            current_user.avatar_l, current_user.avatar_raw
        ]
        x = form.x.data
        y = form.y.data
        w = form.w.data
        h = form.h.data
        names = avatars.crop_avatar(current_user.avatar_raw, x, y, w, h)
        # removing old photos of user
        for filename in useless_photos:
            path = os.path.join(current_app.config["AVATARS_SAVE_PATH"],
                                filename)
            if os.path.exists(path):
                os.remove(path)
        # assigning new photos to user
        current_user.avatar_s = names[0]
        current_user.avatar_m = names[1]
        current_user.avatar_l = names[2]
        db.session.commit()
        flash('Аватар обновлен', 'success')
    flash_errors(form)
    return redirect(url_for('.change_avatar'))
Пример #2
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 = Comment(body=body, author=author, photo=photo)

        replied_id = request.args.get('reply')
        if replied_id:
            comment.replied = Comment.query.get_or_404(replied_id)
            if comment.replied.author.receive_comment_notification:
                push_comment_notification(photo_id=photo.id,
                                          receiver=comment.replied.author)
        db.session.add(comment)
        db.session.commit()
        flash(_l('Comment published.'), 'success')

        if current_user != photo.author and photo.author.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))
Пример #3
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(_l('Image uploaded, please crop.'), 'success')
    flash_errors(form)
    return redirect(url_for('.change_avatar'))
Пример #4
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'))
Пример #5
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
        save_user_avatars(current_user, x, y, w, h)
        flash(_l('Avatar updated.'), 'success')
    flash_errors(form)
    return redirect(url_for('.change_avatar'))
Пример #6
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
        # TODO: crop avatar
        db.session.commit()
        flash('Avatar updated.', 'success')
    flash_errors(form)
    return redirect(url_for('.change_avatar'))
Пример #7
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(_l('Description updated.'), 'success')

    flash_errors(form)
    return redirect(url_for('.show_photo', photo_id=photo_id))
Пример #8
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'))
Пример #9
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(_l('Tag added.'), 'success')

    flash_errors(form)
    return redirect(url_for('.show_photo', photo_id=photo_id))