Esempio n. 1
0
	def get_queryset(self, **kwargs):
		forum = self.kwargs['forum']
                thread = self.kwargs['thread']
		f = get_object_or_404(Forum, slug=forum)
		t = get_object_or_404(Thread, pk=thread)
		p = t.post_set.all().order_by('-time')[:1]

		if t.closed:
			return HttpResponseRedirect('/accounts/login?next=%s' % request.path)

		if request.method == 'POST':
			form = create_newpostform(request)

			if form.is_valid():
				if request.user.is_authenticated() or form.login(request):
					p = Post(
						thread=t, 
						author=request.user,
						body=form.cleaned_data['body'],
						time=datetime.now(),
						)
					if form.data.has_key(u'post'):
						p.save()
						return HttpResponseRedirect(p.get_absolute_url())
					else:
						return render(request, 'community/thread.html',{
								'forum': f,
								'form': form,
								'thread': t,
								'posting': p,
								'form_action' : ''})
		else:
			form = create_newpostform(request)
		return p
Esempio n. 2
0
def reply(request, forum, thread):
    """
	If a thread isn't closed, and the user is logged in, post a reply
	to a thread. Note we don't have "nested" replies at this stage.
	"""
    f = get_object_or_404(Forum, slug=forum)
    t = get_object_or_404(Thread, pk=thread)
    p = t.post_set.all().order_by('-time')[:1]

    if t.closed:
        return HttpResponseRedirect('/accounts/login?next=%s' % request.path)

    if request.method == 'POST':
        form = create_newpostform(request)

        if form.is_valid():
            if request.user.is_authenticated() or form.login(request):
                p = Post(
                    thread=t,
                    author=request.user,
                    body=form.cleaned_data['body'],
                    time=datetime.now(),
                )
                if form.data.has_key(u'post'):
                    p.save()
                    return HttpResponseRedirect(p.get_absolute_url())
                else:
                    return render_to_response(
                        'community/thread.html',
                        RequestContext(
                            request, {
                                'forum': f,
                                'form': form,
                                'thread': t,
                                'posting': p,
                                'form_action': ''
                            }))
    else:
        form = create_newpostform(request)

    return list_detail.object_list(request,
                                   paginate_by=10,
                                   queryset=p,
                                   template_name='community/thread.html',
                                   extra_context={
                                       'forum': f,
                                       'form': form,
                                       'thread': t,
                                       'form_action': ''
                                   })
Esempio n. 3
0
def reply(request, forum, thread):
	"""
	If a thread isn't closed, and the user is logged in, post a reply
	to a thread. Note we don't have "nested" replies at this stage.
	"""
	f = get_object_or_404(Forum, slug=forum)
	t = get_object_or_404(Thread, pk=thread)
	p = t.post_set.all().order_by('-time')[:1]

	if t.closed:
		return HttpResponseRedirect('/accounts/login?next=%s' % request.path)

	if request.method == 'POST':
		form = create_newpostform(request)

		if form.is_valid():
			if request.user.is_authenticated() or form.login(request):
				p = Post(
					thread=t, 
					author=request.user,
					body=form.cleaned_data['body'],
					time=datetime.now(),
					)
				if form.data.has_key(u'post'):
					p.save()
					return HttpResponseRedirect(p.get_absolute_url())
				else:
					return render_to_response('community/thread.html',
						RequestContext(request, {
							'forum': f,
							'form': form,
							'thread': t,
							'posting': p,
							'form_action' : ''}))
	else:
		form = create_newpostform(request)

	return list_detail.object_list(request,
			paginate_by=10,
			queryset=p,
			template_name='community/thread.html',
		extra_context= {
			'forum': f,
			'form': form,
			'thread': t,
			'form_action' : ''})
Esempio n. 4
0
def reply(request, forum, thread):
    """
	If a thread isn't closed, and the user is logged in, post a reply
	to a thread. Note we don't have "nested" replies at this stage.
	"""
    f = get_object_or_404(Forum, slug=forum)
    t = get_object_or_404(Thread, pk=thread)
    p = t.post_set.all().order_by("-time")[:1]

    if t.closed:
        return HttpResponseRedirect("/accounts/login?next=%s" % request.path)

    if request.method == "POST":
        form = create_newpostform(request)

        if form.is_valid():
            if request.user.is_authenticated() or form.login(request):
                p = Post(thread=t, author=request.user, body=form.cleaned_data["body"], time=datetime.now())
                if form.data.has_key(u"post"):
                    p.save()
                    return HttpResponseRedirect(p.get_absolute_url())
                else:
                    return render_to_response(
                        "community/thread.html",
                        RequestContext(
                            request, {"forum": f, "form": form, "thread": t, "posting": p, "form_action": ""}
                        ),
                    )
    else:
        form = create_newpostform(request)

    return DetailView.as_view(
        request,
        paginate_by=10,
        queryset=p,
        template_name="community/thread.html",
        extra_context={"forum": f, "form": form, "thread": t, "form_action": ""},
    )
Esempio n. 5
0
    def get_queryset(self, **kwargs):
        forum = self.kwargs['forum']
        thread = self.kwargs['thread']
        f = get_object_or_404(Forum, slug=forum)
        t = get_object_or_404(Thread, pk=thread)
        p = t.post_set.all().order_by('-time')[:1]

        if t.closed:
            return HttpResponseRedirect('/accounts/login?next=%s' %
                                        request.path)

        if request.method == 'POST':
            form = create_newpostform(request)

            if form.is_valid():
                if request.user.is_authenticated() or form.login(request):
                    p = Post(
                        thread=t,
                        author=request.user,
                        body=form.cleaned_data['body'],
                        time=datetime.now(),
                    )
                    if form.data.has_key(u'post'):
                        p.save()
                        return HttpResponseRedirect(p.get_absolute_url())
                    else:
                        return render(
                            request, 'community/thread.html', {
                                'forum': f,
                                'form': form,
                                'thread': t,
                                'posting': p,
                                'form_action': ''
                            })
        else:
            form = create_newpostform(request)
        return p