def create_form(self, instance, request): ContactFormBase = class_for_path(instance.form_layout) if instance.get_spam_protection_method_display() == 'Akismet': AkismetContactForm.aksimet_api_key = instance.akismet_api_key class ContactForm(ContactFormBase, AkismetContactForm): pass FormClass = ContactForm elif instance.get_spam_protection_method_display() == 'ReCAPTCHA': #if you really want the user to be able to set the key in # every form, this should be more flexible class ContactForm(ContactFormBase, RecaptchaContactForm): recaptcha_public_key = ( instance.recaptcha_public_key or getattr(settings, "RECAPTCHA_PUBLIC_KEY", None)) recaptcha_private_key = ( instance.recaptcha_private_key or getattr(settings, "RECAPTCHA_PRIVATE_KEY", None)) recaptcha_theme = instance.recaptcha_theme FormClass = ContactForm else: class ContactForm(ContactFormBase, HoneyPotContactForm): pass FormClass = ContactForm if request.method == "POST": return FormClass(request, data=request.POST, files=request.FILES) else: return FormClass(request)
def create_form(self, instance, request): ContactFormBase = class_for_path(instance.form_layout) if instance.get_spam_protection_method_display() == 'Akismet': AkismetContactForm.aksimet_api_key = instance.akismet_api_key class ContactForm(ContactFormBase, AkismetContactForm): pass FormClass = ContactForm elif instance.get_spam_protection_method_display() == 'ReCAPTCHA': #if you really want the user to be able to set the key in # every form, this should be more flexible class ContactForm(ContactFormBase, RecaptchaContactForm): recaptcha_public_key = ( instance.recaptcha_public_key or getattr(settings, "RECAPTCHA_PUBLIC_KEY", None) ) recaptcha_private_key = ( instance.recaptcha_private_key or getattr(settings, "RECAPTCHA_PRIVATE_KEY", None) ) recaptcha_theme = instance.recaptcha_theme FormClass = ContactForm else: class ContactForm(ContactFormBase, HoneyPotContactForm): pass FormClass = ContactForm if request.method == "POST": return FormClass(request, data=request.POST, files=request.FILES) else: return FormClass(request)
def create_form(self, instance, request): ContactFormBase = class_for_path(instance.form_layout) if instance.get_spam_protection_method_display() == 'Akismet': AkismetContactForm.aksimet_api_key = instance.akismet_api_key class ContactForm(ContactFormBase, AkismetContactForm): pass FormClass = ContactForm elif instance.get_spam_protection_method_display() == 'ReCAPTCHA': #if you really want the user to be able to set the key in # every form, this should be more flexible from nocaptcha_recaptcha.fields import NoReCaptchaField class ContactForm(ContactFormBase, RecaptchaContactForm): recaptcha_public_key = ( instance.recaptcha_public_key or getattr(settings, "RECAPTCHA_PUBLIC_KEY", None)) recaptcha_private_key = ( instance.recaptcha_private_key or getattr(settings, "RECAPTCHA_PRIVATE_KEY", None)) recaptcha_theme = instance.recaptcha_theme recaptcha_size = instance.recaptcha_size form_name = instance.form_name captcha = NoReCaptchaField(site_key=recaptcha_public_key, secret_key=recaptcha_private_key, gtag_attrs={ 'data-theme': recaptcha_theme, 'data-size': recaptcha_size }) FormClass = ContactForm else: class ContactForm(ContactFormBase, HoneyPotContactForm): pass FormClass = ContactForm form = None if request.method == "POST": form = FormClass(request, data=request.POST, files=request.FILES) else: form = FormClass(request) form.fields['my_name'] = forms.CharField(max_length=len( instance.form_name), widget=forms.HiddenInput, label='', initial=instance.form_name, required=False) return form
def create_form(self, instance, request): ContactFormBase = class_for_path(instance.form_layout) if instance.get_spam_protection_method_display() == 'Akismet': AkismetContactForm.aksimet_api_key = instance.akismet_api_key class ContactForm(ContactFormBase, AkismetContactForm): pass FormClass = ContactForm elif instance.get_spam_protection_method_display() == 'ReCAPTCHA': #if you really want the user to be able to set the key in # every form, this should be more flexible class ContactForm(ContactFormBase, RecaptchaContactForm): recaptcha_public_key = ( instance.recaptcha_public_key or getattr(settings, "RECAPTCHA_PUBLIC_KEY", None) ) recaptcha_private_key = ( instance.recaptcha_private_key or getattr(settings, "RECAPTCHA_PRIVATE_KEY", None) ) recaptcha_theme = instance.recaptcha_theme FormClass = ContactForm else: class ContactForm(ContactFormBase, HoneyPotContactForm): pass FormClass = ContactForm form = None if getattr(request, 'CMSPLUGIN_CONTACT', None) \ == instance.form_name \ or (request.method == "POST" and (not instance.form_name or instance.form_name == request.POST.get('my_name', '-'))): form = FormClass(request, data=request.POST, files=request.FILES) else: form = FormClass(request) form.fields['my_name'] = forms.CharField(max_length=len(instance.form_name), widget=forms.HiddenInput, label='', initial=instance.form_name, required=False) return form