def process_response(self, request, response): if response['Content-Type'].split(';')[0] in _HTML_TYPES: # ensure we don't add the 'id' attribute twice (HTML validity) def add_honeypot_field(match): """Returns the matched <form> tag plus the added <input> element""" value = getattr(settings, 'HONEYPOT_VALUE', '') if callable(value): value = value() return mark_safe(match.group() + render_to_string('honeypot/honeypot_field.html', {'fieldname': settings.HONEYPOT_FIELD_NAME, 'value': value})) # Modify any POST forms response.content = _POST_FORM_RE.sub(add_honeypot_field, force_unicode(response.content)) return response
def process_response(self, request, response): if response['Content-Type'].split(';')[0] in _HTML_TYPES: # ensure we don't add the 'id' attribute twice (HTML validity) def add_honeypot_field(match): """Returns the matched <form> tag plus the added <input> element""" value = getattr(settings, 'HONEYPOT_VALUE', '') if callable(value): value = value() return mark_safe(match.group() + '''<div style="display: none;"> <label>leave this field blank to prove your humanity <input type="text" name="%(fieldname)s" value="%(value)s" /> </label></div>''' % {'fieldname': settings.HONEYPOT_FIELD_NAME, 'value': value}) # Modify any POST forms response.content = _POST_FORM_RE.sub(add_honeypot_field, response.content) return response