Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No 'field_template' arg for CaptchaTextInput #119

Open
Antonboom opened this issue Jul 5, 2017 · 2 comments
Open

No 'field_template' arg for CaptchaTextInput #119

Antonboom opened this issue Jul 5, 2017 · 2 comments

Comments

@Antonboom
Copy link

Antonboom commented Jul 5, 2017

Hello!
Why do you take a custom template from the arguments, but render the template from the settings anyway?

class CaptchaTextInput(BaseCaptchaTextInput):
    def __init__(self, attrs=None, **kwargs):
        self._args = kwargs
        self._args['field_template'] = self._args.get('field_template') or settings.CAPTCHA_FIELD_TEMPLATE

    def format_output(self, rendered_widgets):
        hidden_field, text_field = rendered_widgets    # <---- Unused variables

        if self._args['output_format']:
            return self._args['output_format'] % {...}

        elif self._args['field_template']:
            context = {
                'image': mark_safe(self.image_and_audio),
                'hidden_field': mark_safe(self.hidden_field),
                'text_field': mark_safe(self.text_field)
            }
            return render_to_string(settings.CAPTCHA_FIELD_TEMPLATE, context)    # <---- This line

In addition, it would also be nice to take from the arguments.

    def render(self, name, value, attrs=None):
        self.fetch_captcha_store(name, value, attrs, self._args.get('generator'))

        context = {...}
        if settings.CAPTCHA_FLITE_PATH:    # <-------- self._args
            context.update({'audio': self.audio_url()})

        self.image_and_audio = render_to_string(settings.CAPTCHA_IMAGE_TEMPLATE, context)     # <-------- self._args
        self.hidden_field = render_to_string(settings.CAPTCHA_HIDDEN_FIELD_TEMPLATE, context)     # <-------- self._args
        self.text_field = render_to_string(settings.CAPTCHA_TEXT_FIELD_TEMPLATE, context)     # <-------- self._args

        return super(CaptchaTextInput, self).render(name, self._value, attrs=attrs)

This will not allow you to bind all the captcha in the project to the same settings.

@ziima
Copy link
Contributor

ziima commented Apr 5, 2018

field_template fixed in #139.

@ziima
Copy link
Contributor

ziima commented Apr 5, 2018

_args removed in #133.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants