def add_message(request, topic_id): topic = Topic.objects.get(id=topic_id) msg_post = request.POST['message'] msg_author = User.objects.get(pk=1) message = Message(post=msg_post, created_at=timezone.now(), author=msg_author, msg_topic=topic) message.save() return HttpResponseRedirect(reverse('meep.views.topic', args=(topic_id,)))
def add_thread(request): check_auth(request) print "enter add_thread" form = add_thread_form(auto_id=True) if request.method == 'POST': #if the form is submitted title = request.POST['title'] body = request.POST['message'] user_id = request.session['_auth_user_id'] if user_id: user = User.objects.get(id=user_id) creator = user created = datetime.datetime.now() thread = Thread(title=title, creator=creator, created=created) thread.save() message = Message(title=title, body=body, creator=creator, created=created, thread=thread) message.save() return HttpResponseRedirect('/list_threads/') return render_to_response('add_thread.html', {'form': form,}, RequestContext(request))
def add_message(request): if not request.user.is_authenticated(): return HttpResponseRedirect("/registration/login/") print "enter add_message" form = add_message_form(auto_id=True) if request.method == 'POST': #if the form is submitted title = request.POST['title'] body = request.POST['message'] user_id = request.session['_auth_user_id'] if user_id: user = User.objects.get(id=user_id) creator = user created = datetime.datetime.now() thread = Thread(title="default", creator=creator, created=created) thread.save() message = Message(title=title, body=body, creator=creator, created=created, thread=thread) message.save() return HttpResponseRedirect('/list_messages/') return render_to_response('add_message.html', {'form': form,}, RequestContext(request))