├── .coveragerc ├── .editorconfig ├── .github └── ISSUE_TEMPLATE.md ├── .gitignore ├── .idea └── inspectionProfiles │ └── Project_Default.xml ├── .travis.yml ├── AUTHORS.rst ├── CONTRIBUTING.rst ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── django_typeform ├── __init__.py ├── apps.py ├── forms.py ├── responses.py ├── templates │ └── django_typeform │ │ ├── typeform.html │ │ └── typeform_embed.html ├── templatetags │ ├── __init__.py │ └── django_typeform.py └── views.py ├── docs ├── Makefile ├── authors.rst ├── conf.py ├── configuration.rst ├── contributing.rst ├── django_typeform.rst ├── django_typeform.templatetags.rst ├── history.rst ├── index.rst ├── installation.rst ├── make.bat ├── modules.rst ├── objects.inv │ ├── django.inv │ └── python.inv ├── readme.rst ├── typeformmixin.rst ├── typeformview.rst └── usage.rst ├── manage.py ├── requirements.txt ├── requirements_dev.txt ├── requirements_test.txt ├── runtests.py ├── setup.cfg ├── setup.py ├── tests ├── __init__.py ├── settings.py ├── templates │ └── typeform_test.html ├── test_forms.py ├── test_views.py └── urls.py └── tox.ini /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | branch = true 3 | 4 | [report] 5 | omit = 6 | *site-packages* 7 | *tests* 8 | *.tox* 9 | show_missing = True 10 | exclude_lines = 11 | raise NotImplementedError 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.{py,rst,ini}] 12 | indent_style = space 13 | indent_size = 4 14 | 15 | [*.{html,css,scss,json,yml}] 16 | indent_style = space 17 | indent_size = 2 18 | 19 | [*.md] 20 | trim_trailing_whitespace = false 21 | 22 | [Makefile] 23 | indent_style = tab 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * Django Typeform version: 2 | * Django version: 3 | * Python version: 4 | * Operating System: 5 | 6 | ### Description 7 | 8 | Describe what you were trying to get done. 9 | Tell us what happened, what went wrong, and what you expected to happen. 10 | 11 | ### What I Did 12 | 13 | ``` 14 | Paste the command(s) you ran and the output. 15 | If there was a crash, please include the traceback here. 16 | ``` 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/code,python,django 3 | 4 | ### Code ### 5 | # Visual Studio Code - https://code.visualstudio.com/ 6 | .settings/ 7 | .vscode/ 8 | tsconfig.json 9 | jsconfig.json 10 | 11 | ### Django ### 12 | *.log 13 | *.pot 14 | *.pyc 15 | __pycache__/ 16 | local_settings.py 17 | db.sqlite3 18 | media 19 | 20 | # If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ 21 | # in your Git repository. Update and uncomment the following line accordingly. 22 | # /staticfiles/ 23 | 24 | ### Python ### 25 | # Byte-compiled / optimized / DLL files 26 | *.py[cod] 27 | *$py.class 28 | 29 | # C extensions 30 | *.so 31 | 32 | # Distribution / packaging 33 | .Python 34 | build/ 35 | develop-eggs/ 36 | dist/ 37 | downloads/ 38 | eggs/ 39 | .eggs/ 40 | lib/ 41 | lib64/ 42 | parts/ 43 | sdist/ 44 | var/ 45 | wheels/ 46 | *.egg-info/ 47 | .installed.cfg 48 | *.egg 49 | 50 | # PyInstaller 51 | # Usually these files are written by a python script from a template 52 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 53 | *.manifest 54 | *.spec 55 | 56 | # Installer logs 57 | pip-log.txt 58 | pip-delete-this-directory.txt 59 | 60 | # Unit test / coverage reports 61 | htmlcov/ 62 | .tox/ 63 | .coverage 64 | .coverage.* 65 | .cache 66 | nosetests.xml 67 | coverage.xml 68 | *.cover 69 | .hypothesis/ 70 | 71 | # Translations 72 | *.mo 73 | 74 | # Django stuff: 75 | 76 | # Flask stuff: 77 | instance/ 78 | .webassets-cache 79 | 80 | # Scrapy stuff: 81 | .scrapy 82 | 83 | # Sphinx documentation 84 | docs/_build/ 85 | 86 | # PyBuilder 87 | target/ 88 | 89 | # Jupyter Notebook 90 | .ipynb_checkpoints 91 | 92 | # pyenv 93 | .python-version 94 | 95 | # celery beat schedule file 96 | celerybeat-schedule 97 | 98 | # SageMath parsed files 99 | *.sage.py 100 | 101 | # Environments 102 | .env 103 | .venv 104 | env/ 105 | venv/ 106 | ENV/ 107 | env.bak/ 108 | venv.bak/ 109 | 110 | # Spyder project settings 111 | .spyderproject 112 | .spyproject 113 | 114 | # Rope project settings 115 | .ropeproject 116 | 117 | # mkdocs documentation 118 | /site 119 | 120 | # mypy 121 | .mypy_cache/ 122 | 123 | # End of https://www.gitignore.io/api/code,python,django 124 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for automatic testing at travis-ci.org 2 | 3 | dist: xenial 4 | 5 | language: python 6 | 7 | python: 8 | - "3.6" 9 | - "3.7" 10 | 11 | env: 12 | - TOX_ENV=py3-django-111 13 | - TOX_ENV=py3-django-20 14 | - TOX_ENV=py3-django-21 15 | 16 | matrix: 17 | fast_finish: true 18 | 19 | # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors 20 | install: pip install -r requirements_test.txt 21 | 22 | # command to run tests using coverage, e.g. python setup.py test 23 | script: tox -e $TOX_ENV 24 | 25 | after_success: 26 | - codecov -e TOX_ENV 27 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Credits 3 | ======= 4 | 5 | Development Lead 6 | ---------------- 7 | 8 | * Jafnee Jesmee 9 | 10 | Contributors 11 | ------------ 12 | 13 | * Fabian Braun 14 | 15 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Contributing 3 | ============ 4 | 5 | Contributions are welcome, and they are greatly appreciated! Every 6 | little bit helps, and credit will always be given. 7 | 8 | You can contribute in many ways: 9 | 10 | Types of Contributions 11 | ---------------------- 12 | 13 | Report Bugs 14 | ~~~~~~~~~~~ 15 | 16 | Report bugs at https://github.com/redapesolutions/django-typeform/issues. 17 | 18 | If you are reporting a bug, please include: 19 | 20 | * Your operating system name and version. 21 | * Any details about your local setup that might be helpful in troubleshooting. 22 | * Detailed steps to reproduce the bug. 23 | 24 | Fix Bugs 25 | ~~~~~~~~ 26 | 27 | Look through the GitHub issues for bugs. Anything tagged with "bug" 28 | is open to whoever wants to implement it. 29 | 30 | Implement Features 31 | ~~~~~~~~~~~~~~~~~~ 32 | 33 | Look through the GitHub issues for features. Anything tagged with "feature" 34 | is open to whoever wants to implement it. 35 | 36 | Write Documentation 37 | ~~~~~~~~~~~~~~~~~~~ 38 | 39 | Django Typeform could always use more documentation, whether as part of the 40 | official Django Typeform docs, in docstrings, or even on the web in blog posts, 41 | articles, and such. 42 | 43 | Submit Feedback 44 | ~~~~~~~~~~~~~~~ 45 | 46 | The best way to send feedback is to file an issue at https://github.com/redapesolutions/django-typeform/issues. 47 | 48 | If you are proposing a feature: 49 | 50 | * Explain in detail how it would work. 51 | * Keep the scope as narrow as possible, to make it easier to implement. 52 | * Remember that this is a volunteer-driven project, and that contributions 53 | are welcome :) 54 | 55 | Get Started! 56 | ------------ 57 | 58 | Ready to contribute? Here's how to set up `django-typeform` for local development. 59 | 60 | 1. Fork the `django-typeform` repo on GitHub. 61 | 2. Clone your fork locally:: 62 | 63 | $ git clone git@github.com:your_name_here/django-typeform.git 64 | 65 | 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: 66 | 67 | $ mkvirtualenv django-typeform 68 | $ cd django-typeform/ 69 | $ python setup.py develop 70 | 71 | 4. Create a branch for local development:: 72 | 73 | $ git checkout -b name-of-your-bugfix-or-feature 74 | 75 | Now you can make your changes locally. 76 | 77 | 5. When you're done making changes, check that your changes pass flake8 and the 78 | tests, including testing other Python versions with tox:: 79 | 80 | $ flake8 django_typeform tests 81 | $ python setup.py test 82 | $ tox 83 | 84 | To get flake8 and tox, just pip install them into your virtualenv. 85 | 86 | 6. Commit your changes and push your branch to GitHub:: 87 | 88 | $ git add . 89 | $ git commit -m "Your detailed description of your changes." 90 | $ git push origin name-of-your-bugfix-or-feature 91 | 92 | 7. Submit a pull request through the GitHub website. 93 | 94 | Pull Request Guidelines 95 | ----------------------- 96 | 97 | Before you submit a pull request, check that it meets these guidelines: 98 | 99 | 1. The pull request should include tests. 100 | 2. If the pull request adds functionality, the docs should be updated. Put 101 | your new functionality into a function with a docstring, and add the 102 | feature to the list in README.rst. 103 | 3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check 104 | https://travis-ci.org/redapesolutions/django-typeform/pull_requests 105 | and make sure that the tests pass for all supported Python versions. 106 | 107 | Tips 108 | ---- 109 | 110 | To run a subset of tests:: 111 | 112 | $ python -m unittest tests.test_django_typeform 113 | -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | .. :changelog: 2 | 3 | History 4 | ------- 5 | 6 | 0.2.0 (2019-07-18) 7 | ++++++++++++++++++ 8 | 9 | * Add TypeformMixin and TypeformView 10 | 11 | 0.1.0 (2017-10-05) 12 | ++++++++++++++++++ 13 | 14 | * Add Embed SDK support 15 | 16 | 0.0.0 (2017-10-05) 17 | ++++++++++++++++++ 18 | 19 | * First release on PyPI. 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | MIT License 3 | 4 | Copyright (c) 2017, Jafnee Jesmee 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS.rst 2 | include CONTRIBUTING.rst 3 | include HISTORY.rst 4 | include LICENSE 5 | include README.rst 6 | recursive-include django_typeform *.html *.png *.gif *js *.css *jpg *jpeg *svg *py 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean-pyc clean-build docs help 2 | .DEFAULT_GOAL := help 3 | define BROWSER_PYSCRIPT 4 | import os, webbrowser, sys 5 | try: 6 | from urllib import pathname2url 7 | except: 8 | from urllib.request import pathname2url 9 | 10 | webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) 11 | endef 12 | export BROWSER_PYSCRIPT 13 | BROWSER := python -c "$$BROWSER_PYSCRIPT" 14 | 15 | help: 16 | @perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}' 17 | 18 | clean: clean-build clean-pyc 19 | 20 | clean-build: ## remove build artifacts 21 | rm -fr build/ 22 | rm -fr dist/ 23 | rm -fr *.egg-info 24 | 25 | clean-pyc: ## remove Python file artifacts 26 | find . -name '*.pyc' -exec rm -f {} + 27 | find . -name '*.pyo' -exec rm -f {} + 28 | find . -name '*~' -exec rm -f {} + 29 | 30 | lint: ## check style with flake8 31 | flake8 django_typeform tests 32 | 33 | test: ## run tests quickly with the default Python 34 | python runtests.py tests 35 | 36 | test-all: ## run tests on every Python version with tox 37 | tox 38 | 39 | coverage: ## check code coverage quickly with the default Python 40 | coverage run --source django_typeform runtests.py tests 41 | coverage report -m 42 | coverage html 43 | open htmlcov/index.html 44 | 45 | docs: ## generate Sphinx HTML documentation, including API docs 46 | rm -f docs/django-typeform.rst 47 | rm -f docs/modules.rst 48 | sphinx-apidoc -o docs/ django_typeform 49 | $(MAKE) -C docs clean 50 | $(MAKE) -C docs html 51 | $(BROWSER) docs/_build/html/index.html 52 | 53 | release: clean ## package and upload a release 54 | python setup.py sdist upload 55 | python setup.py bdist_wheel upload 56 | 57 | sdist: clean ## package 58 | python setup.py sdist 59 | ls -l dist 60 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ============================= 2 | Django Typeform 3 | ============================= 4 | 5 | .. image:: https://badge.fury.io/py/django-typeform.svg 6 | :target: https://badge.fury.io/py/django-typeform 7 | 8 | .. image:: https://travis-ci.org/redapesolutions/django-typeform.svg?branch=master 9 | :target: https://travis-ci.org/redapesolutions/django-typeform 10 | 11 | .. image:: https://codecov.io/gh/redapesolutions/django-typeform/branch/master/graph/badge.svg 12 | :target: https://codecov.io/gh/redapesolutions/django-typeform 13 | 14 | 15 | A Typeform integration for Django 16 | 17 | Documentation 18 | ------------- 19 | 20 | The full documentation is at https://django-typeform.readthedocs.io. 21 | 22 | Quickstart 23 | ---------- 24 | 25 | Install Django Typeform:: 26 | 27 | pip install django-typeform 28 | 29 | Add it to your `INSTALLED_APPS`: 30 | 31 | .. code-block:: python 32 | 33 | INSTALLED_APPS = ( 34 | ... 35 | 'django_typeform.apps.DjangoTypeformConfig', 36 | ... 37 | ) 38 | 39 | Usage as template tag: 40 | 41 | .. code-block:: html 42 | 43 | {% load django_typeform %} 44 | 45 | 46 | {% typeforms_embed 'https://xxxx.typeform.com/to/xxxxxx' 'my-typeform' '{"hideHeaders": true, "hideFooter": true}' %} 47 | 48 | 49 | 50 | Features 51 | -------- 52 | 53 | * Embed SDK Support 54 | * Results API support 55 | * TypeformMixin to use Django forms to process typeform results 56 | * TypeformView to transparently integrate typeforms into the Django framework 57 | -------------------------------------------------------------------------------- /django_typeform/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.2.0' 2 | -------------------------------------------------------------------------------- /django_typeform/apps.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 2 | from django.apps import AppConfig 3 | 4 | 5 | class DjangoTypeformConfig(AppConfig): 6 | name = 'django_typeform' 7 | -------------------------------------------------------------------------------- /django_typeform/forms.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 2 | """Define TypeformMixin.""" 3 | import hashlib 4 | 5 | from django.template.loader import render_to_string 6 | from django.utils.crypto import get_random_string 7 | 8 | from .responses import TypeformResponses 9 | 10 | 11 | class TypeformMixin(object): 12 | """ 13 | Extend a Form class to add Typeform funcitonality. 14 | """ 15 | typeform_id = None 16 | typeform_url = None 17 | typeform_template = 'django_typeform/typeform.html' 18 | 19 | def __init__(self, *args, **kwargs): 20 | self.typeform_url = kwargs.pop('typeform_url', self.typeform_url) 21 | if self.typeform_url: 22 | if self.typeform_url[-1] == '/': # Skip trailing / 23 | self.typeform_url = self.typeform_url[:-1] 24 | self.typeform_id = self.typeform_url.rsplit('/', 1)[-1] # slug is typeform_id 25 | 26 | return super().__init__(*args, **kwargs) 27 | 28 | def typeform_to_query_dict(self, typeformuid): 29 | """ 30 | Get repsonse from typeform respopnses api as a query dict suitable 31 | for POST. 32 | """ 33 | server = TypeformResponses(form=self.typeform_id) 34 | result = server.query_dict(0, { 35 | 'query': typeformuid, 36 | 'page_size': 1, 37 | 'sort': 'submitted_at,desc', 38 | }, helper_form=self) 39 | return result 40 | 41 | def get_uid(self, request): 42 | """Generate unique id for each typeform and session""" 43 | hash = hashlib.md5(self.typeform_id.encode('utf-8')).hexdigest() 44 | if hash in request.session: 45 | return request.session[hash] 46 | request.session[hash] = get_random_string(31) # unique id is random 47 | return request.session[hash] 48 | 49 | def render(self, context): 50 | """ 51 | Renders the typeform. Allows to use "{% include typeform %}" in templates 52 | for typeform rendering 53 | """ 54 | request = context['request'] 55 | context.update({ 56 | 'typeformuid': self.get_uid(request), 57 | 'typeform_url': self.typeform_url, 58 | }) 59 | return render_to_string(self.typeform_template, context.flatten()) 60 | -------------------------------------------------------------------------------- /django_typeform/responses.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 2 | """ 3 | Implement the response API of typeform_id. 4 | 5 | The class TypeformResponse reads JSON objects as described on the typeform_id developer web site: 6 | https://developer.typeform.com/ 7 | """ 8 | 9 | import json 10 | from urllib.error import HTTPError 11 | from urllib.parse import urlencode 12 | from urllib.request import Request, urlopen 13 | 14 | from dateutil.parser import parse 15 | from django.conf import settings 16 | from django.http import QueryDict 17 | 18 | TYPEFORM_SERVER = getattr(settings, 'TYPEFORM_SERVER', 'https://api.typeform.com/') 19 | if TYPEFORM_SERVER[-1] != '/': # add trailing slash if missing 20 | TYPEFORM_SERVER += '/' 21 | TYPEFORM_FORM = getattr(settings, 'TYPEFORM_FORM', None) 22 | TYPEFORM_TOKEN = getattr(settings, 'TYPEFORM_TOKEN', "") 23 | TYPEFORM_CHOICES = getattr(settings, 'TYPEFORM_CHOICES', {}) 24 | 25 | 26 | class TypeformResponses(object): 27 | """ 28 | Retrieve typeform response answers and convert them to Django form compatible 29 | formats. 30 | 31 | "Decode" is a dictionary of functions to decode results returned as json objects by 32 | the typeform response api. Currently it supports choice fields and date fields. 33 | Additional fields to be added. 34 | 35 | All types not listed in decode will follow the rule lambda x: x[answer['type']], 36 | i.e. the property named after the answer type contains the result. 37 | 38 | Since Django separates representation and answers for choice fields, answers 39 | will have to converted back to representationd in _to_choice_field. 40 | """ 41 | decode = { 42 | 'choice': lambda x: x['choice']['label'] if x['choice'] else None, 43 | 'date': lambda x: parse[x['date']], 44 | } 45 | form = None 46 | 47 | def __init__(self, *args, **kwargs): 48 | self.form_id = kwargs.pop('form', TYPEFORM_FORM) 49 | super().__init__(*args, **kwargs) 50 | 51 | 52 | def get(self, parameters, form_id = None): 53 | """ 54 | Read typeform_id results from server 55 | :param form_id: Typeform form id for form to read (overwrites the form_id given on object initialization) 56 | :type parameters: dict 57 | """ 58 | if form_id is None: 59 | if self.form_id: 60 | form_id = self.form_id 61 | else: 62 | raise ValueError('No form_id specified for typeform_id response api') 63 | 64 | url = "{}forms/{}/responses".format(TYPEFORM_SERVER, form_id) 65 | if parameters: 66 | url += "?" + urlencode(parameters) 67 | 68 | request = Request(url) 69 | request.add_header('authorization', 'bearer {}'.format(TYPEFORM_TOKEN)) 70 | 71 | results = urlopen(request) 72 | if results.status == 200: # OK 73 | data = json.loads(results.read()) 74 | else: 75 | raise HTTPError('Error reading form typeform_id response api: {} {}' 76 | .format(results.status, results.reason)) 77 | 78 | return data 79 | 80 | def _to_choice_field(self, value, form_id, form_field): 81 | """ 82 | Convert choice field value to Django FormField representation in 83 | two-step process. First try form_field.choices attribute to find 84 | representation. Secondly, try TYPEFORM_CHOICES setting which contains 85 | a dictionary for choices attributes for a given typeform id. 86 | 87 | :param value: Returned value from response api 88 | :param form_id: typeform id 89 | :param form_field: ChoiceField object 90 | :return: 91 | """ 92 | if form_field: 93 | choices = getattr(form_field, 'choices', []) 94 | for choice in choices: 95 | if choice[-1] == value or choice[1] == value: 96 | return choice[0] 97 | if form_id in TYPEFORM_CHOICES: 98 | for choice in TYPEFORM_CHOICES[form_id]: 99 | if choice[-1] == value or choice[1] == value: 100 | return choice[0] 101 | return value 102 | 103 | def query_dict(self, result_id, parameters, form_id=None, helper_form=None): 104 | if form_id is None: 105 | form_id = self.form_id 106 | if isinstance(helper_form, type): # is (new style) class? 107 | helper_form = helper_form() 108 | data = self.get(parameters, form_id) 109 | if 0 <= result_id < data['total_items']: 110 | answers = data['items'][result_id] 111 | 112 | q_dict= QueryDict(mutable=True) 113 | for answer in answers.get('answers'): 114 | field = answer.get('field', {'ref': None}).get('ref', None) 115 | if field: 116 | q_dict[field] = self.decode.get(answer['type'], lambda x: x[answer['type']])(answer) 117 | if answer['type'] == 'choice': 118 | if helper_form: 119 | q_dict[field] = self._to_choice_field(q_dict[field], form_id, 120 | helper_form.fields.get(field, None)) 121 | else: 122 | q_dict[field] = self._to_choice_field(q_dict[field], form_id, None) 123 | return q_dict 124 | raise HTTPError('No typeform result supplied from results api') 125 | -------------------------------------------------------------------------------- /django_typeform/templates/django_typeform/typeform.html: -------------------------------------------------------------------------------- 1 | {% load sekizai_tags static %} 2 |
3 | 4 | {% addtoblock 'js' %}{% endaddtoblock %} 5 | {% addtoblock 'js' %}{% spaceless %} 6 | {% endspaceless %} 31 | {% endaddtoblock %} 32 | -------------------------------------------------------------------------------- /django_typeform/templates/django_typeform/typeform_embed.html: -------------------------------------------------------------------------------- 1 | {% load sekizai_tags static %} 2 |
3 | {% addtoblock 'js' %}{% endaddtoblock %} 4 | {% addtoblock 'js' %}{% spaceless %} 5 | 6 | {% endspaceless %} 14 | {% endaddtoblock %} 15 | -------------------------------------------------------------------------------- /django_typeform/templatetags/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redapesolutions/django-typeform/5a922c3a0ae60a01671cd742f5e1626787039da3/django_typeform/templatetags/__init__.py -------------------------------------------------------------------------------- /django_typeform/templatetags/django_typeform.py: -------------------------------------------------------------------------------- 1 | """Django Typeform template tags.""" 2 | import json 3 | 4 | from django import template 5 | 6 | 7 | register = template.Library() 8 | 9 | 10 | @register.inclusion_tag('django_typeform/typeform_embed.html') 11 | def typeforms_embed(url, selector, options={}, mode='widget'): 12 | """Embed a typeforms form. 13 | 14 | Parameters 15 | ---------- 16 | url : str 17 | Typeform share typeform_url. 18 | selector : str 19 | CSS selector to place typeform_id into. 20 | options : dict, str 21 | Accepts a dictionary or JSON as string. 22 | Options passed into the JS make function. 23 | see https://developer.typeform.com/embed/modes/ for values. 24 | 25 | """ 26 | if isinstance(options, str): 27 | # Loads to verify valid JSON is valid. 28 | options = json.loads(options) 29 | return { 30 | 'typeform_url': url, 31 | 'selector': selector[1:] if selector[0]=='.' else selector, 32 | 'options': json.dumps(options), 33 | 'mode': mode 34 | } 35 | -------------------------------------------------------------------------------- /django_typeform/views.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 2 | """Define TypeformView.""" 3 | 4 | from django.views import View 5 | from django.views.generic.edit import FormMixin 6 | from django.views.generic.base import TemplateResponseMixin 7 | 8 | 9 | class BaseTypeformView(FormMixin, View): 10 | """ 11 | Render a typeform_id on GET and retrieve typeform_id results 12 | and process them it on POST. 13 | """ 14 | typeform_url = None 15 | 16 | def get(self, request, *args, **kwargs): 17 | context = self.get_context_data(**kwargs) 18 | return self.render_to_response(context) 19 | 20 | def post(self, request, *args, **kwargs): 21 | """ 22 | Handle POST requests: get typeform_id results from typeform_id API, 23 | instantiate a form instance with the retrieved input and then 24 | check if it's valid. 25 | """ 26 | 27 | if 'typeformuid' in request.POST: 28 | request.POST = self.form_class().typeform_to_query_dict(request.POST.get('typeformuid')) 29 | return self.post(request, *args, **kwargs) 30 | form = self.get_form() 31 | if form.is_valid(): 32 | return self.form_valid(form) 33 | else: 34 | return self.form_invalid(form) 35 | 36 | 37 | class TypeformView(TemplateResponseMixin, BaseTypeformView): 38 | """A view for displaying a typeform_id and rendering a template response.""" 39 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/complexity.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/complexity.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/complexity" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/complexity" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../AUTHORS.rst 2 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # complexity documentation build configuration file, created by 4 | # sphinx-quickstart on Tue Jul 9 22:26:36 2013. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | cwd = os.getcwd() 22 | parent = os.path.dirname(cwd) 23 | sys.path.append(parent) 24 | 25 | import django 26 | sys.path.insert(0, os.path.abspath('..')) 27 | django.setup() 28 | import django_typeform 29 | 30 | 31 | # -- General configuration ----------------------------------------------------- 32 | 33 | # If your documentation needs a minimal Sphinx version, state it here. 34 | #needs_sphinx = '1.0' 35 | 36 | # Add any Sphinx extension module names here, as strings. They can be extensions 37 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 38 | extensions = [ 39 | 'sphinx.ext.autodoc', 40 | 'sphinx.ext.intersphinx', 41 | 'sphinx.ext.viewcode', 42 | 'sphinx.ext.napoleon', 43 | ] 44 | 45 | autodoc_default_flags = [ 46 | 'members', 47 | 'show-inheritance', 48 | ] 49 | 50 | # Add any paths that contain templates here, relative to this directory. 51 | templates_path = ['_templates'] 52 | 53 | # The suffix of source filenames. 54 | source_suffix = '.rst' 55 | 56 | # The encoding of source files. 57 | #source_encoding = 'utf-8-sig' 58 | 59 | # The master toctree document. 60 | master_doc = 'index' 61 | 62 | # General information about the project. 63 | project = u'Django Typeform' 64 | copyright = u'2017, Jafnee Jesmee' 65 | 66 | # The version info for the project you're documenting, acts as replacement for 67 | # |version| and |release|, also used in various other places throughout the 68 | # built documents. 69 | # 70 | # The short X.Y version. 71 | version = django_typeform.__version__ 72 | # The full version, including alpha/beta/rc tags. 73 | release = django_typeform.__version__ 74 | 75 | # The language for content autogenerated by Sphinx. Refer to documentation 76 | # for a list of supported languages. 77 | #language = None 78 | 79 | # There are two options for replacing |today|: either, you set today to some 80 | # non-false value, then it is used: 81 | #today = '' 82 | # Else, today_fmt is used as the format for a strftime call. 83 | #today_fmt = '%B %d, %Y' 84 | 85 | # List of patterns, relative to source directory, that match files and 86 | # directories to ignore when looking for source files. 87 | exclude_patterns = ['_build'] 88 | 89 | # The reST default role (used for this markup: `text`) to use for all documents. 90 | #default_role = None 91 | 92 | # If true, '()' will be appended to :func: etc. cross-reference text. 93 | #add_function_parentheses = True 94 | 95 | # If true, the current module name will be prepended to all description 96 | # unit titles (such as .. function::). 97 | #add_module_names = True 98 | 99 | # If true, sectionauthor and moduleauthor directives will be shown in the 100 | # output. They are ignored by default. 101 | #show_authors = False 102 | 103 | # The name of the Pygments (syntax highlighting) style to use. 104 | pygments_style = 'sphinx' 105 | 106 | # A list of ignored prefixes for module index sorting. 107 | #modindex_common_prefix = [] 108 | 109 | # If true, keep warnings as "system message" paragraphs in the built documents. 110 | #keep_warnings = False 111 | 112 | 113 | # -- Options for HTML output --------------------------------------------------- 114 | 115 | # The theme to use for HTML and HTML Help pages. See the documentation for 116 | # a list of builtin themes. 117 | html_theme = 'default' 118 | 119 | # Theme options are theme-specific and customize the look and feel of a theme 120 | # further. For a list of options available for each theme, see the 121 | # documentation. 122 | #html_theme_options = {} 123 | 124 | # Add any paths that contain custom themes here, relative to this directory. 125 | #html_theme_path = [] 126 | 127 | # The name for this set of Sphinx documents. If None, it defaults to 128 | # " v documentation". 129 | #html_title = None 130 | 131 | # A shorter title for the navigation bar. Default is the same as html_title. 132 | #html_short_title = None 133 | 134 | # The name of an image file (relative to this directory) to place at the top 135 | # of the sidebar. 136 | #html_logo = None 137 | 138 | # The name of an image file (within the static path) to use as favicon of the 139 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 140 | # pixels large. 141 | #html_favicon = None 142 | 143 | # Add any paths that contain custom static files (such as style sheets) here, 144 | # relative to this directory. They are copied after the builtin static files, 145 | # so a file named "default.css" will overwrite the builtin "default.css". 146 | html_static_path = ['_static'] 147 | 148 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 149 | # using the given strftime format. 150 | #html_last_updated_fmt = '%b %d, %Y' 151 | 152 | # If true, SmartyPants will be used to convert quotes and dashes to 153 | # typographically correct entities. 154 | #html_use_smartypants = True 155 | 156 | # Custom sidebar templates, maps document names to template names. 157 | #html_sidebars = {} 158 | 159 | # Additional templates that should be rendered to pages, maps page names to 160 | # template names. 161 | #html_additional_pages = {} 162 | 163 | # If false, no module index is generated. 164 | #html_domain_indices = True 165 | 166 | # If false, no index is generated. 167 | #html_use_index = True 168 | 169 | # If true, the index is split into individual pages for each letter. 170 | #html_split_index = False 171 | 172 | # If true, links to the reST sources are added to the pages. 173 | #html_show_sourcelink = True 174 | 175 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 176 | #html_show_sphinx = True 177 | 178 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 179 | #html_show_copyright = True 180 | 181 | # If true, an OpenSearch description file will be output, and all pages will 182 | # contain a tag referring to it. The value of this option must be the 183 | # base URL from which the finished HTML is served. 184 | #html_use_opensearch = '' 185 | 186 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 187 | #html_file_suffix = None 188 | 189 | # Output file base name for HTML help builder. 190 | htmlhelp_basename = 'django-typeformdoc' 191 | 192 | 193 | # -- Options for LaTeX output -------------------------------------------------- 194 | 195 | latex_elements = { 196 | # The paper size ('letterpaper' or 'a4paper'). 197 | #'papersize': 'letterpaper', 198 | 199 | # The font size ('10pt', '11pt' or '12pt'). 200 | #'pointsize': '10pt', 201 | 202 | # Additional stuff for the LaTeX preamble. 203 | #'preamble': '', 204 | } 205 | 206 | # Grouping the document tree into LaTeX files. List of tuples 207 | # (source start file, target name, title, author, documentclass [howto/manual]). 208 | latex_documents = [ 209 | ('index', 'django-typeform.tex', u'Django Typeform Documentation', 210 | u'Jafnee Jesmee', 'manual'), 211 | ] 212 | 213 | # The name of an image file (relative to this directory) to place at the top of 214 | # the title page. 215 | #latex_logo = None 216 | 217 | # For "manual" documents, if this is true, then toplevel headings are parts, 218 | # not chapters. 219 | #latex_use_parts = False 220 | 221 | # If true, show page references after internal links. 222 | #latex_show_pagerefs = False 223 | 224 | # If true, show URL addresses after external links. 225 | #latex_show_urls = False 226 | 227 | # Documents to append as an appendix to all manuals. 228 | #latex_appendices = [] 229 | 230 | # If false, no module index is generated. 231 | #latex_domain_indices = True 232 | 233 | 234 | # -- Options for manual page output -------------------------------------------- 235 | 236 | # One entry per manual page. List of tuples 237 | # (source start file, name, description, authors, manual section). 238 | man_pages = [ 239 | ('index', 'django-typeform', u'Django Typeform Documentation', 240 | [u'Jafnee Jesmee'], 1) 241 | ] 242 | 243 | # If true, show URL addresses after external links. 244 | #man_show_urls = False 245 | 246 | 247 | # -- Options for Texinfo output ------------------------------------------------ 248 | 249 | # Grouping the document tree into Texinfo files. List of tuples 250 | # (source start file, target name, title, author, 251 | # dir menu entry, description, category) 252 | texinfo_documents = [ 253 | ('index', 'django-typeform', u'Django Typeform Documentation', 254 | u'Jafnee Jesmee', 'django-typeform', 'One line description of project.', 255 | 'Miscellaneous'), 256 | ] 257 | 258 | # Documents to append as an appendix to all manuals. 259 | #texinfo_appendices = [] 260 | 261 | # If false, no module index is generated. 262 | #texinfo_domain_indices = True 263 | 264 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 265 | #texinfo_show_urls = 'footnote' 266 | 267 | # If true, do not generate a @detailmenu in the "Top" node's menu. 268 | #texinfo_no_detailmenu = False 269 | 270 | # Example configuration for intersphinx: refer to the Python standard library. 271 | intersphinx_mapping = { 272 | 'python': ('https://docs.python.org/3.5', 'objects.inv/python.inv'), 273 | 'django': ('https://docs.djangoproject.com/en/1.10/', 'objects.inv/django.inv'), 274 | } 275 | -------------------------------------------------------------------------------- /docs/configuration.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Configuration 3 | ============= 4 | 5 | ``django_typeform`` interacts with the Typeform Responses API. To use the 6 | API you need to get a **Personal token** from typeform. 7 | 8 | 9 | TYPEFORM_TOKEN 10 | .............. 11 | 12 | The ``TYPEFORM_TOKEN`` setting is **required**. It carries the 13 | personal token of the typeform account. Example: 14 | 15 | .. code-block:: python 16 | 17 | TYPEFORM_TOKEN = 'heregoesthereallylongtokenstringgiventoyoubytypeform' 18 | 19 | Without the token the Responses API will not work and type ``TypeformMixin`` will 20 | not be able to retrieve responses. The template tags are unaffected. 21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst 2 | -------------------------------------------------------------------------------- /docs/django_typeform.rst: -------------------------------------------------------------------------------- 1 | django\_typeform package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | django\_typeform\.apps module 8 | ----------------------------- 9 | 10 | .. automodule:: django_typeform.apps 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | 16 | Module contents 17 | --------------- 18 | 19 | .. automodule:: django_typeform 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | -------------------------------------------------------------------------------- /docs/django_typeform.templatetags.rst: -------------------------------------------------------------------------------- 1 | django\_typeform\.templatetags package 2 | ====================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | django\_typeform\.templatetags\.django\_typeform module 8 | ------------------------------------------------------- 9 | 10 | .. automodule:: django_typeform.templatetags.django_typeform 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | 16 | Template tags 17 | ------------- 18 | 19 | .. automodule:: django_typeform.templatetags 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | 24 | TypeformMixin 25 | ------------- 26 | 27 | .. automodule:: django_typeform.forms 28 | :members: 29 | :undoc-members: 30 | :show-inheritance: 31 | 32 | TypeformView 33 | ------------ 34 | 35 | .. automodule:: django_typeform.views 36 | :members: 37 | :undoc-members: 38 | :show-inheritance: 39 | 40 | -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../HISTORY.rst 2 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. complexity documentation master file, created by 2 | sphinx-quickstart on Tue Jul 9 22:26:36 2013. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Django Typeform's documentation! 7 | ================================================================= 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | readme 15 | installation 16 | configuration 17 | usage 18 | typeformmixin 19 | typeformview 20 | contributing 21 | authors 22 | history 23 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Installation 3 | ============ 4 | 5 | At the command line:: 6 | 7 | $ easy_install django-typeform 8 | 9 | Or, if you have virtualenvwrapper installed:: 10 | 11 | $ mkvirtualenv django-typeform 12 | $ pip install django-typeform 13 | 14 | ``django_typeform`` requires ``django-sekizai`` to be installed (should happen automatically in the 15 | above instructions). Sekizai is used to position javascript elements at the ebnd of the HTML body. 16 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\complexity.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\complexity.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /docs/modules.rst: -------------------------------------------------------------------------------- 1 | django_typeform 2 | =============== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | django_typeform 8 | -------------------------------------------------------------------------------- /docs/objects.inv/django.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redapesolutions/django-typeform/5a922c3a0ae60a01671cd742f5e1626787039da3/docs/objects.inv/django.inv -------------------------------------------------------------------------------- /docs/objects.inv/python.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redapesolutions/django-typeform/5a922c3a0ae60a01671cd742f5e1626787039da3/docs/objects.inv/python.inv -------------------------------------------------------------------------------- /docs/readme.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | -------------------------------------------------------------------------------- /docs/typeformmixin.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | TypeformMixin 3 | ============= 4 | 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``: 10 | 11 | .. code-block:: python 12 | 13 | from django_typeforms.forms import TypeformMixin 14 | 15 | from forms import MyForm 16 | 17 | class MyTypeForm(TypeformMixin, MyForm) 18 | typeform_url = 'https://xxxx.typeform.com/to/xxxxxx' 19 | 20 | ``MyTypeForm`` will be a fully fledged Django form and at the same 21 | time be linked to the Typeform with given url. 22 | 23 | For this link to work, the ``Question reference`` for each Typeform 24 | question must be set to the matching Django field name, e.g. ``first_name`` for a 25 | field ``first_name = forms.CharField(max_length=40, blank=True)``. **This requires editiing 26 | all questions of a typeform and as Typeform warns might break 27 | other integrations.** 28 | 29 | Additionally, the typeform needs a **hidden field** "typeformuid" which 30 | the ``TypeformMixin`` uses to identify the relevant answer sent to the 31 | Typeform servers. Hidden fields currently are only available to 32 | users of the Typeform PRO and PRO+ plans. 33 | 34 | Rendering a typeform 35 | -------------------- 36 | 37 | Once, a form is turned into a typeform using the mixin, it still can 38 | used and rendered as a Django form using, e.g., ``{{ form }}`` or any 39 | other of your preferred rendering methods. 40 | 41 | Additionally, it can be rendered as a typeform using include: 42 | 43 | .. code-block:: html 44 | 45 |
46 | {% include form with mode='popup' %} 47 |
48 | 49 | This will render a hidden input field with a unique id passed to the 50 | typeform's hidden ``typeformuid`` field. Upon completion of 51 | the typeform the above HTML form is posted to the server and 52 | the server can retrieve the answers given by querying the response 53 | with the unique id. 54 | 55 | Additional context can be given to the typeform using the ``with`` clause. 56 | 57 | Currently, valid context parameters are: 58 | 59 | mode 60 | .... 61 | ``mode`` (default: None) describes the emed mede to be used: ``None`` or ``widget`` 62 | for a widget. In widget mode the additional parameter ``height`` is 63 | needed for proper display. Example: 64 | 65 | .. code-block:: html 66 | 67 |
68 | {% include form with mode='widget' height='100vh' %} 69 |
70 | 71 | Other values of ``mode`` can be ``popup``, ``drawer_left``, or 72 | ``drawer_right`` which are the three modes for typeform popup modes. 73 | 74 | 75 | Form validation 76 | --------------- 77 | 78 | Both Django and Typeform provide form validation. This is prone for conflicts 79 | since both validations need not agree. When turning a Django form into a typeform 80 | we recommend to leave out any validation on the Django side, since for now 81 | there is no way of returning validation errors to typeform. 82 | -------------------------------------------------------------------------------- /docs/typeformview.rst: -------------------------------------------------------------------------------- 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 |
43 | {% include form with height='100vh' %} 44 |
45 | {% endblock %} 46 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | ===== 2 | Usage 3 | ===== 4 | 5 | To use Django Typeform in a project, add it to your `INSTALLED_APPS`: 6 | 7 | .. code-block:: python 8 | 9 | INSTALLED_APPS = ( 10 | ... 11 | 'django_typeform.apps.DjangoTypeformConfig', 12 | ... 13 | ) 14 | 15 | Make sure your TEMPLATE OPTIONS' context_processors include 16 | 17 | .. code-block:: python 18 | 19 | TEMPLATES = [ 20 | { 21 | ... 22 | 'OPTIONS': { 23 | 'context_processors': [ 24 | ... 25 | 'django.template.context_processors.request', 26 | ... 27 | ] 28 | } 29 | }, 30 | ] 31 | 32 | The ``typeform_embed`` template tag includes a ``
`` at its position. It carries 33 | a class 34 | 35 | 36 | Example: 37 | 38 | .. code-block:: html 39 | 40 | {% load django_typeform %} 41 | 42 | 43 | {% typeforms_embed 'https://xxxx.typeform.com/to/xxxxxx' '.my-typeform' '{"hideHeaders": true, "hideFooter": true}' %} 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from __future__ import unicode_literals, absolute_import 4 | 5 | import os 6 | import sys 7 | 8 | if __name__ == "__main__": 9 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") 10 | from django.core.management import execute_from_command_line 11 | 12 | execute_from_command_line(sys.argv) 13 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | django-sekizai 2 | python-dateutil 3 | 4 | # Additional requirements go here 5 | 6 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | -r requirements.txt 2 | 3 | bumpversion==0.5.3 4 | wheel==0.30.0 5 | 6 | -------------------------------------------------------------------------------- /requirements_test.txt: -------------------------------------------------------------------------------- 1 | -r requirements.txt 2 | 3 | coverage==4.4.1 4 | mock>=1.0.1 5 | flake8>=2.1.0 6 | tox>=1.7.0 7 | codecov>=2.0.0 8 | 9 | 10 | # Additional test requirements go here 11 | -------------------------------------------------------------------------------- /runtests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 3 | from __future__ import unicode_literals, absolute_import 4 | 5 | import os 6 | import sys 7 | 8 | import django 9 | from django.conf import settings 10 | from django.test.utils import get_runner 11 | 12 | 13 | def run_tests(*test_args): 14 | if not test_args: 15 | test_args = ['tests'] 16 | 17 | os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' 18 | django.setup() 19 | TestRunner = get_runner(settings) 20 | test_runner = TestRunner() 21 | failures = test_runner.run_tests(test_args) 22 | sys.exit(bool(failures)) 23 | 24 | 25 | if __name__ == '__main__': 26 | run_tests(*sys.argv[1:]) 27 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 0.2.0 3 | commit = False 4 | tag = False 5 | 6 | [bumpversion:file:django_typeform/__init__.py] 7 | 8 | [wheel] 9 | universal = 1 10 | 11 | [flake8] 12 | ignore = D203 13 | exclude = 14 | django_typeform/migrations, 15 | .git, 16 | .tox, 17 | docs/conf.py, 18 | build, 19 | dist 20 | max-line-length = 119 21 | 22 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import os 4 | import re 5 | import sys 6 | 7 | try: 8 | from setuptools import setup 9 | except ImportError: 10 | from distutils.core import setup 11 | 12 | 13 | def get_version(*file_paths): 14 | """Retrieves the version from django_typeform/__init__.py""" 15 | filename = os.path.join(os.path.dirname(__file__), *file_paths) 16 | version_file = open(filename).read() 17 | version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", 18 | version_file, re.M) 19 | if version_match: 20 | return version_match.group(1) 21 | raise RuntimeError('Unable to find version string.') 22 | 23 | 24 | version = get_version("django_typeform", "__init__.py") 25 | 26 | 27 | if sys.argv[-1] == 'publish': 28 | try: 29 | import wheel 30 | print("Wheel version: ", wheel.__version__) 31 | except ImportError: 32 | print('Wheel library missing. Please run "pip install wheel"') 33 | sys.exit() 34 | os.system('python setup.py sdist upload') 35 | os.system('python setup.py bdist_wheel upload') 36 | sys.exit() 37 | 38 | if sys.argv[-1] == 'tag': 39 | print("Tagging the version on git:") 40 | os.system("git tag -a %s -m 'version %s'" % (version, version)) 41 | os.system("git push --tags") 42 | sys.exit() 43 | 44 | readme = open('README.rst').read() 45 | history = open('HISTORY.rst').read().replace('.. :changelog:', '') 46 | 47 | setup( 48 | name='django-typeform', 49 | version=version, 50 | description="""A Typeform integration for Django""", 51 | long_description=readme + '\n\n' + history, 52 | author='Jafnee Jesmee', 53 | author_email='jafnee@redapesolutions.com', 54 | url='https://github.com/redapesolutions/django-typeform', 55 | packages=[ 56 | 'django_typeform', 57 | ], 58 | include_package_data=True, 59 | install_requires=[], 60 | license="MIT", 61 | zip_safe=False, 62 | keywords='django-typeform', 63 | classifiers=[ 64 | 'Development Status :: 3 - Alpha', 65 | 'Framework :: Django', 66 | 'Framework :: Django :: 1.11', 67 | 'Framework :: Django :: 2.0', 68 | 'Framework :: Django :: 2.1', 69 | 'Framework :: Django :: 2.2', 70 | 'Intended Audience :: Developers', 71 | 'License :: OSI Approved :: MIT License', 72 | 'Natural Language :: English', 73 | 'Programming Language :: Python :: 3', 74 | 'Programming Language :: Python :: 3.5', 75 | 'Programming Language :: Python :: 3.6', 76 | 'Programming Language :: Python :: 3.7', 77 | ], 78 | ) 79 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redapesolutions/django-typeform/5a922c3a0ae60a01671cd742f5e1626787039da3/tests/__init__.py -------------------------------------------------------------------------------- /tests/settings.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 2 | from __future__ import unicode_literals, absolute_import 3 | 4 | import os 5 | 6 | import django 7 | 8 | BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 9 | 10 | DEBUG = True 11 | USE_TZ = True 12 | 13 | # SECURITY WARNING: keep the secret key used in production secret! 14 | SECRET_KEY = "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" 15 | 16 | DATABASES = { 17 | "default": { 18 | "ENGINE": "django.db.backends.sqlite3", 19 | "NAME": ":memory:", 20 | } 21 | } 22 | 23 | ROOT_URLCONF = "tests.urls" 24 | 25 | INSTALLED_APPS = [ 26 | "django.contrib.auth", 27 | "django.contrib.contenttypes", 28 | "django.contrib.sites", 29 | 'django.contrib.sessions', 30 | "django_typeform", 31 | "sekizai", 32 | ] 33 | 34 | TEMPLATES = [ 35 | { 36 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 37 | 'DIRS': [os.path.join(BASE_DIR, "tests/templates")], 38 | 'APP_DIRS': True, 39 | 'OPTIONS': { 40 | 'context_processors': [ 41 | 'django.template.context_processors.request', 42 | ] 43 | } 44 | }, 45 | ] 46 | 47 | 48 | SITE_ID = 1 49 | 50 | MIDDLEWARE = ( 51 | 'django.contrib.sessions.middleware.SessionMiddleware', 52 | ) 53 | -------------------------------------------------------------------------------- /tests/templates/typeform_test.html: -------------------------------------------------------------------------------- 1 |
2 | {% include form with height='100vh' %} 3 |
4 | -------------------------------------------------------------------------------- /tests/test_forms.py: -------------------------------------------------------------------------------- 1 | from django.forms import Form 2 | from django.http import QueryDict 3 | from django.template import Context 4 | from django.test import SimpleTestCase 5 | 6 | from django_typeform.forms import TypeformMixin 7 | 8 | 9 | class MyForm(TypeformMixin, Form): 10 | typeform_url='https://whatever.typeform.com/to/xxxxxx' 11 | 12 | def typeform_to_query_dict(self, typeformuid): 13 | return QueryDict() # Set actual response query to nop 14 | 15 | class TypeformMixinTest(SimpleTestCase): 16 | def test_mixin(self): 17 | form = MyForm() 18 | self.assertEqual(form.typeform_id, 'xxxxxx') 19 | 20 | def test_mixin_rendering(self): 21 | class Request(object): 22 | session = {} 23 | 24 | request = Request() 25 | form = MyForm(typeform_url='https://whatever.typeform.com/to/xxxxxx') 26 | 27 | form.get_uid(Request()) 28 | self.assertFalse(not request.session, 'typeformuid not stored in session') 29 | form.render(Context({'request': Request()})) 30 | -------------------------------------------------------------------------------- /tests/test_views.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | from django.test import Client 3 | 4 | class TypeformViewTest(TestCase): 5 | def test_view(self): 6 | c = Client() 7 | response = c.get('/testform/') 8 | self.assertEqual(response.status_code, 200) 9 | response = c.post('/testform/', {'typeformuid': 'test'}) 10 | self.assertEqual(response.status_code, 302) # should be a redirect response 11 | -------------------------------------------------------------------------------- /tests/urls.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals, absolute_import 3 | 4 | from django.conf.urls import include, url 5 | from django_typeform.views import TypeformView 6 | from tests.test_forms import MyForm 7 | 8 | 9 | urlpatterns = [ 10 | url(r'^testform/', TypeformView.as_view( 11 | template_name='typeform_test.html', 12 | form_class=MyForm, 13 | success_url='/yeah/', 14 | )) 15 | ] 16 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = 3 | py3-django-111 4 | py3-django-20 5 | py3-django-21 6 | py3-django-22 7 | 8 | [testenv] 9 | setenv = 10 | PYTHONPATH = {toxinidir}:{toxinidir}/django_typeform 11 | commands = coverage run --source django_typeform runtests.py 12 | deps = 13 | django-111: Django>=1.11,<2.0 14 | django-20: Django>=2.0,<2.1 15 | django-21: Django>=2.1,<2.2 16 | django-22: Django>=2.2,<2.3 17 | -r{toxinidir}/requirements_test.txt 18 | basepython = 19 | py3: python3 20 | 21 | --------------------------------------------------------------------------------