Skip to content

Commit

Permalink
Added recaptcha to formpage (#493)
Browse files Browse the repository at this point in the history
* Rename extra css to extra head

* Install wagtail recaptcha

* added recaptcha to form page

* added missing migration

* small fixes
  • Loading branch information
dakaza98 authored Oct 24, 2020
1 parent ca55d43 commit 33c917c
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 15 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ wagtailmedia==0.6.0
django-instagram==0.3.2

djangorestframework==3.12.1

# Recaptcha for wagtail form pages
wagtail-django-recaptcha==1.0
28 changes: 28 additions & 0 deletions src/google/migrations/0026_auto_20201023_1815.py

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions src/home/migrations/0046_auto_20201023_1650.py

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/home/migrations/0047_auto_20201023_1815.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.13 on 2020-10-23 16:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('home', '0046_auto_20201023_1650'),
]

operations = [
migrations.AlterField(
model_name='formpage',
name='use_recaptcha',
field=models.BooleanField(default=False, verbose_name='Use Recaptcha'),
),
]
15 changes: 13 additions & 2 deletions src/home/models/form_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
from blocks.models import WAGTAIL_STATIC_BLOCKTYPES
from utils.translation import TranslatedField
from involvement.blocks import ContactCardBlock
from wagtailcaptcha.models import WagtailCaptchaEmailForm


class FormPage(AbstractEmailForm):
class FormPage(WagtailCaptchaEmailForm):

title_sv = models.CharField(max_length=255)
translated_title = TranslatedField('title', 'title_sv')
use_recaptcha = models.BooleanField(
default=False,
verbose_name=_("Use Recaptcha"),
)

intro_en = StreamField(
WAGTAIL_STATIC_BLOCKTYPES + [
Expand Down Expand Up @@ -84,10 +89,16 @@ class FormPage(AbstractEmailForm):
StreamFieldPanel('thank_you_text_sv'),
]

custom_settings_panel = Page.settings_panels + [
MultiFieldPanel([
FieldPanel('use_recaptcha'),
], 'Recaptcha')
]

edit_handler = TabbedInterface([
ObjectList(general_panels, heading=_('General')),
ObjectList(content_panels_en, heading=_('English')),
ObjectList(content_panels_sv, heading=_('Swedish')),
ObjectList(Page.promote_panels, heading=_('Promote')),
ObjectList(Page.settings_panels, heading=_('Settings')),
ObjectList(custom_settings_panel, heading=_('Settings')),
])
4 changes: 2 additions & 2 deletions src/home/templates/home/contact_page.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "page.html" %}
{% load i18n involvement_tags wagtailcore_tags %}

{% block extra_css %}
{% block extra_head %}
{{ block.super }}
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" crossorigin=""/>
{% endblock %}
Expand Down Expand Up @@ -62,4 +62,4 @@ <h2>{% trans 'our team'|title %}</h2>
{% endfor %}
</div>
</div>
{% endblock %}
{% endblock %}
6 changes: 5 additions & 1 deletion src/home/templates/home/form_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
<form action="{% pageurl page %}" method="POST">
{% csrf_token %}
{% for field in form %}
{% materialize_field field %}
{% if field.id_for_label != 'id_wagtailcaptcha' %}
{% materialize_field field %}
{% elif page.use_recaptcha %}
{{field}}
{% endif %}
{% endfor %}
<button id="submit" type="submit" class="btn btn-inverse">{% trans 'send' %}</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "modeladmin/create.html" %}
{% load i18n %}

{% block extra_css %}
{% block extra_head %}
{{ block.super }}
<style>
.field-content {
Expand Down Expand Up @@ -89,4 +89,4 @@ <h2>{% trans 'manual appointment' %}</h2>
<span class="icon icon-spinner"></span><em>{% trans 'Save' %}</em>
</button>
</div>
{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "modeladmin/create.html" %}
{% load i18n %}

{% block extra_css %}
{% block extra_head %}
{{ block.super }}
<style>
.field-content {
Expand Down Expand Up @@ -74,4 +74,4 @@ <h2>{{ form.instance.applicant }}</h2>
<span class="icon icon-spinner"></span><em>{% trans 'Save' %}</em>
</button>
</div>
{% endblock %}
{% endblock %}
4 changes: 2 additions & 2 deletions src/members/templates/wagtailusers/users/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</form>
{% endblock %}

{% block extra_css %}
{% block extra_head %}
{{ block.super }}
{% include "wagtailadmin/pages/_editor_css.html" %}
{{ form.media.css }}
Expand All @@ -60,4 +60,4 @@
{{ block.super }}
{% include "wagtailadmin/pages/_editor_js.html" %}
{{ form.media.js }}
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion src/members/templates/wagtailusers/users/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
</form>
{% endblock %}

{% block extra_css %}
{% block extra_head %}
{{ block.super }}
{% include "wagtailadmin/pages/_editor_css.html" %}
{{ form.media.css }}
Expand Down
4 changes: 4 additions & 0 deletions src/moore/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
'wagtailfontawesome',
'django_instagram',
'rest_framework',
'wagtailcaptcha',
'captcha',

'django.contrib.admin', # Used for wagtail admin filters
'django.contrib.auth',
Expand Down Expand Up @@ -225,3 +227,5 @@
'rest_framework.renderers.JSONRenderer',
]
}

SILENCED_SYSTEM_CHECKS = ['captcha.recaptcha_test_key_error']
3 changes: 3 additions & 0 deletions src/moore/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
# Google API
GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY')

RECAPTCHA_PUBLIC_KEY = os.environ.get("RECAPTCHA_PUBLIC_KEY", "ss")
RECAPTCHA_PRIVATE_KEY = os.environ.get("RECAPTCHA_PRIVATE_KEY", "ss")

try:
from .local import *
except ImportError:
Expand Down
6 changes: 3 additions & 3 deletions src/moore/templates/skeleton.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<link href="{% static 'sass/noyce.scss' %}" rel="stylesheet" type="text/x-scss" id="css-primary">
{% endcompress %}

{% block extra_css %}
{# Override this in templates to add extra stylesheets #}
{% block extra_head %}
{# Override this in templates to add extra things in head tag #}
{% endblock %}
</head>

Expand All @@ -49,4 +49,4 @@
{% endblock %}
</body>

</html>
</html>

0 comments on commit 33c917c

Please sign in to comment.