コード例 #1
0
    def post(self):
        form = PostForm()
        if request.method == 'POST':
            if form.validate_on_submit():
                post = Post.create()
                form.populate_obj(post)
                f = request.files.get('file')
                post.user = current_user

                if f:
                    picture = Picture.create()
                    picture.save_file(f, current_user)
                    post.cover_picture_id = picture.id if picture else 0

                post.update_score(page_view=1)
                post.save()

                if form.remain.data:
                    url = url_for('PostsView:put', id=post.id)
                else:
                    url = url_for('PostsView:get', id=post.id)

                return resp(url, redirect=True,
                            message=gettext('Stamp succesfully created'))
            else:
                return resp('admin/posts/edit.html', status=False, form=form,
                            message=gettext('Invalid submission, please check the message below'))

        return resp('admin/posts/edit.html', form=form)
コード例 #2
0
    def upload_profile_picture(self, id):
        user = User.get_by_id(id)

        f = request.files.get('file')

        if f:
            picture = Picture.create()
            picture.save_file(f, current_user)
            user.profile_picture_id = picture.id if picture else 0
            user.save()

        return resp('', user=user)
コード例 #3
0
ファイル: index.py プロジェクト: gabriel-tessier/HeadsUp
    def post(self):
        form = PostForm()

        if form.validate_on_submit():
            try:
                if not form.validate():
                    raise Exception(_('ERROR_INVALID_SUBMISSION'))

                remain = request.values.get('remain', False, bool)
                post = Post.create()
                form.populate_obj(post)
                post.user = current_user

                f = request.files.get('file')

                if f:
                    picture = Picture.create()
                    picture.save_file(f, current_user)
                    post.cover_picture_id = picture.id if picture else 0

                # init the score
                post.update_score(page_view=1)

                post.editor_version = 1
                post.save()

                Feed.clear_feed_cache()

                if post.is_draft:
                    message = _('POST_DRAFT_SAVE_SUCESS')
                else:
                    message = _('POST_PUBLIC_SAVE_SUCESS')

                if remain:
                    url = url_for('PostsView:put', id=post.id, remain='y')
                else:
                    url = url_for('PostsView:get', id=post.id)

                return render_view(url, redirect=True, message=message)

            except Exception as e:
                flash(e.message, 'error')

        return render_view('admin/posts/edit.html',
                           form=form)
コード例 #4
0
    def put(self, id):
        post = Post.get_by_id(id)

        if post is None or not post.can_edit():
            flash(gettext('The requested stamp was not found'), 'error')
            return redirect(url_for('PostsView:index'))

        if request.method in ['POST']:
            form = PostForm()
            if form.validate_on_submit():
                cover_picture_id = request.values.get('cover_picture_id', 0, int)
                remain = request.values.get('remain', False, bool)

                if post.cover_picture and cover_picture_id == 0:
                    # remove the picture, when user request its deletion
                    post.cover_picture.remove()
                c = form.category_id.data
                form.populate_obj(post)

                f = request.files.get('file')
                if f:
                    if post.cover_picture:
                        post.cover_picture.remove()
                    picture = Picture.create()
                    picture.save_file(f, current_user)
                    post.cover_picture_id = picture.id if picture else 0

                post.save()
                message = gettext('Stamp was succesfully saved')

                if remain:
                    return resp('admin/posts/edit.html', form=form, post=post, message=message)

                return resp(url_for('PostsView:get', id=post.id), redirect=True, message=message)
            else:
                return resp('admin/posts/edit.html', status=False, form=form, post=post,
                            message=gettext('Invalid submission, please check the message below'))
        else:
            form = PostForm(post)

        return resp('admin/posts/edit.html', form=form, post=post)
コード例 #5
0
ファイル: index.py プロジェクト: gabriel-tessier/HeadsUp
    def put(self, id):
        post = Post.get_by_id(id)

        if post is None or not post.can_edit() or post.is_hidden:
            return render_view(url_for('PostsView:index'),
                               status=False,
                               redirect=True,
                               message=_('POST_NOT_FOUND'))

        form = PostForm(post=post)

        if form.is_submitted():
            try:
                if not form.validate():
                    raise Exception(_('ERROR_INVALID_SUBMISSION'))

                cover_picture_id = request.values.get('cover_picture_id', 0, int)
                is_draft = request.values.get('status', 0, int) == Post.POST_DRAFT
                remain = request.values.get('remain', False, bool)

                if post.cover_picture and cover_picture_id == 0:
                    # remove the picture, when user request its deletion
                    post.cover_picture.remove()

                form.populate_obj(post)

                f = request.files.get('file')

                if f:
                    if post.cover_picture:
                        post.cover_picture.remove()
                    picture = Picture.create()
                    picture.save_file(f, current_user)
                    post.cover_picture_id = picture.id if picture else 0

                if is_draft:
                    post.status = Post.POST_DRAFT
                else:
                    if post.save_count == 1 or post.created_at is None:
                        post.created_at = Post.current_date()
                        post.save_count = 1
                    post.status = Post.POST_PUBLIC
                    post.save_count += 1

                post.editor_version = 1
                post.save()

                Feed.clear_feed_cache()

                if post.is_draft:
                    message = _('POST_DRAFT_SAVE_SUCESS')
                else:
                    message = _('POST_PUBLIC_SAVE_SUCESS')

                if not remain:
                    return render_view(url_for('PostsView:get', id=post.id),
                                       redirect=True,
                                       message=message)
            except Exception as e:
                flash(e.message, 'error')

        return render_view('admin/posts/edit.html',
                           form=form,
                           post=post)