def new_topic(request, forum_id): form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = form.cleaned_data['description'] topic.forum = forum topic.creator = request.user topic.save() return HttpResponseRedirect( reverse('forum-detail', args=(forum_id, ))) return render_to_response('django_simple_forum/new-topic.html', { 'form': form, 'forum': forum, }, context_instance=RequestContext(request))
def new_topic(request, slug): form = TopicForm() forum = get_object_or_404(Forum, slug=slug) if request.method == "POST": form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data["title"] topic.description = "" topic.creator = request.user topic.save() topic.forums.add(forum) topic.save() post = Post() post.title = form.cleaned_data["title"] post.body = form.cleaned_data["description"] post.creator = request.user post.user_ip = request.META["REMOTE_ADDR"] post.topic = topic post.save() l = Log() l.mota = "Foroa" l.tituloa = "Gai berria" l.deskripzioa = post.title l.post_id = post.id l.user = request.user l.forum_id = forum.id l.save() return HttpResponseRedirect(reverse("topic-detail", args=(slug, topic.id))) return render_to_response( "django_simple_forum/new-topic.html", {"form": form, "forum": forum}, context_instance=RequestContext(request) )
def new_topic(request, slug): form = TopicForm() forum = get_object_or_404(Forum, slug=slug) if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = form.cleaned_data['description'] topic.creator = request.user topic.save() topic.forums.add(forum) topic.save() return HttpResponseRedirect(reverse('forum-detail', args=(slug, ))) return render_to_response('django_simple_forum/new-topic.html', { 'form': form, 'forum': forum, }, context_instance=RequestContext(request))