Python captcha.fields.CaptchaField() Examples

The following are 2 code examples of captcha.fields.CaptchaField(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module captcha.fields , or try the search function .
Example #1
Source File: forms.py    From django-mptt-comments with MIT License 6 votes vote down vote up
def __init__(self, target_object, data=None, initial=None, parent=None, **kwargs):
        self.user = kwargs.pop('user', None)
        self.parent = parent
        if initial is None:
            initial = {}
        initial.update({'parent': self.parent})
        super(MPTTCommentForm, self).__init__(target_object, data=data, initial=initial, **kwargs)
        if self.user is not None:
            if self.user.is_authenticated:
                self.fields['email'].required = False
                self.fields['name'].required = False
            else:
                self.fields['captcha'] = CaptchaField()
        else:
            current_request = CrequestMiddleware.get_request()
            if current_request.user.is_authenticated:
                self.fields['email'].required = False
                self.fields['name'].required = False
            else:
                self.fields['captcha'] = CaptchaField() 
Example #2
Source File: forms.py    From tethys with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_captcha():
    if getattr(settings, 'ENABLE_CAPTCHA', False):
        if getattr(settings, 'RECAPTCHA_PRIVATE_KEY', '') and getattr(settings, 'RECAPTCHA_PUBLIC_KEY', ''):
            from snowpenguin.django.recaptcha2.fields import ReCaptchaField
            from snowpenguin.django.recaptcha2.widgets import ReCaptchaWidget

            return ReCaptchaField(label='', widget=ReCaptchaWidget())
        else:
            from captcha.fields import CaptchaField

            return CaptchaField(label='')
    else:
        return None