Beispiel #1
0
def create_blog(request):
    errors = []
    template = "blog/templates/create_blog.html"
    form = CreateBlogForm()
    user = request.user

    if not user.is_authenticated():
        raise Http404

    if request.method == "POST":
        form = CreateBlogForm(request.POST)

        if form.is_valid():
            try:
                data = form.cleaned_data
                _blog = Blog()
                _blog.title = data["title"]
                _blog.owner = user
                _blog.url = data["url"]
                _blog.tagline = data["tagline"]
                _blog.active = True
                _blog.save()
                _blog.contributors.add(user)
                _blog.save()
                return HttpResponseRedirect("/blog/%s/" % user.username)
            except:
                errors.append("Blog URL already taken.")

    return render(request, template, {"errors": errors, "form": form})
Beispiel #2
0
def create_blog(request):
	errors = []
	template = "blog/templates/create_blog.html"
	form = CreateBlogForm()
	user = request.user

	if not user.is_authenticated():
		raise Http404

	if request.method == "POST":
		form = CreateBlogForm(request.POST)

		if form.is_valid():
			try:
				data = form.cleaned_data
				_blog = Blog()
				_blog.title = data["title"]
				_blog.owner = user
				_blog.url = data["url"]
				_blog.tagline = data["tagline"]
				_blog.active = True
				_blog.save()
				_blog.contributors.add(user)
				_blog.save()
				return HttpResponseRedirect("/blog/%s/"%user.username)
			except:
				errors.append("Blog URL already taken.")

	return render(request, template, {"errors":errors, "form":form})
Beispiel #3
0
def create_blog_view(request):
    if request.method == 'POST':
        form = CreateBlogForm(request.POST)
        if form.is_valid():
            blog = Blog.objects.create(user=request.user, date=datetime.date.today())
            blog.title, blog.description = form.cleaned_data['title'], form.cleaned_data['description']
            blog.name_field = form.cleaned_data['name_field']
            blog.save()

            return HttpResponseRedirect(reverse('blog', args=[blog.name_field]))

    else:
        form = CreateBlogForm()
    context = {
        'form': form
    }
    return render(request, 'createblog.html', context=context)
Beispiel #4
0
def create(request):
    form = CreateBlogForm(request.POST or None, request.FILES or None)
    if request.method == 'POST':
        if form.is_valid():
            form = form.save(commit=False)
            form.user = request.user
            form.save()
            return redirect('account')
    return render(request, 'blog/blog-create.html', {'form': form})
Beispiel #5
0
def edit(request, slug):
    post = get_object_or_404(Post,
                             slug=slug,
                             user=request.user,
                             status__in=['D', 'P'],
                             category__status='A')
    form = CreateBlogForm(request.POST or None,
                          request.FILES or None,
                          instance=post)
    if request.method == 'POST':
        if form.is_valid():
            form = form.save(commit=False)
            form.updated_by = request.user
            form.save()
            return redirect('account')
    return render(request, 'blog/blog-edit.html', {'post': post, 'form': form})
Beispiel #6
0
def create_blog(request):
    if request.method == 'POST':
        form = CreateBlogForm(request.POST)
        if form.is_valid():
            blog = form.save(commit=False)
            if request.user.is_authenticated():
                blog.author = request.user
            blog.save()
            return HttpResponseRedirect('/blog/')
    else:
        form = CreateBlogForm()

    return render(request, 'blog/create_blog.html', {'form': form})