Skip to content

Commit 5e90fca

Browse files
committed
first commit
0 parents  commit 5e90fca

39 files changed

+1386
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
.idea
3+
.postgres
4+
**__pycache__**
5+
*.pyc

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM python:3.6-slim
2+
3+
# Copy the application code to the container:
4+
RUN mkdir /code/
5+
WORKDIR /code/
6+
ADD . /code/
7+
8+
# Install all build deps:
9+
RUN set -ex \
10+
&& apt-get update \
11+
&& apt-get install -y \
12+
gcc \
13+
libjpeg62 \
14+
libjpeg62-turbo-dev \
15+
libpq-dev \
16+
make \
17+
postgresql-client \
18+
&& pip install --no-cache-dir -r /code/requirements.txt
19+
20+
# expose port
21+
EXPOSE 8000
22+
23+
# Docker entrypoint:
24+
ENV DJANGO_MANAGEPY_MIGRATE=on \
25+
DJANGO_MANAGEPY_COLLECTSTATIC=on \
26+
DJANGO_MANAGEPY_UPDATEINDEX=on
27+
ENTRYPOINT ["/code/docker-entrypoint.sh"]
28+
29+
# Start python runserver:
30+
CMD ["python", "./manage.py", "runserver", "0.0.0.0:8000"]

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include *.md

README.md

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# wagtail_streamforms
2+
3+
## General Setup
4+
5+
1. Add wagtail_streamforms to your INSTALLED_APPS:
6+
7+
```
8+
INSTALLED_APPS = [
9+
...
10+
'wagtail_streamforms'
11+
...
12+
]
13+
```
14+
15+
2. Define the form templates in your settings.py:
16+
17+
```python
18+
# defaults
19+
WAGTAIL_STREAMFORMS_FORM_TEMPLATES = (
20+
('streamforms/form_block.html', 'Default Form Template'),
21+
)
22+
```
23+
24+
3. Include in your base template the javascript to handle the post and response
25+
26+
```html
27+
<script src="//code.jquery.com/jquery-2.2.4.min.js"></script>
28+
<script src="{% static 'streamforms/js/form-handler.js' %}"></script>
29+
```
30+
31+
## Enable Recaptcha
32+
33+
Has been enabled via the [django-recaptcha](https://github.com/praekelt/django-recaptcha) package. Please note that only one recapcha should be used per page.
34+
35+
Just add captcha to your INSTALLED_APPS:
36+
37+
```
38+
INSTALLED_APPS = [
39+
...
40+
'captcha'
41+
...
42+
]
43+
```
44+
45+
and add the required keys in your settings.py which you can get from google's recapcha service:
46+
47+
```
48+
RECAPTCHA_PUBLIC_KEY = 'xxx'
49+
RECAPTCHA_PRIVATE_KEY = 'xxx'
50+
51+
# To use the new No Captcha reCaptcha
52+
NOCAPTCHA = True
53+
```
54+
55+
## Styling Form Errors
56+
57+
Below is an example of the css you will need to highlight the form errors:
58+
59+
```scss
60+
// errors
61+
.has-error input,
62+
.has-error select,
63+
.has-error textarea { border-color: red; }
64+
65+
.has-error label,
66+
.has-error .error-msg { color: red; }
67+
68+
// recaptcha
69+
.g-recaptcha { margin-bottom: 20px; }
70+
```
71+
72+
## Example Site
73+
74+
1. Run the docker container
75+
76+
```bash
77+
$ docker-compose up
78+
```
79+
80+
2. Create yourself a superuser
81+
```bash
82+
$ docker exec -it <container_name> bash
83+
$ python manage.py createsuperuser
84+
```
85+
86+
3. Go to [http://127.0.0.1:8000](http://127.0.0.1:8000)

docker-compose.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: '2'
2+
3+
# run the app in development mode
4+
5+
services:
6+
app:
7+
build: .
8+
tty: true
9+
volumes:
10+
- .:/code
11+
environment:
12+
- DJANGO_MANAGEPY_COLLECTSTATIC=off
13+
- DJANGO_SETTINGS_MODULE=example.settings
14+
- SECRET_KEY=secret
15+
- ALLOWED_HOSTS=*
16+
- RDS_HOSTNAME=db
17+
- RDS_PORT=5432
18+
- RDS_DB_NAME=postgres
19+
- RDS_USERNAME=postgres
20+
- RDS_PASSWORD=password
21+
- EMAIL_HOST=mail
22+
- EMAIL_PORT=1025
23+
depends_on:
24+
- db
25+
- mail
26+
ports:
27+
- 8000:8000
28+
db:
29+
image: postgres
30+
environment:
31+
- POSTGRES_USER=postgres
32+
- POSTGRES_PASSWORD=password
33+
- POSTGRES_DB=postgres
34+
- PGDATA=/var/lib/postgresql/data/pgdata
35+
volumes:
36+
- ./.postgres:/var/lib/postgresql/data/pgdata
37+
ports:
38+
- 5432:5432
39+
mail:
40+
image: mailhog/mailhog
41+
ports:
42+
- 8025:8025

docker-entrypoint.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
set -e
3+
4+
export PGPASSWORD=$RDS_PASSWORD
5+
6+
while ! psql -h $RDS_HOSTNAME -d $RDS_DB_NAME -p $RDS_PORT -U $RDS_USERNAME -c "SELECT version();" > /dev/null 2>&1; do
7+
echo 'Waiting for connection with db...'
8+
sleep 1;
9+
done;
10+
echo 'Connected to db...';
11+
12+
if [ "x$DJANGO_MANAGEPY_MIGRATE" = 'xon' ]; then
13+
python manage.py migrate --noinput
14+
fi
15+
16+
if [ "x$DJANGO_MANAGEPY_COLLECTSTATIC" = 'xon' ]; then
17+
python manage.py collectstatic --noinput
18+
fi
19+
20+
if [ "x$DJANGO_MANAGEPY_UPDATEINDEX" = 'xon' ]; then
21+
python manage.py update_index
22+
fi
23+
24+
exec "$@"

example/migrations/0001_initial.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.6 on 2017-10-10 00:27
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
import wagtail.wagtailcore.blocks
8+
import wagtail.wagtailcore.fields
9+
import wagtail_streamforms.blocks
10+
11+
12+
class Migration(migrations.Migration):
13+
14+
initial = True
15+
16+
dependencies = [
17+
('wagtailcore', '0040_page_draft_title'),
18+
]
19+
20+
operations = [
21+
migrations.CreateModel(
22+
name='BasicPage',
23+
fields=[
24+
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
25+
('body', wagtail.wagtailcore.fields.StreamField((('form', wagtail.wagtailcore.blocks.StructBlock((('form', wagtail_streamforms.blocks.FormChooserBlock()),))),))),
26+
],
27+
options={
28+
'abstract': False,
29+
},
30+
bases=('wagtailcore.page',),
31+
),
32+
]

example/migrations/__init__.py

Whitespace-only changes.

example/models.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from wagtail.wagtailadmin.edit_handlers import StreamFieldPanel
2+
from wagtail.wagtailcore.fields import StreamField
3+
from wagtail.wagtailcore.models import Page
4+
from wagtail_streamforms.blocks import WagtailFormBlock
5+
6+
7+
class BasicPage(Page):
8+
9+
body = StreamField([
10+
('form', WagtailFormBlock())
11+
])
12+
13+
# show in menu ticked by default
14+
show_in_menus_default = True
15+
16+
content_panels = Page.content_panels + [
17+
StreamFieldPanel('body'),
18+
]

0 commit comments

Comments
 (0)