Ejemplo n.º 1
0
def new_post(request):
    if request.method == 'POST': 
        form = AddNewPostForm(request.POST) # A form bound to the POST data
        
        if form.is_valid(): # All validation rules pass
            Post.objects.create(
                    author=request.user,
                    title=form.cleaned_data['post_title'],
                    content=form.cleaned_data['post_content'],
                    link=title_to_link(form.cleaned_data['post_title']),
                    publication_date=form.cleaned_data['post_publication_date'],
                    publish=form.cleaned_data['post_publish'],
                    category=Category.get(form.cleaned_data['post_category']),
                    tags=form.cleaned_data['post_tags'],
            )
            return HttpResponseRedirect('/blog') # Redirect after POST
    else:
        form = AddNewPostForm() # An unbound form

    return render(request, 'blog/new-post.html', 
            {'form': form})
Ejemplo n.º 2
0
 def test_form_publish_checkbox_can_be_set(self):
     form = AddNewPostForm(self.post_data)
     self.assertTrue(form.is_valid())
     self.assertTrue(form.cleaned_data['post_publish'])
Ejemplo n.º 3
0
 def test_form_validation(self):
     form = AddNewPostForm(self.post_data)
     
     self.assertTrue(form.is_valid())
     self.assertEqual(True,{}==form.errors)