Project for merging different file types, as example easy thumbnail image and unpacking archive in one field
pip install django-subscribe-form
or from git
pip install -e git+https://github.com/Apkawa/django-subscribe-form.git#egg=django-subscribe-form
- python-2.7 - django>=1.8,<=1.11
- python-3.4 - django>=1.8,<=1.11
- python-3.5 - django>=1.8,<=1.11
- python-3.6 - django>=1.11
- Add to
INSTALLED_APPS
post_office
,corsheaders
andsubscribe_form
INSTALLED_APPS = [
#...
'post_office',
'subscribe_form',
#...
]
- Configure
corsheaders
MIDDLEWARE_CLASSES = (
#...
'corsheaders.middleware.CorsMiddleware',
#...
)
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
from corsheaders.defaults import default_headers
CORS_ALLOW_HEADERS = default_headers + (
'api-key',
)
- Add to
urls.py
from django.conf.urls import include, url
urlpatterns = [
url(r'^subscribe/', include('subscribe_form.urls')),
]
- Run migrations
./manage migrate
- Create
post_office.EmailTemplate
instance in admin http://127.0.0.1:8000/admin/post_office/emailtemplate/add/
Example content fields
subject
From site {{ host }} was submited form from {{ fields.full_name.value|default:email }}
content
{{ fields.full_name.value }}
{% for key,field in fields.items %}
{{ field.display_name|default:key }}: {{ field.value }}
{% endfor %}
Host: {{ host }}
Referer: {{ referer }}
-
Create
subscribe_form.EmailTemplate
instance http://127.0.0.1:8000/admin/subscribe_form/emailtemplate/add/ -
Create
subscrube_form.Form
instance and get emdedding code -
Add embedding code to page:
<script
data-endpoint="//example.com/api/v1/subscribe/subscribe/"
data-key="4a96f68d-7acb-4f7f-8e43-63e8902bf08f"
src="//example.com/static/subscribe_form/js/subscribe.js?r=dev">
</script>
curl -X POST //example.com/api/v1/subscribe/subscribe/ \
-H "Content-Type: multipart/form-data" \
-H 'API-Key: 4a96f68d-7acb-4f7f-8e43-63e8902bf08f' \
-H 'Accept: application/json' \
-F form_data='[{"value": "example@email.com", "display_name": "User email*", "name": "email", "is_file": false}]'
curl -X POST //example.com/api/v1/subscribe/subscribe/ \
-H "Content-Type: multipart/form-data" \
-H 'API-Key: 4a96f68d-7acb-4f7f-8e43-63e8902bf08f' \
-H 'Accept: application/json' \
-F form_data='[{"display_name": "User avatar*", "name": "avatar", "is_file": true}]' \
-F "avatar=@/home/user/avatar.png" \
pip install -r requirements.txt
./test/manage.py migrate
pytest
tox
python setup.py sdist upload -r pypi