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 group(request, gurl_number): group = Group.objects(url_number=gurl_number).get() if request.method == "POST": form = NewTopicForm(request.POST) if form.is_valid(): title = form.cleaned_data["title"] content = form.cleaned_data["content"] topic = Topic(title=title) turl_number = len(Topic.objects) + 1 topic.url_number = turl_number topic.content = content topic.creat_time = datetime.datetime.now() topic.is_active = True topic.is_locked = False topic.is_top = False topic.clicks = 0 topic.update_time = datetime.datetime.now() topic.update_author = request.user sgcard = S_G_Card.objects(user=request.user, group=group).get() topic.creator = sgcard topic.save() return HttpResponseRedirect("/group/" + str(gurl_number) + "/topic/" + str(turl_number) + "/") else: form = NewTopicForm() return render_to_response( "group/group.html", {"form": form, "group": group, "STATIC_URL": STATIC_URL, "current_user": request.user}, 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() 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/')