Exemplo n.º 1
0
def create_post(request):
	if request.method == "GET":
		return render(request, 'blogApp/create_post.html', {
			'blog_post_form': BlogPostForm(),
			'image_form': UploadImageForm(),
		})

	else:
		form = BlogPostForm(request.POST)

		if form.is_valid():
			new_post = form.save()

			messages.success(request, _('Blog post was added.'))
			return redirect(new_post)

		else: # not valid, return errors
			return render(request, 'blogApp/create_post.html', {
				'blog_post_form': form,
				'image_form': UploadImageForm()
			})
Exemplo n.º 2
0
def create_post(request):
    if request.method == "GET":
        return render(request, 'blogApp/create_post.html', {
            'blog_post_form': BlogPostForm(),
            'image_form': UploadImageForm(),
        })

    else:
        form = BlogPostForm(request.POST)

        if form.is_valid():
            new_post = form.save()

            messages.success(request, _('Blog post was added.'))
            return redirect(new_post)

        else:  # not valid, return errors
            return render(request, 'blogApp/create_post.html', {
                'blog_post_form': form,
                'image_form': UploadImageForm()
            })
Exemplo n.º 3
0
def edit_post(request, slug):
	instance = get_object_or_404(Post.objects.filter(slug=slug))

	if request.method == "GET": return render( request, 'blogApp/create_post.html', {
		'blog_post_form': BlogPostForm(instance=instance),
		'image_form': UploadImageForm()
	})

	else:
		form = BlogPostForm(request.POST or None, instance=instance)

		if form.is_valid():
			new_post = form.save()

			messages.success(request, _('Blog post saved.'))
			return redirect(new_post)

		else: # not valid, return errors
			return render(request, 'blogApp/create_post.html', {
				'blog_post_form': form,
				'image_form': UploadImageForm()
			})
Exemplo n.º 4
0
def edit_post(request, slug):
    instance = get_object_or_404(Post.objects.filter(slug=slug))

    if request.method == "GET":
        return render(
            request, 'blogApp/create_post.html', {
                'blog_post_form': BlogPostForm(instance=instance),
                'image_form': UploadImageForm()
            })

    else:
        form = BlogPostForm(request.POST or None, instance=instance)

        if form.is_valid():
            new_post = form.save()

            messages.success(request, _('Blog post saved.'))
            return redirect(new_post)

        else:  # not valid, return errors
            return render(request, 'blogApp/create_post.html', {
                'blog_post_form': form,
                'image_form': UploadImageForm()
            })