[Django]-How do I get access to the request object when validating a django.contrib.comments form?

1👍

The comments framework provides a comment_will_be_posted signal:
http://docs.djangoproject.com/en/1.2/ref/contrib/comments/signals/#comment-will-be-posted

If you register at this signal, your handler will be passed the (not yet saved) comment object and the request as arguments. If your handler returns False, the post_comment view answers with CommentPostBadRequest, as it does on any other sort of error like failed form validation.

0👍

One possible way, but you still do not have request object in this level of validation…

class SomeForm(forms.ModelForm):
    somefield = forms.CharField(...)

    def check_somefield(self):
        somefield = self.cleaned_data['somefield']
        ...  #do what you want
    return somefield

Hope this can help, or i do not understand what you want correctly.

👤Mp0int

0👍

Leave a comment