Skip to content
A django survey app, based on and compatible with 'django-survey' (ie: you can migrate your old django-survey app and its data), but ported to python 3 and allowing export and report as CSV or PDF. Available on PyPi as "django-survey-and-report"
Python TeX HTML
Branch: master
Clone or download
Pull request Compare This branch is 307 commits ahead of ijasperyang:master.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create FUNDING.yml Aug 20, 2019
csv add redirect and test for message Jul 16, 2019
dev/templates add redirect and test for message Jul 16, 2019
doc Style - Apply black and format yaml example file Mar 2, 2019
example_project Style - Apply black, isort, fix trailing whitespace, etc Dec 12, 2018
survey Update survey/tests/testdump.json Oct 3, 2019
tex Style - Apply black, isort, fix trailing whitespace, etc Dec 12, 2018
.flake8 Chore - Add pre-commit and document dumpdata Dec 11, 2018
.gitattributes Style - Apply black, isort, fix trailing whitespace, etc Dec 12, 2018
.gitignore add redirect and test for message Jul 16, 2019
.isort.cfg Refactor - pysankey beta is now a third party lib Dec 13, 2018
.pre-commit-config.yaml Style - Remove some pylint warning Mar 2, 2019
.pylintrc Style - Remove some pylint warning Mar 2, 2019
.travis.yml Test - Add Travis test for python 3.7 Jun 19, 2019
LICENSE.txt Feat - Register and upload on Pypi as django-survey-and-report Oct 10, 2017 Fix - Add readme and requirements in Sep 22, 2018 Style - Apply black, isort, fix trailing whitespace, etc Dec 12, 2018 Sets relative urls Sep 20, 2019 Question.choices could use separator from setttings.CHOICES_SEPARATOR ( May 25, 2019
setup.cfg Chore - Prepating for pypi release Jul 20, 2017 [] Increase version number to 1.3.12 Oct 13, 2019 Style - Apply black, isort, fix trailing whitespace, etc Dec 12, 2018 Chore - Reorganisation of architecture for clarity Mar 28, 2017

Django survey

A django survey app, based on and compatible with "django-survey". You will be able to migrate your data from an ancient version of django-survey, but it has been ported to python 3 and you can export results as CSV or PDF using your native language.

If you want the latest version still compatible with python 2.7 you need a version < 1.3.0.

Build Status Coverage Status PyPI version Code style: black PRs Welcome

Table of contents

Getting started

Add django-survey-and-report to your requirements and get it with pip.

echo 'django-survey-and-report' > requirements.txt
pip install -r requirements.txt

Add bootstrapform and survey in the INSTALLED_APPS in your settings :

	# Your own installed apps here


Add an URL entry to your project’s, for example:

from django.conf import settings
from django.conf.urls import include, url

urlpatterns = [
    # Your own url pattern here

if 'survey' in settings.INSTALLED_APPS:
    urlpatterns += [
        url(r'^survey/', include('survey.urls'))

Note: you can use whatever you wish as the URL prefix.

To uninstall django-survey-and-report, simply comment out or remove the 'survey' line in your INSTALLED_APPS.

If you want to use the pdf rendering with the Sankey's diagram generation you will have to install python-tk (for python 2.7) or python3-tk (for python 3.x).

Making a survey

Using the admin interface you can create surveys, add questions, give questions categories, and mark them as required or not. You can define choices for answers using comma separated words.

Creating of a question

The front-end survey view then automatically populates based on the questions that have been defined and published in the admin interface. We use bootstrap3 to render them.

Answering a survey

Submitted responses can be viewed via the admin backend, in an exported csv or in a pdf generated with latex.

Generating a pdf report from the survey's result

You can manage the way the report is created in a yaml file, globally, survey by survey, or question by question. In order to render pdf you will need to install texlive and python-tk or python3-tk for sankey's diagram.

The results are generated for the server only when needed, but you can force it as a developper with:

python exportresult -h

Following is an example of a configuration file. you can generate one with:

python generatetexconf -h

Basic example

  document_option: 11pt
'Test survëy':
  document_class: report
    'Lorem ipsum dolor sit amët, <strong> consectetur </strong> adipiscing elit.':
        type: polar
        text: pin
    'Dolor sit amët, consectetur<strong>  adipiscing</strong>  elit.':
        type: cloud
        text: inside

The pdf is then generated using the very good pgf-pie library.

The generated pdf for the polar and pin options

The generated pdf for the cloud and inside options

Sankey diagram

If you installed python3-tk, you can also show the relation between two questions using a sankey diagram :

'Lorem ipsum dolor sit amët, <strong> consectetur </strong> adipiscing elit.':
    type: sankey
    question: 'Dolor sit amët, consectetur<strong>  adipiscing</strong>  elit.'

You get this as a result:

The generated pdf for the sankey example

Advanced example

You can also limit the answers shown by cardinality, filter them, group them together and choose the color for each answer or group of answers.

If you use this configuration for the previous question:

'Test survëy':
  'Dolor sit amët, consectetur<strong>  adipiscing</strong>  elit.':
      'Sub Sub Section with radius=3':
          Yës: blue!50
          No: red!50
          Whatever: red!50!blue!50
        radius: 3
      'Sub Sub Section with text=pin':
            - No
            - Whatever
            - Yës
          Nah: blue!33!red!66
          K.: blue!50
        text: pin
      radius: 1
      type: cloud
      text: inside

You get this as a result:

The generated pdf for the multiple charts example

Implementing a custom treatment

If you want to make your own treatment you can use your own class, for example.


'Test survëy':
    'Ipsum dolor sit amët, <strong> consectetur </strong>  adipiscing elit.':
        type: survey.tests.exporter.tex.CustomQuestion2TexChild

Code in survey.tests.exporter.tex.CustomQuestion2TexChild:

from survey.exporter.tex.question2tex_chart import Question2TexChart

class CustomQuestion2TexChild(Question2TexChart):

    def get_results(self):
        self.type = "polar"
        return """        2/There were no answer at all,
        3/But we have a custom treatment to show some,
        2/You can make minor changes too !"""


The generated pdf for the custom example

For a full example of a configuration file look at example_conf.yaml in doc, you can also generate your configuration file with python generatetexconf -h, it will create the default skeleton for every survey and question.

Contributing as a developper

Development environment

This is the typical command you should do to get started:

python -m venv venv/ # Create virtualenv
source venv/bin/activate # Activate virtualenv
pip install -e ".[dev]" # Install dev requirements
pre-commit install # Install pre-commit hook framework
python migrate # Create database
python loaddata survey/tests/testdump.json # Load test data
python createsuperuser
python runserver # Launch server

Committing code

Launching tests

python test survey

Adding test data

If you want to dump a test database after adding data to it, this is the command to have a minimal diff :

python dumpdata --format json -e contenttypes -e admin -e auth.Permission
-e sessions.session -e --natural-foreign --indent 1
-o survey/tests/testdump.json

Launching coverage

coverage run --source=survey --omit=survey/migrations/* ./ test
coverage html
xdg-open htmlcov/index.html

Applying Lint

We're using pre-commit, it should take care of linting during commit.

Translating the project

Django survey's is available in multiple language. Your contribution would be very appreciated if you know a language that is not yet available.

Language available

The software is developed in english. Other available languages are :

As a developper

If your language do not exists add it in the LANGUAGE variable in the settings, like here. Do not forget to credit yourself like in the header seen here

Then you can translate with :

python makemessages
# python createsuperuser ? (You need to login for rosetta)
python runserver
# Access http://localhost:8000/admin to login
# Then go to http://localhost:8000/rosetta to translate
python makemessages --no-obsolete --no-wrap
git add survey/locale/

If your language is not yet available in rosetta, this stack overflow question should work even for language not handled by django.

As a translator

If you're not a developper, open an issue on github and ask for a .po file in your language. I will generate it for you, so you can edit it with an online editor. I will then create the .po and commit them, so you can edit them with your github account or integrate it myself if you do not have one. You will be credited here.


Based on jessykate's django-survey, and contribution by jibaku, joshualoving, and ijasperyang in forks of jessykate's project.

We use anazalea's pySankey for sankey's diagram during reporting.

You can’t perform that action at this time.