コード例 #1
0
ファイル: views.py プロジェクト: nadavperetz/MeneEduca
def reply_create(request, thread_id):

    member = request.user.profile
    thread = get_object_or_404(ForumThread, id=thread_id)

    if thread.closed:
        messages.error(request, "This thread is closed.")
        return HttpResponseRedirect(reverse("forums:agora_thread", args=[thread.id]))

    can_create_reply = request.user.has_perm("agora.add_forumreply", obj=thread)

    if not can_create_reply:
        messages.error(request, "You do not have permission to reply to this thread.")
        return HttpResponseRedirect(reverse("forums:agora_thread", args=[thread.id]))

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

        if form.is_valid():
            reply = form.save(commit=False)
            reply.thread = thread
            reply.author = request.user
            reply.save()

            # subscribe the poster to the thread if requested (default value is True)
            if form.cleaned_data["subscribe"]:
                thread.subscribe(reply.author, "email")

            # all users are automatically subscribed to onsite
            thread.subscribe(reply.author, "onsite")

            return HttpResponseRedirect(reverse("forums:agora_thread", args=[thread_id]))
    else:
        quote = request.GET.get("quote")  # thread id to quote
        initial = {}

        if quote:
            quote_reply = ForumReply.objects.get(id=int(quote))
            initial["content"] = '"%s"' % quote_reply.content

        form = ReplyForm(initial=initial)

    first_reply = not ForumReply.objects.filter(thread=thread, author=request.user).exists()

    return render_to_response(
        "agora/reply_create.html",
        {
            "form": form,
            "member": member,
            "thread": thread,
            "subscribed": thread.subscribed(request.user, "email"),
            "first_reply": first_reply,
        },
        context_instance=RequestContext(request),
    )
コード例 #2
0
ファイル: views.py プロジェクト: nadavperetz/MeneEduca
def forum_thread(request, thread_id):
    qs = ForumThread.objects.select_related("forum")
    thread = get_object_or_404(qs, id=thread_id)

    can_create_reply = all(
        [request.user.has_perm("agora.add_forumreply", obj=thread), not thread.closed, not thread.forum.closed]
    )

    if can_create_reply:
        if request.method == "POST":
            reply_form = ReplyForm(request.POST)

            if reply_form.is_valid():
                reply = reply_form.save(commit=False)
                reply.thread = thread
                reply.author = request.user
                reply.save()

                # subscribe the poster to the thread if requested (default value is True)
                if reply_form.cleaned_data["subscribe"]:
                    thread.subscribe(reply.author, "email")

                # all users are automatically subscribed to onsite
                thread.subscribe(reply.author, "onsite")

                return HttpResponseRedirect(reverse("forums:agora_thread", args=[thread.id]))
        else:
            reply_form = ReplyForm()
    else:
        reply_form = None

    order_type = request.GET.get("order_type", "asc")
    posts = ForumThread.objects.posts(thread, reverse=(order_type == "desc"))
    thread.inc_views()

    if not (thread.forum.group in request.user.profile.group_set.all()):
        messages.error(request, "You do not have permission to read this.")
        return HttpResponseRedirect(reverse("forums:agora_forums"))

    return render_to_response(
        "agora/thread.html",
        {
            "thread": thread,
            "posts": posts,
            "order_type": order_type,
            "subscribed": thread.subscribed(request.user, "email"),
            "reply_form": reply_form,
            "can_create_reply": can_create_reply,
        },
        context_instance=RequestContext(request),
    )
コード例 #3
0
ファイル: views.py プロジェクト: szairis/projectMed
def detail(request, encrypted_id):
    if ie_test(request):
        return fuck_ie(request)
    
    now = datetime.now()
    post_id = unencrypt(encrypted_id)

    if not Posting.objects.get(id=post_id).is_alive:
        raise Http404

    if request.method == 'POST': # If the form has been submitted...
        reply_form = ReplyForm(request.POST) # A form bound to the POST data
        if reply_form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ... here is where we save()
            try:
                if request.session['reply_time']:
                    return HttpResponseRedirect('/sorry/')
            except:                
                pass
            request.session['reply_time'] = True
            request.session.set_expiry(timedelta(seconds=60))
            reply = reply_form.save(commit=False)
            reply.posting_id = post_id
            reply.save()
            reply_post = Posting.objects.get(id=post_id)
            reply_post.number_replies += 1
            reply_post.save()
            subject = "re: %s" % (reply_post.title)
            message = reply.msg_body
            from_email = "projectMed <*****@*****.**>"
            to_email = reply_post.contact_email
            reply_header = {'Reply-To': "%s <%s>" % (reply.name, reply.contact_email)}
            email = EmailMessage(subject,message,from_email,[to_email], headers = reply_header)
            email.send(fail_silently=True)
            return HttpResponseRedirect('/reply_success/') # Redirect after POST
        else:
            owner_form = OwnerForm()
    else:
        reply_form = ReplyForm() # An unbound form
        owner_form = OwnerForm()

    post = Posting.objects.get(id=post_id)
        
    return render(request, 'agora/base_listing.html', {
        'listing': post,
        'form': reply_form,
        'owner_form' : owner_form,
        'pagetitle': 'listing',
    })
