def post_new(request): if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): new_entry = form.save(commit=False) new_entry.author = request.user split_content = new_entry.content.split(settings.BLOG_CUT) if len(split_content) > 0: new_entry.preview = split_content[0] if 'save' in request.POST: new_entry.is_published = True if 'draft' in request.POST: new_entry.is_published = False new_entry.save() form.save_m2m() return HttpResponseRedirect(reverse('blog_index')) else: form = PostForm() return direct_to_template(request, 'fblog/post_edit.html',{'form':form})
def post_edit(request, year, month, day, slug, **kwargs): post = Post.objects.get(date__year=year, date__month=month, date__day=day, slug=slug) if request.method == 'POST': form = PostForm(request.POST, instance=post) if form.is_valid(): new_entry = form.save(commit=False) new_entry.author = request.user split_content = new_entry.content.split(settings.BLOG_CUT) if len(split_content) > 0: new_entry.preview = split_content[0] if 'save' in request.POST: new_entry.is_published = True if 'draft' in request.POST: new_entry.is_published = False new_entry.save() form.save_m2m() return HttpResponseRedirect(post.get_absolute_url()) else: form = PostForm(instance=post) return direct_to_template(request, 'fblog/post_edit.html', {'form':form,'post':post})