Git Product home page Git Product logo

mariusraileanu / django-survey Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pierre-sassoulas/django-survey

0.0 1.0 0.0 1.33 MB

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"

License: GNU Affero General Public License v3.0

Shell 0.04% Python 89.81% HTML 2.49% TeX 7.65%

django-survey's Introduction

Django survey

This is a django survey app, its based on and compatible with "django-survey". This means you will be able to migrate from an ancient version of django-survey. As the old 'django-survey' seem to be inactive and do not accept pull-request, this is available on PyPi as "django-survey-and-report".

Compared to django-survey, it has been refactored, ported to python 3, and test has been added as well as exports as csv and pdf for the survey's results.

Build Status Coverage Status PyPI version

Getting started

In order to get started, install the requirements, create the database, create a superuser, launch the server, then create your survey in the django admin :

  pip install -r requirements.txt
  python manage.py migrate
  python manage.py createsuperuser
  python manage.py runserver
  # Create survey in interface

You will have to change the settings in order to suit your need.

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

Creating 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

Handling the results

Submitted responses can be viewed via the admin backend, in an exported csv or in a pdf generated with latex. The way the pdf is generated is configurable 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.

The generated pdf for the polar and pin options

The generated pdf for the cloud and inside options

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:

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.:
    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:

The generated pdf for the multiple charts example

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:

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 manage.py generatetexconf -h, it will create the default skeleton for every survey and question.

Getting started as a contributor

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

Internationalisation :

  python manage.py makemessages --no-obsolete --no-wrap
  python manage.py runserver
  # Access http://localhost:8000/rosetta

Lint :

  pylint survey

Build the package :

    python setup.py build

Credits

Some inspiration came from an older django-survey app, but this app uses a different model architecture and different mechanism for dynamic form generation.

For the sankey's diagram we used pysankey.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.