File tree Expand file tree Collapse file tree 9 files changed +101
-12
lines changed Expand file tree Collapse file tree 9 files changed +101
-12
lines changed Original file line number Diff line number Diff line change 3
3
language : python
4
4
5
5
python :
6
- - " 3.5 "
6
+ - " 3.7 "
7
7
8
8
env :
9
- - TOX_ENV=py35 -django-19
10
- - TOX_ENV=py34 -django-19
11
- - TOX_ENV=py35 -django-110
12
- - TOX_ENV=py34 -django-110
13
- - TOX_ENV=py35 -django-111
14
- - TOX_ENV=py34 -django-111
9
+ - TOX_ENV=py36 -django-111
10
+ - TOX_ENV=py37 -django-111
11
+ - TOX_ENV=py36 -django-20
12
+ - TOX_ENV=py37 -django-20
13
+ - TOX_ENV=py36 -django-21
14
+ - TOX_ENV=py37 -django-21
15
15
16
16
matrix :
17
17
fast_finish : true
Original file line number Diff line number Diff line change 4
4
from django .views import View
5
5
from django .views .generic .edit import FormMixin
6
6
from django .views .generic .base import TemplateResponseMixin
7
- from .forms import TypeformMixin
8
7
9
8
10
9
class BaseTypeformView (FormMixin , View ):
Original file line number Diff line number Diff line change 2
2
TypeformMixin
3
3
=============
4
4
5
- The ``TypeformMixin `` is a mixin for Django's form class. To turn
6
- Typeform features on for a Django form just use the Mixin:
5
+ To process a typeform in Django just the way you would process a Django form,
6
+ use the ``TypeformMixin ``. It requires the typeform to be mirrored by a corresponding
7
+ Django form, question by question, but can also contain processing logic.
8
+ To turn Typeform features on for a Django form just use the Mixin and specify
9
+ the ``typeform_url ``:
7
10
8
11
.. code-block :: python
9
12
@@ -14,7 +17,7 @@ Typeform features on for a Django form just use the Mixin:
14
17
class MyTypeForm (TypeformMixin , MyForm )
15
18
typeform_url = 'https :// xxxx.typeform.com/ to/ xxxxxx'
16
19
17
- ``MyTypeForm `` will be a fully fledge Django form and at the same
20
+ ``MyTypeForm `` will be a fully fledged Django form and at the same
18
21
time be linked to the Typeform with given url.
19
22
20
23
For this link to work, the ``Question reference `` for each Typeform
Original file line number Diff line number Diff line change
1
+ ============
2
+ TypeformView
3
+ ============
4
+
5
+ The ``TypeformView `` replaces the ``FormView `` class and is the default view
6
+ for typeforms.
7
+
8
+ Upon get requests it displays the typeform using the ``template_name `` property
9
+ just like a ``FormView ``. Upon completion of the typeform the rendered
10
+ typeform posts the typeform's unique id to the view.
11
+
12
+ ``TypeformView `` intercepts this post request, uses the Typeform Results
13
+ API and retrieves the answers the user has just entered. These answers are
14
+ encoded as a ``QueryDict `` and forwarded for form processing.
15
+
16
+ This way the use of ``TypeformView `` becomes transparent for Django.
17
+
18
+ See this example, taken from ``urls.py ``:
19
+
20
+ .. code-block :: python
21
+
22
+ from django.urls import path
23
+ from django_typeform.views import TypeformView
24
+
25
+ from .forms import MyTypeForm
26
+
27
+ urlpatterns = [
28
+ ... ,
29
+ path(' my-typeform/' , TypeformView.as_view(
30
+ form_class = MyTypeForm,
31
+ template_name = ' mytypeform.html' ,
32
+ )),
33
+ ... ,
34
+ ]
35
+
36
+ where a simple template might look like this (``mytypeform.html ``):
37
+
38
+ .. code-block :: html
39
+
40
+ {% extends 'base.html' %}
41
+ {% block content %}
42
+ <form method =" post" >
43
+ {% include form with height='100vh' %}
44
+ </form >
45
+ {% endblock %}
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8
2
2
from __future__ import unicode_literals , absolute_import
3
3
4
+ import os
5
+
4
6
import django
5
7
8
+ BASE_DIR = os .path .dirname (os .path .dirname (__file__ ))
9
+
6
10
DEBUG = True
7
11
USE_TZ = True
8
12
23
27
"django.contrib.contenttypes" ,
24
28
"django.contrib.sites" ,
25
29
"django_typeform" ,
30
+ "sekizai" ,
26
31
]
27
32
33
+ TEMPLATES = [
34
+ {
35
+ 'BACKEND' : 'django.template.backends.django.DjangoTemplates' ,
36
+ 'DIRS' : [os .path .join (BASE_DIR , "tests/templates" )],
37
+ 'APP_DIRS' : True ,
38
+ },
39
+ ]
40
+
41
+
28
42
SITE_ID = 1
29
43
30
44
if django .VERSION >= (1 , 10 ):
Original file line number Diff line number Diff line change
1
+ < form method ="post ">
2
+ {% include form with height='100vh' %}
3
+ </ form >
Original file line number Diff line number Diff line change 8
8
class MyForm (TypeformMixin , Form ):
9
9
pass
10
10
11
+
11
12
class TypeformMixinTest (SimpleTestCase ):
12
13
def test_mixin (self ):
13
14
form = MyForm (typeform_url = 'https://whatever.typeform.com/to/xxxxxx' )
14
15
self .assertEqual (form .typeform_id , 'xxxxxx' )
15
16
17
+ def test_mixin_rendering (self ):
18
+ class Request (object ):
19
+ session = {}
20
+
21
+ request = Request ()
22
+ form = MyForm (typeform_url = 'https://whatever.typeform.com/to/xxxxxx' )
23
+
24
+ form .get_uid (Request ())
25
+ self .assertFalse (not request .session , 'typeformuid not stored in session' )
26
+ form .render (Context ({'request' : Request ()}))
Original file line number Diff line number Diff line change
1
+ from django .test import SimpleTestCase
2
+ from django .test import Client
3
+
4
+ class TypeformViewTest (SimpleTestCase ):
5
+ def test_view (self ):
6
+ c = Client ()
7
+ response = c .get ('/testform/' )
8
+ self .assertEqual (response .status_code , 200 )
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
from __future__ import unicode_literals , absolute_import
3
3
4
- from django .conf .urls import url , include
4
+ from django .conf .urls import include , url
5
+ from django_typeform .views import TypeformView
6
+ from tests .test_forms import MyForm
5
7
6
8
7
9
urlpatterns = [
10
+ url (r'^testform/' , TypeformView .as_view (
11
+ template_name = 'typeform_test.html' ,
12
+ form_class = MyForm ,
13
+ ))
8
14
]
You can’t perform that action at this time.
0 commit comments