A django survey app, based on and compatible with
Project description
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 you can use python 3 and export results as CSV or PDF using your native language.
Summary
Generating a pdf report from the survey's result
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 :
INSTALLED_APPS = [
...
'bootstrapform',
'survey'
]
Add an URL entry to your project’s urls.py, for example:
from django.conf import settings
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.
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.
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 manage.py exportresult -h
Following is an example of a configuration file. you can generate one with:
python manage.py generatetexconf -h
Basic example
generic:
document_option: 11pt
Test survëy:
document_class: report
questions:
Lorem ipsum dolor sit amët, <strong> consectetur </strong> adipiscing elit.:
chart:
type: polar
text: pin
Dolor sit amët, consectetur<strong> adipiscing</strong> elit.:
chart:
type: cloud
text: inside
The pdf is then generated using the very good pgf-pie library.
Sankey diagram
If you installed python-tk (for python 2.7) or python3-tk (for python 3.x), you can also show the relation between two questions using a sankey diagram :
Lorem ipsum dolor sit amët, <strong> consectetur </strong> adipiscing elit.:
chart:
type: sankey
question: Dolor sit amët, consectetur<strong> adipiscing</strong> elit.
You get this as a result:
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.:
multiple_charts:
Sub Sub Section with radius=3 :
color: {"Yës": "blue!50", "No": "red!50",
"Whatever": "red!50!blue!50"}
radius: 3
Sub Sub Section with text=pin :
group_together: {"Nah": ["No", "Whatever"], "K.": ["Yës"]}
color: {"Nah": "blue!33!red!66", "K.": "blue!50"}
text: pin
chart:
radius: 1
type: cloud
text: inside
You get this as a result:
Implementing a custom treatment
If you want to make your own treatment you can use your own class, for example.
Configuration:
Test survëy:
questions:
Ipsum dolor sit amët, <strong> consectetur </strong> adipiscing elit.:
chart:
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 !"""
Result:
For a full example of a configuration file look at example_conf.yaml
in doc,
you can also generate your configuration file with
python manage.py generatetexconf -h
, it will create the default skeleton
for every survey and question.
Contributing as a developper
Development environement
You may want to use a virtualenv for python 2.7 or 3+ :
python3.5 -m venv .3env/
# Resp. for python 2.7 : virtualenv .env
source .3env/bin/activate
# Resp. for python 2.7 : source .env/bin/activate
In order to get started, install the dev requirements, create the database, create a superuser, load the test dump, then launch the server :
pip install -r requirements_dev.txt
python manage.py migrate
python manage.py createsuperuser
python manage.py loaddata survey/tests/testdump.json
python manage.py runserver
Test
python manage.py test survey
Coverage
coverage.sh
xdg-open htmlcov/index.html
Sorting imports
isort -rc survey
Lint :
pylint survey
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
- French thanks to Pierre Sassoulas (@Pierre-Sassoulas)
- English
- Japanese thanks to Nobukuni Suzue (@nsuzue)
As a developper
If your language already exists and you're a developper :
python manage.py makemessages --no-obsolete --no-wrap
python manage.py runserver
# Access http://localhost:8000/rosetta
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 integrate it to the project and credit you here.
Credits
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-survey-and-report-1.2.3.tar.gz
.
File metadata
- Download URL: django-survey-and-report-1.2.3.tar.gz
- Upload date:
- Size: 292.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96acbf10a95a01d9c17e89e319c6120718711a409b2fbe0ac4968e11fa8c2447 |
|
MD5 | 9ac6bd4a25a05ad80dbfb48e679823f1 |
|
BLAKE2b-256 | 3d168878fb6b18bcd3a4dc4e8b167a89c82d4c216fc781071319bcef1dcc758f |