コード例 #4
0
ファイル: views.py プロジェクト: MechanisM/agora
def reply_create(request, thread_id):

    member = request.user.get_profile()
    thread = get_object_or_404(ForumThread, id=thread_id)

    if thread.closed:
        messages.error(request, "This thread is closed.")
        return HttpResponseRedirect(reverse("agora_thread", args=[thread.id]))

    can_create_reply = request.user.has_perm("agora.add_forumreply",
                                             obj=thread)

    if not can_create_reply:
        messages.error(request,
                       "You do not have permission to reply to this thread.")
        return HttpResponseRedirect(reverse("agora_thread", args=[thread.id]))

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

        if form.is_valid():
            reply = form.save(commit=False)
            reply.thread = thread
            reply.author = request.user
            reply.save()

            # subscribe the poster to the thread if requested (default value is True)
            if form.cleaned_data["subscribe"]:
                thread.subscribe(reply.author, "email")

            # all users are automatically subscribed to onsite
            thread.subscribe(reply.author, "onsite")

            return HttpResponseRedirect(
                reverse("agora_thread", args=[thread_id]))
    else:

        quote = request.GET.get("quote")  # thread id to quote
        initial = {}

        if quote:
            quote_reply = ForumReply.objects.get(id=int(quote))
            initial["content"] = "\"%s\"" % quote_reply.content

        form = ReplyForm(initial=initial)

    first_reply = not ForumReply.objects.filter(thread=thread,
                                                author=request.user).exists()

    return render_to_response(
        "agora/reply_create.html", {
            "form": form,
            "member": member,
            "thread": thread,
            "subscribed": thread.subscribed(request.user, "email"),
            "first_reply": first_reply,
        },
        context_instance=RequestContext(request))
コード例 #5
0
def detail(request, encrypted_id):
    if ie_test(request):
        return fuck_ie(request)

    now = datetime.now()
    post_id = unencrypt(encrypted_id)

    if not Posting.objects.get(id=post_id).is_alive:
        raise Http404

    if request.method == 'POST':  # If the form has been submitted...
        reply_form = ReplyForm(request.POST)  # A form bound to the POST data
        if reply_form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            # ... here is where we save()
            try:
                if request.session['reply_time']:
                    return HttpResponseRedirect('/sorry/')
            except:
                pass
            request.session['reply_time'] = True
            request.session.set_expiry(timedelta(seconds=60))
            reply = reply_form.save(commit=False)
            reply.posting_id = post_id
            reply.save()
            reply_post = Posting.objects.get(id=post_id)
            reply_post.number_replies += 1
            reply_post.save()
            subject = "re: %s" % (reply_post.title)
            message = reply.msg_body
            from_email = "projectMed <*****@*****.**>"
            to_email = reply_post.contact_email
            reply_header = {
                'Reply-To': "%s <%s>" % (reply.name, reply.contact_email)
            }
            email = EmailMessage(subject,
                                 message,
                                 from_email, [to_email],
                                 headers=reply_header)
            email.send(fail_silently=True)
            return HttpResponseRedirect(
                '/reply_success/')  # Redirect after POST
        else:
            owner_form = OwnerForm()
    else:
        reply_form = ReplyForm()  # An unbound form
        owner_form = OwnerForm()

    post = Posting.objects.get(id=post_id)

    return render(
        request, 'agora/base_listing.html', {
            'listing': post,
            'form': reply_form,
            'owner_form': owner_form,
            'pagetitle': 'listing',
        })
コード例 #6
0
ファイル: views.py プロジェクト: MechanisM/agora
def forum_thread(request, thread_id):
    qs = ForumThread.objects.select_related("forum")
    thread = get_object_or_404(qs, id=thread_id)

    can_create_reply = all([
        request.user.has_perm("agora.add_forumreply", obj=thread),
        not thread.closed,
        not thread.forum.closed,
    ])

    if can_create_reply:
        if request.method == "POST":
            reply_form = ReplyForm(request.POST)

            if reply_form.is_valid():
                reply = reply_form.save(commit=False)
                reply.thread = thread
                reply.author = request.user
                reply.save()

                # subscribe the poster to the thread if requested (default value is True)
                if form.cleaned_data["subscribe"]:
                    thread.subscribe(reply.author, "email")

                # all users are automatically subscribed to onsite
                thread.subscribe(reply.author, "onsite")

                return HttpResponseRedirect(
                    reverse("agora_thread", args=[thread.id]))
        else:
            reply_form = ReplyForm()
    else:
        reply_form = None

    order_type = request.GET.get("order_type", "asc")

    posts = ForumThread.objects.posts(thread, reverse=(order_type == "desc"))

    thread.inc_views()

    return render_to_response(
        "agora/thread.html", {
            "thread": thread,
            "posts": posts,
            "order_type": order_type,
            "subscribed": thread.subscribed(request.user, "email"),
            "reply_form": reply_form,
            "can_create_reply": can_create_reply,
        },
        context_instance=RequestContext(request))