Skip to content

Commit

Permalink
add recaptcha support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ogero committed Jan 3, 2017
1 parent 7676d31 commit 0131624
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-e git://github.com/maxicecilia/django_site_news.git@7d320097cedec159e396ad3d223b3919d6449c3e#egg=django_site_news-0.1.1
-e git://github.com/maxicecilia/[email protected]#egg=django_contact_us
-e git://github.com/bfirsh/django-ordered-model.git#egg=django-ordered-model
argparse==1.2.1
django-bootstrap3==5.1.1
django-dropbox==0.0.2
Expand All @@ -20,3 +19,4 @@ django-grappelli==2.6.4
django-memcache-status==1.1
django-ordered-model==0.4.0
python-memcached==1.54
django-recaptcha2==v1.0.0
Empty file.
26 changes: 26 additions & 0 deletions simple_classroom/apps/contact_us/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from django.forms import ModelForm
from snowpenguin.django.recaptcha2.fields import ReCaptchaField
from snowpenguin.django.recaptcha2.widgets import ReCaptchaWidget

from contact_us.models import SimpleContact


class CaptchaContactForm(ModelForm):
captcha = ReCaptchaField(widget=ReCaptchaWidget())
'''
Cpatcha enabled default form model for collect contact data.
'''
class Meta:
model = SimpleContact
fields = ('from_name', 'from_email', 'from_phone', 'message')


class SimpleCaptchaContactForm(ModelForm):
captcha = ReCaptchaField(widget=ReCaptchaWidget(explicit=True))
'''
Cpatcha enabled simplified contact form, ignore phone input.
'''
class Meta:
model = SimpleContact
fields = ('from_name', 'from_email', 'message')
20 changes: 20 additions & 0 deletions simple_classroom/apps/contact_us/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from django.conf import settings
from contact_us.views import ContactUsFormView as ContactUsFormViewExt
from contact_us.forms import ContactForm, SimpleContactForm

from forms import CaptchaContactForm, SimpleCaptchaContactForm

class ContactUsFormView(ContactUsFormViewExt):

def get_form_class(self):
"""
Returns the form class to use in this view
"""
if settings.CONTACT_US_FORM_STYLE == 'simple':
self.form_class = SimpleContactForm
if settings.CONTACT_US_FORM_STYLE == 'captcha':
self.form_class = CaptchaContactForm
if settings.CONTACT_US_FORM_STYLE == 'simplecaptcha':
self.form_class = SimpleCaptchaContactForm
return super(ContactUsFormView, self).get_form_class()
7 changes: 6 additions & 1 deletion simple_classroom/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'sitetree',
'tinymce',
'ordered_model',
'snowpenguin.django.recaptcha2',
'simple_classroom.apps.core',
'simple_classroom.apps.classroom',
'simple_classroom.apps.downloads',
Expand Down Expand Up @@ -143,6 +144,10 @@
DROPBOX_ACCESS_TOKEN = ''
DROPBOX_ACCESS_TOKEN_SECRET = ''

# ReCaptcha Site and Secret keys.
RECAPTCHA_PRIVATE_KEY = ''
RECAPTCHA_PUBLIC_KEY = ''

# Title used to retrieve the default download file.
ASSIGNMENT_DEFAULT_DOWNLOAD = 'evaluativo'

Expand All @@ -161,7 +166,7 @@

# Contact-us settings
CONTACT_US_RECIPIENTS_LIST = ['[email protected]', ]
CONTACT_US_FORM_STYLE = 'simple'
CONTACT_US_FORM_STYLE = 'simplecaptcha'

# Grappelli
GRAPPELLI_ADMIN_TITLE = u'Administracion'
Expand Down
2 changes: 2 additions & 0 deletions simple_classroom/templates/contact_us/contact_form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "core/base.html" %}
{% load bootstrap3 %}
{% load recaptcha2 %}

{% block main-content %}
<div class="row bottom-buffer top-buffer">
Expand All @@ -20,6 +21,7 @@ <h2>Opiniones</h2>
</button>
{% endbuttons %}
</form>
{% recaptcha_explicit_init 'es'%}
</div>
{% else %}
<div class="col-md-10">
Expand Down
2 changes: 2 additions & 0 deletions simple_classroom/templates/core/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load sitetree staticfiles %}
{% load recaptcha2 %}
<!DOCTYPE html>
<html lang="es">
<head>
Expand All @@ -19,6 +20,7 @@
<script src="https:http://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https:http://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
{% recaptcha_explicit_support %}
<!-- end bootstrap -->
{% block main_css %}
<link rel="stylesheet" href="{% static "css/style.css" %}">
Expand Down
2 changes: 1 addition & 1 deletion simple_classroom/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.views.generic import TemplateView
from contact_us.views import ContactUsFormView

from simple_classroom.apps.classroom.views import HomeView
from simple_classroom.apps.contact_us.views import ContactUsFormView


urlpatterns = patterns(
Expand Down

0 comments on commit 0131624

Please sign in to comment.