Permalink
Browse files

add "phone number" honeypot

  • Loading branch information...
1 parent c1ad95e commit 645604c194230fdfd5874e18e69f65aa35dc0419 @bryanhelmig bryanhelmig committed Oct 1, 2012
View
@@ -4,7 +4,7 @@
from knowledge import settings
from knowledge.models import Question, Response
-OPTIONAL_FIELDS = ['alert']
+OPTIONAL_FIELDS = ['alert', 'phone_number']
__todo__ = """
@@ -55,6 +55,9 @@ def __init__(self, *args, **kwargs):
qf.widget = qf.hidden_widget()
qf.required = False
+ # honey pot!
+ phone_number = forms.CharField(required=False)
+
def clean_user(self):
return user
@@ -109,6 +112,9 @@ def __init__(self, *args, **kwargs):
qf.widget = qf.hidden_widget()
qf.required = False
+ # honey pot!
+ phone_number = forms.CharField(required=False)
+
def clean_user(self):
return user
@@ -100,14 +100,16 @@
background: #e7e7e7; }
.dk-inner .dk-content .dk-widget form.dk-form .field-wrapper {
padding-bottom: 12px; }
+ .dk-inner .dk-content .dk-widget form.dk-form .field-wrapper.field-phone_number {
+ display: none; }
.dk-inner .dk-content .dk-widget form.dk-form .field-wrapper .field-label label {
font-size: 14px;
font-weight: 600; }
.dk-inner .dk-content .dk-widget form.dk-form .field-wrapper .field-label small {
font-size: 11px; }
.dk-inner .dk-content .dk-widget form.dk-form .field-wrapper input, .dk-inner .dk-content .dk-widget form.dk-form .field-wrapper textarea {
padding: 8px 1%;
- font-size: 14px;
+ font-size: 12px;
width: 96%;
border: 1px solid #ccc; }
.dk-inner .dk-content .dk-widget form.dk-form .field-wrapper input[type=checkbox] {
@@ -100,6 +100,10 @@
.field-wrapper {
padding-bottom:12px;
+ &.field-phone_number {
+ display:none;
+ }
+
.field-label {
label { font-size:14px; font-weight:600; }
small { font-size:11px; }
@@ -4,7 +4,7 @@
{% csrf_token %}
{% for field in form.visible_fields %}
- <div class="field-wrapper">
+ <div class="field-wrapper field-{{ field.html_name }}">
<div class="field-label">
<label for="id_{{ field.html_name }}">{{ field.label }}: {% if field.field.required %}<small><em class="quiet">({% trans "required" %})</em></small>{% endif %}</label>
View
@@ -121,7 +121,8 @@ def knowledge_thread(request,
if request.method == 'POST':
form = Form(request.user, question, request.POST)
if form and form.is_valid():
- form.save()
+ if request.user.is_authenticated() or not form.cleaned_data['phone_number']:
+ form.save()
return redirect(question.get_absolute_url())
else:
form = Form(request.user, question)
@@ -203,8 +204,11 @@ def knowledge_ask(request,
if request.method == 'POST':
form = Form(request.user, request.POST)
if form and form.is_valid():
- question = form.save()
- return redirect(question.get_absolute_url())
+ if request.user.is_authenticated() or not form.cleaned_data['phone_number']:
+ question = form.save()
+ return redirect(question.get_absolute_url())
+ else:
+ return redirect('knowledge_index')
else:
form = Form(request.user)
View
@@ -54,4 +54,4 @@
os.path.join(DIRNAME, 'templates').replace('\\','/')
)
-LOGIN_REDIRECT_URL = '/admin/'
+LOGIN_REDIRECT_URL = '/admin/'

0 comments on commit 645604c

Please sign in to comment.