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:forum-detail', args=(forum_id, ))) return render( request, 'forum/new-topic.html', { 'form': form, 'forum': forum, }, )
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() return HttpResponseRedirect(reverse('topic-detail', args=(slug, topic.id, ))) return render(request, 'forum/new-topic.html', {'form': form, 'forum': forum})
def question_topic(request): form = TopicForm2() if request.method == 'POST': form = TopicForm2(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = form.cleaned_data['description'] topic.forum = form.cleaned_data['forum'] topic.creator = request.user topic.save() return HttpResponseRedirect(reverse('forum:forum-index')) return render( request, 'forum/question-topic.html', { 'form': form, }, )
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 userToUpdate = UserProfile.objects.get(user=request.user) nCredits = userToUpdate.credits userToUpdate.credits = int(float(nCredits + 200)) # TODO: Change status (if points+100>threshold -> status changes) # Alert? Maybe return to page with status update info for user. # Make Gold/Platinum distinction if nCredits + 200 >= GOLD_THRESHOLD: newStatus = "Gold" userToUpdate.status = newStatus userToUpdate.save() topic.save() return render_to_response( "forum/status_change.html", {'status': newStatus}, context_instance=RequestContext(request)) elif nCredits + 100 >= PLATINUM_THRESHOLD: newStatus = "Platinum" userToUpdate.status = newStatus userToUpdate.save() topic.save() return render_to_response( "forum/status_change.html", {'status': newStatus}, context_instance=RequestContext(request)) else: userToUpdate.save() topic.save() return HttpResponseRedirect( reverse('forum-detail', args=(forum_id, ))) return render_to_response('forum/new-topic.html', { 'form': form, 'forum': forum, }, context_instance=RequestContext(request))
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 userToUpdate = UserProfile.objects.get(user=request.user) nCredits = userToUpdate.credits userToUpdate.credits = int(float(nCredits + 200)) # TODO: Change status (if points+100>threshold -> status changes) # Alert? Maybe return to page with status update info for user. # Make Gold/Platinum distinction if nCredits + 200 >= GOLD_THRESHOLD: newStatus = "Gold" userToUpdate.status = newStatus userToUpdate.save() topic.save() return render_to_response("forum/status_change.html", {'status': newStatus}, context_instance=RequestContext(request)) elif nCredits + 100 >= PLATINUM_THRESHOLD: newStatus = "Platinum" userToUpdate.status = newStatus userToUpdate.save() topic.save() return render_to_response("forum/status_change.html", {'status': newStatus}, context_instance=RequestContext(request)) else: userToUpdate.save() topic.save() return HttpResponseRedirect(reverse('forum-detail', args=(forum_id, ))) return render_to_response('forum/new-topic.html', { 'form': form, 'forum': forum, }, context_instance=RequestContext(request))
def new_topic(request, forum_id): form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) user = request.user if forum.closed and not user.has_perm('forum.can_post_lock_forum'): return render(request, 'personal/basic.html', {'content': ['This forum is locked.']}) if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = bleach_clean(form.cleaned_data['description']) topic.forum = forum topic.creator = user topic.save() tpkPost = Post() tpkPost.topic = topic tpkPost.title = topic.title tpkPost.body = bleach_clean(form.cleaned_data['description']) tpkPost.creator = user tpkPost.user_ip = get_client_ip(request) tpkPost.save() return HttpResponseRedirect( reverse('topic-detail', args=( topic.id, topic.slug, ))) return render_to_response('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.forum = forum topic.creator = request.user topic.save() return HttpResponseRedirect(reverse('forum:forum-detail', args=(forum.slug, ))) context = get_base_context() context.update({'form': form, 'forum': forum}) return render(request, 'forum/new-topic.html', context)
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, forum_id): form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) user = request.user if forum.closed and not user.has_perm('forum.can_post_lock_forum'): return render(request, 'personal/basic.html', {'content':['This forum is locked.']}) if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = bleach_clean(form.cleaned_data['description']) topic.forum = forum topic.creator = user topic.save() tpkPost = Post() tpkPost.topic = topic tpkPost.title = topic.title tpkPost.body = bleach_clean(form.cleaned_data['description']) tpkPost.creator = user tpkPost.user_ip = get_client_ip(request) tpkPost.save() return HttpResponseRedirect(reverse('topic-detail', args=(topic.id, topic.slug, ))) return render_to_response('forum/new-topic.html', { 'form': form, 'forum': forum, }, context_instance=RequestContext(request))
def new_topic(request, forum_id): if 'userid' in request.session: form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) status = 'student' stud_obj = student.objects.get(pk=request.session['userid']) username = stud_obj.uname 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 obj = student.objects.get(pk=request.session['userid']) topic.creator = obj topic.save() return HttpResponseRedirect( reverse('forum-detail', args=(forum_id, ))) return render( request, 'forum/new-topic.html', { 'form': form, 'forum': forum, 'username': username, 'status': status }, ) elif 'instructorid' in request.session: form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) status = 'instructor' inst_obj = instructor.objects.get(pk=request.session['instructorid']) username = inst_obj.uname 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 obj = instructor.objects.get( pk=request.session['instructorid']) topic.by_instructor = obj topic.save() return HttpResponseRedirect( reverse('forum-detail', args=(forum_id, ))) return render( request, 'forum/new-topic.html', { 'form': form, 'forum': forum, 'username': username, 'status': status }, ) else: return HttpResponseRedirect('/joinus/login/')