https://github.com/apkawa/django-subscribe-form
https://github.com/apkawa/django-subscribe-form
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/apkawa/django-subscribe-form
- Owner: Apkawa
- License: mit
- Created: 2017-11-03T16:39:13.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-28T08:26:48.000Z (over 3 years ago)
- Last Synced: 2025-03-18T08:49:48.860Z (over 1 year ago)
- Language: Python
- Size: 557 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/Apkawa/django-multitype-file-field)
[](https://coveralls.io/github/Apkawa/django-multitype-file-field)
[](https://codecov.io/gh/Apkawa/django-multitype-file-field)
[](https://requires.io/github/Apkawa/django-multitype-file-field/requirements/?branch=master)
[]()
Project for merging different file types, as example easy thumbnail image and unpacking archive in one field
# Installation
```bash
pip install django-subscribe-form
```
or from git
```bash
pip install -e git+https://github.com/Apkawa/django-subscribe-form.git#egg=django-subscribe-form
```
## Django and python version
* 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
# Configuration
1. Add to `INSTALLED_APPS` `post_office`, `corsheaders` and `subscribe_form`
```python
INSTALLED_APPS = [
#...
'post_office',
'subscribe_form',
#...
]
```
2. Configure `corsheaders`
```python
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',
)
```
2. Add to `urls.py`
```python
from django.conf.urls import include, url
urlpatterns = [
url(r'^subscribe/', include('subscribe_form.urls')),
]
```
3. Run migrations
```bash
./manage migrate
```
# Usage
1. Create `post_office.EmailTemplate` instance in admin
[http://127.0.0.1:8000/admin/post_office/emailtemplate/add/](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 }}
```
2. Create `subscribe_form.EmailTemplate` instance
[http://127.0.0.1:8000/admin/subscribe_form/emailtemplate/add/](http://127.0.0.1:8000/admin/subscribe_form/emailtemplate/add/)
3. Create `subscrube_form.Form` instance and get emdedding code
4. Add embedding code to page:
```
```
# API
## Simple usage
```
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}]'
```
## Send file
```
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" \
```
# Contributing
## run tests
```bash
pip install -r requirements.txt
./test/manage.py migrate
pytest
tox
```
## publish pypi
```bash
python setup.py sdist upload -r pypi
```