Django Sitemap Framework integriert
This commit is contained in:
@@ -9,9 +9,11 @@ from django.conf import settings
|
||||
from django.core import validators
|
||||
from django.core.validators import EMPTY_VALUES
|
||||
from django.forms import utils, Form, ModelForm, ValidationError
|
||||
import sys
|
||||
import django.forms.fields
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
|
||||
from . import widgets
|
||||
|
||||
|
||||
@@ -28,6 +30,9 @@ class Html5Mixin(object):
|
||||
if self.help_text:
|
||||
attrs['title'] = self.help_text
|
||||
attrs['placeholder'] = self.help_text
|
||||
if hasattr(self, 'placeholder'):
|
||||
attrs['placeholder'] = self.placeholder
|
||||
|
||||
if self.accesskey:
|
||||
attrs['accesskey'] = self.accesskey
|
||||
return attrs
|
||||
@@ -124,6 +129,7 @@ class CharField(Html5Mixin, django.forms.CharField):
|
||||
|
||||
|
||||
class DateField(Html5Mixin, django.forms.fields.DateField):
|
||||
placeholder = _('yyyy-mm-dd')
|
||||
widget = widgets.DateInput
|
||||
|
||||
|
||||
@@ -200,63 +206,36 @@ class ReCaptchaField(django.forms.fields.CharField):
|
||||
self.required = True
|
||||
super(ReCaptchaField, self).__init__(*args, **kwargs)
|
||||
|
||||
def _check_recaptcha(self, challenge_value, response_value, remote_ip=None):
|
||||
"""
|
||||
Submits a reCAPTCHA request for verification.
|
||||
Returns RecaptchaResponse for the request
|
||||
|
||||
@param challenge_value: value of recaptcha_challenge_field
|
||||
@param response_value: value of recaptcha_response_field
|
||||
@param remoteip -- the user's ip address
|
||||
|
||||
"""
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
private_key = settings.RECAPTCHA_PRIVATE_KEY
|
||||
challenge_value = challenge_value.encode('utf-8')
|
||||
response_value = response_value.encode('utf-8')
|
||||
params = urllib.urlencode({
|
||||
'privatekey': private_key,
|
||||
'remoteip': remote_ip,
|
||||
'challenge': challenge_value,
|
||||
'response': response_value,
|
||||
})
|
||||
|
||||
request = urllib2.Request(
|
||||
url="http://www.google.com/recaptcha/api/verify",
|
||||
data=params,
|
||||
headers={
|
||||
"Content-type": "application/x-www-form-urlencoded",
|
||||
"User-agent": "reCAPTCHA Python"
|
||||
}
|
||||
)
|
||||
httpresp = urllib2.urlopen(request)
|
||||
|
||||
return_values = httpresp.read().splitlines()
|
||||
httpresp.close()
|
||||
|
||||
return_code = return_values[0]
|
||||
if (return_code == "true"):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
def get_remote_ip(self):
|
||||
f = sys._getframe()
|
||||
while f:
|
||||
if 'request' in f.f_locals:
|
||||
request = f.f_locals['request']
|
||||
if request:
|
||||
remote_ip = request.META.get('REMOTE_ADDR', None)
|
||||
forwarded_ip = request.META.get('HTTP_X_FORWARDED_FOR', None)
|
||||
return forwarded_ip or remote_ip
|
||||
f = f.f_back
|
||||
|
||||
def clean(self, values):
|
||||
""" test the google recaptcha"""
|
||||
import json, urllib, urllib2
|
||||
|
||||
url = "https://www.google.com/recaptcha/api/siteverify"
|
||||
challenge_value = values[0]
|
||||
response_value = values[1]
|
||||
super(ReCaptchaField, self).clean(response_value)
|
||||
if not challenge_value:
|
||||
data = urllib.urlencode({
|
||||
'secret': settings.RECAPTCHA_PRIVATE_KEY,
|
||||
'response': values[1],
|
||||
'remoteip': self.get_remote_ip()
|
||||
})
|
||||
req = urllib2.Request(url, data)
|
||||
response = urllib2.urlopen(req)
|
||||
result = json.loads(response.read())
|
||||
|
||||
# result["success"] will be True on a success
|
||||
if not result["success"]:
|
||||
raise ValidationError(
|
||||
_(u'The CAPTCHA challenge is missing.'))
|
||||
elif not response_value:
|
||||
raise ValidationError(
|
||||
_(u'The CAPTCHA solution is missing.'))
|
||||
elif self._check_recaptcha(challenge_value, response_value):
|
||||
return challenge_value
|
||||
else:
|
||||
raise ValidationError(
|
||||
_(u'The CAPTCHA solution was incorrect.'))
|
||||
_(u'Only humans are allowed to submit this form.'))
|
||||
|
||||
|
||||
class RegexField(Html5Mixin, django.forms.RegexField):
|
||||
|
||||
@@ -126,23 +126,15 @@ class ReCaptchaInput(widgets.Widget):
|
||||
"""
|
||||
Der HTML Code von Googles ReCaptcha als Form Widget
|
||||
"""
|
||||
recaptcha_challenge_name = 'recaptcha_challenge_field'
|
||||
recaptcha_response_name = 'recaptcha_response_field'
|
||||
recaptcha_challenge_name = 'g-recaptcha-response'
|
||||
recaptcha_response_name = 'g-recaptcha-response'
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
javascript = u"""
|
||||
<script type="text/javascript">var RecaptchaOptions = {theme :
|
||||
'%(theme)s'};</script><script type="text/javascript"
|
||||
src="https://www.google.com/recaptcha/api/challenge?k=%(public_key)s">
|
||||
</script><noscript><iframe
|
||||
src="https://www.google.com/recaptcha/api/noscript?k=%(public_key)s"
|
||||
height="130" width="500"></iframe><br /><textarea
|
||||
name="recaptcha_challenge_field" rows="3" cols="40"></textarea><input
|
||||
type="hidden" name="recaptcha_response_field" value="manual_challenge">
|
||||
</noscript>"""
|
||||
return mark_safe(javascript % {'public_key':
|
||||
settings.RECAPTCHA_PUBLIC_KEY,
|
||||
'theme': 'red'})
|
||||
html_code = u'''
|
||||
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
|
||||
<div class="g-recaptcha" data-sitekey="{public_key}" data-size="compact"></div>
|
||||
'''.format(public_key=settings.RECAPTCHA_PUBLIC_KEY)
|
||||
return mark_safe(html_code)
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
return [data.get(self.recaptcha_challenge_name, None),
|
||||
|
||||
@@ -7,16 +7,16 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: kasu.utils\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2016-09-16 18:07+0200\n"
|
||||
"PO-Revision-Date: 2015-08-16 11:42+0200\n"
|
||||
"Last-Translator: Christian Berg <xeniac.at@gmail.com>\n"
|
||||
"POT-Creation-Date: 2016-09-28 00:25+0200\n"
|
||||
"PO-Revision-Date: 2016-09-28 00:24+0200\n"
|
||||
"Last-Translator: Christian Berg <xeniac@posteo.at>\n"
|
||||
"Language-Team: Kasu <verein@kasu.at>\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"X-Generator: Poedit 1.8.3\n"
|
||||
"X-Generator: Poedit 1.8.9\n"
|
||||
|
||||
#: src/utils/__init__.py:16
|
||||
msgid "Rejected"
|
||||
@@ -1014,31 +1014,27 @@ msgstr "Sambia"
|
||||
msgid "Zimbabwe"
|
||||
msgstr "Zimbabwe"
|
||||
|
||||
#: src/utils/html5/forms.py:43
|
||||
#: src/utils/html5/forms.py:48
|
||||
msgid ""
|
||||
"Select a valid choice. That choice is not one of the available "
|
||||
"choices."
|
||||
msgstr ""
|
||||
"Bitte eine gültige Auswahl treffen. Diese Option steht nicht zur Verfügung."
|
||||
|
||||
#: src/utils/html5/forms.py:89
|
||||
#: src/utils/html5/forms.py:94
|
||||
msgid ""
|
||||
"Select a valid choice. That choice is not one of the available "
|
||||
"choices."
|
||||
msgstr ""
|
||||
"Bitte eine gültige Auswahl treffen. Diese Option steht nicht zur Verfügung."
|
||||
|
||||
#: src/utils/html5/forms.py:251
|
||||
msgid "The CAPTCHA challenge is missing."
|
||||
msgstr "Das CAPTCHA Rätsel wurde nicht gelöst"
|
||||
#: src/utils/html5/forms.py:132
|
||||
msgid "yyyy-mm-dd"
|
||||
msgstr "tt.mm.jjjj"
|
||||
|
||||
#: src/utils/html5/forms.py:254
|
||||
msgid "The CAPTCHA solution is missing."
|
||||
msgstr "Das CAPTCHA wurde nicht richtig gelöst."
|
||||
|
||||
#: src/utils/html5/forms.py:259
|
||||
msgid "The CAPTCHA solution was incorrect."
|
||||
msgstr "Das CAPTCHA wurde nicht richtig gelöst."
|
||||
#: src/utils/html5/forms.py:238
|
||||
msgid "Only humans are allowed to submit this form."
|
||||
msgstr "Nur Menschen dürfen dieses Formular übermitteln."
|
||||
|
||||
#: src/utils/management/commands/compresscss.py:22
|
||||
#: src/utils/management/commands/compressjs.py:21
|
||||
@@ -1071,3 +1067,15 @@ msgstr "Du hast nicht genügend Rechte dafür."
|
||||
#: src/utils/mixins.py:100
|
||||
msgid "You don't have the permissions for this"
|
||||
msgstr "Du hast nicht genügend Rechte dafür."
|
||||
|
||||
#~ msgid "dd.mm.yyyy"
|
||||
#~ msgstr "tt.mm.jjjj"
|
||||
|
||||
#~ msgid "The CAPTCHA challenge is missing."
|
||||
#~ msgstr "Das CAPTCHA Rätsel wurde nicht gelöst"
|
||||
|
||||
#~ msgid "The CAPTCHA solution is missing."
|
||||
#~ msgstr "Das CAPTCHA wurde nicht richtig gelöst."
|
||||
|
||||
#~ msgid "The CAPTCHA solution was incorrect."
|
||||
#~ msgstr "Das CAPTCHA wurde nicht richtig gelöst."
|
||||
|
||||
Reference in New Issue
Block a user