def newblog(request): """Create blog form and action Keyword arguments: request -- request object Returns: HttpResponse """ if request.method == 'POST': form = CreateBlogForm(request.POST) if form.is_valid(): data = form.cleaned_data blog = Blog() blog.name = data['name'] blog.description = data['description'] blog.owner = request.user blog.rate = 0 blog.rate_count = 0 blog.type = BlogType.objects.get(name=DEFAULT_BLOG_TYPE) blog.save() owner = UserInBlog() owner.blog = blog owner.user = request.user owner.save() return HttpResponseRedirect('/newpost/') else: form = CreateBlogForm() return { 'form': form }
def test_create_blog(self): BlogType.objects.create(name=settings.DEFAULT_BLOG_TYPE) form = CreateBlogForm(self.user, { 'name': 'okok', 'description': 'test blog' }) self.assertTrue(form.is_valid(), msg='blog form not work') blog = form.save() self.assertIsNotNone(blog.id, msg='blog saving not work') self.assertEqual(blog.name, 'okok', msg='blog data broken')
def newblog(request): """Create blog form and action Keyword arguments: request -- request object Returns: HttpResponse """ if request.method == 'POST': form = CreateBlogForm(request.user, request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/newpost/') else: form = CreateBlogForm(request.user) return { 'form': form }
def newblog(request): """Create blog form and action Keyword arguments: request -- request object Returns: HttpResponse """ if request.method == 'POST': form = CreateBlogForm(request.user, request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/newpost/') else: form = CreateBlogForm(request.user) return {'form': form}