Esempio n. 1
0
def my_post_free_comment(request):
    if request.POST.has_key('url'):
        url = request.POST['url']
    else:
        url = '/comments/posted.html'
    response = post_free_comment(request)
    return HttpResponseRedirect(url)
def free_comment_wrapper(request, extra_context={}, context_processors=None):
    if request.POST:
        check_captcha = captcha.submit(
            request.POST.get("recaptcha_challenge_field", ""),
            request.POST.get("recaptcha_response_field", ""),
            settings.RECAPTCHA_PRIVATE_KEY,
            request.META["REMOTE_ADDR"],
        )
        if check_captcha.is_valid is False:
            raise Http404, "Invalid Captcha Attempt"
        extra_context["recaptcha_html"] = captcha.displayhtml(settings.RECAPTCHA_PUB_KEY)
        return post_free_comment(request, extra_context, context_processors)
    raise Http404, "Only POSTs are allowed"
Esempio n. 3
0
def save_free_comment(request):
    
    if request.POST:
        
        target = request.POST.get("target", None)
        
        if target:
            
            (ct_id, obj_id) = target.split(":")
        
            user_type = ContentType.objects.get(id=ct_id)
            
            if user_type.model == "section":
                section = Section.objects.get(pk=obj_id)
                legislation = section.title.legislation
            elif user_type.model == "legislation":
                legislation = Legislation.objects.get(pk=obj_id)
            else:
                legislation = None
        
            if legislation and legislation.allow_comments:
        
                if not request.has_key('preview') and not settings.DEBUG:
        
                    recaptcha_resp = captcha.submit(
                        recaptcha_challenge_field=request.POST.get('recaptcha_challenge_field'),
                        recaptcha_response_field=request.POST.get('recaptcha_response_field'),
                        private_key=settings.RECAPTCHA_PRIVATE_KEY,
                        remoteip=request.META['REMOTE_ADDR']
                    )
        
                    if recaptcha_resp.is_valid is False:
                        raise Http404, "Invalid Captcha Attempt"
            
                extra_context = {"recaptcha_html": captcha.displayhtml(settings.RECAPTCHA_PUBLIC_KEY)}
        
                return post_free_comment(request, extra_context)
                
            else:
                
                raise Http404, "Sorry, comments are not allowed on this legislation."
    
    else:
    
        raise Http404, "All you do is GET, GET, GET. How about you POST every once in a while like you used to at the beginning of our relationship?"
        
    return HttpResponseServerError("DENIED! Not really, something just broke.")
Esempio n. 4
0
 def post(self, request, **kwargs):
     defaults = dict(queryset=self.get_blog().entry_set.of_type(Entry.TYPE_POST), date_field="pub_date")
     defaults.update(kwargs)
     if request.method == "POST":
         form = CommentForm(request.POST)
         if form.is_valid():
             response = post_free_comment(request)
             return HttpResponseRedirect(request.POST["url"])
         else:
             extra_context = dict(extra_context=dict(form=form))
             defaults.update(extra_context)
             return object_detail(request, **defaults)
     else:
         form = CommentForm()
         extra_context = dict(extra_context=dict(form=form))
         defaults.update(extra_context)
         return object_detail(request, **defaults)
Esempio n. 5
0
def post_comment(request):
    """Post a comment, and redirect back to the blog entry on success."""

    answer=0
    try:
        # El cheapo anti-spammage - only shows up on the preview page
        answer=request.POST["answer"]
    except KeyError:
        pass
    if answer != '4711' and 'post' in request.POST:
        raise Http404

    response = post_free_comment(request)
    if isinstance(response, HttpResponseRedirect):
        # We can assume content_type refers to Post, since this
        # comment posting URL is local to the blogging app.
        target = request.POST['target']
        content_type_id, object_id = target.split(':')
        return HttpResponseRedirect(Post.objects.get(pk=int(object_id)).get_absolute_url())
    return response
Esempio n. 6
0
 def post(self, request, **kwargs):
     defaults = dict(
         queryset=self.get_blog().entry_set.of_type(Entry.TYPE_POST),
         date_field='pub_date',
     )
     defaults.update(kwargs)
     if request.method == 'POST':
         form = CommentForm(request.POST)
         if form.is_valid():
             response = post_free_comment(request)
             return HttpResponseRedirect(request.POST['url'])
         else:
             extra_context = dict(extra_context=dict(form=form))
             defaults.update(extra_context)
             return object_detail(request, **defaults)
     else:
         form = CommentForm()
         extra_context = dict(extra_context=dict(form=form))
         defaults.update(extra_context)
         return object_detail(request, **defaults)
Esempio n. 7
0
 def page(self, request, **kwargs):
     defaults = dict(
         queryset=self.get_blog().entry_set.of_type(Entry.TYPE_PAGE),
         slug_field='slug',
         template_name='djog/entry_detail.html',
     )
     defaults.update(kwargs)
     if request.method == 'POST':
         form = CommentForm(request.POST)
         if form.is_valid():
             response = post_free_comment(request)
             return HttpResponseRedirect(request.POST['url'])
         else:
             extra_context = dict(extra_context=dict(form=form))
             defaults.update(extra_context)
             return list_detail.object_detail(request, **defaults)
     else:
         form = CommentForm()
         extra_context = dict(extra_context=dict(form=form))
         defaults.update(extra_context)
         return list_detail.object_detail(request, **defaults)
Esempio n. 8
0
 def page(self, request, **kwargs):
     defaults = dict(
         queryset=self.get_blog().entry_set.of_type(Entry.TYPE_PAGE),
         slug_field="slug",
         template_name="djog/entry_detail.html",
     )
     defaults.update(kwargs)
     if request.method == "POST":
         form = CommentForm(request.POST)
         if form.is_valid():
             response = post_free_comment(request)
             return HttpResponseRedirect(request.POST["url"])
         else:
             extra_context = dict(extra_context=dict(form=form))
             defaults.update(extra_context)
             return list_detail.object_detail(request, **defaults)
     else:
         form = CommentForm()
         extra_context = dict(extra_context=dict(form=form))
         defaults.update(extra_context)
         return list_detail.object_detail(request, **defaults)