Пример #1
0
def new_message(request, user_id, thread_id):
	user = get_object_or_404(User, pk=user_id)
	thread = get_object_or_404(Thread, pk=thread_id)
	message_text = request.POST['message_text']
	message = Message(sender = user, thread = thread, text = message_text, html = message_text)
	message.save()
	return HttpResponseRedirect(reverse('thread_detail', args=(user_id, thread_id,)))
Пример #2
0
def new_thread(request, user_id):
	user = get_object_or_404(User, pk=user_id)
	users = User.objects.all().exclude(pk=user_id) # all users except for the logged in one.  Obviously this needs to get smarter!
	if request.method == 'POST':
		print 'we posted'
		form = ThreadForm(user, request.POST)
		if form.is_valid():
			print 'form is valid'
			members = User.objects.filter(pk__in=form.cleaned_data['members'])
			#members = [User.objects.get(pk=m) for m in form.cleaned_data['members']]
			print members

			group = group_with_members(user, members)
			thread = Thread(subject = form.cleaned_data['subject'],
							creator = user,
							group = group)
			thread.save()

			# finally add the message
			message = Message(sender = user,
							  text = form.cleaned_data['message_text'],
							  html = form.cleaned_data['message_text'],
							  thread = thread)
			message.save()

			return HttpResponseRedirect(reverse('thread_detail', args=(user.pk, thread.pk,)))
		else:
			print 'form invalid'
	else:
		form = ThreadForm(user)

	return render(request, 'new_thread.html', {'user': user, 'form': form})
Пример #3
0
def new_message(request, user_id, thread_id):
    user = get_object_or_404(User, pk=user_id)
    thread = get_object_or_404(Thread, pk=thread_id)
    message_text = request.POST['message_text']
    message = Message(sender=user,
                      thread=thread,
                      text=message_text,
                      html=message_text)
    message.save()
    return HttpResponseRedirect(
        reverse('thread_detail', args=(
            user_id,
            thread_id,
        )))
Пример #4
0
def new_thread(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    users = User.objects.all().exclude(
        pk=user_id
    )  # all users except for the logged in one.  Obviously this needs to get smarter!
    if request.method == 'POST':
        print 'we posted'
        form = ThreadForm(user, request.POST)
        if form.is_valid():
            print 'form is valid'
            members = User.objects.filter(pk__in=form.cleaned_data['members'])
            #members = [User.objects.get(pk=m) for m in form.cleaned_data['members']]
            print members

            group = group_with_members(user, members)
            thread = Thread(subject=form.cleaned_data['subject'],
                            creator=user,
                            group=group)
            thread.save()

            # finally add the message
            message = Message(sender=user,
                              text=form.cleaned_data['message_text'],
                              html=form.cleaned_data['message_text'],
                              thread=thread)
            message.save()

            return HttpResponseRedirect(
                reverse('thread_detail', args=(
                    user.pk,
                    thread.pk,
                )))
        else:
            print 'form invalid'
    else:
        form = ThreadForm(user)

    return render(request, 'new_thread.html', {'user': user, 'form': form})