Giter Club home page Giter Club logo

django-questionnaire-core's Introduction

django-questionnaire-core

A django application which can be used as a base / starting point for questionnaire functionality in your project. It heavily relies on django form fields & widgets and uses PostgreSQL JSON fields to store the results.

Requirements

Quick start

  1. Add "questionnaire_core" and its dependency to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'ordered_model',
        'questionnaire_core',
    ]
    
  2. Create a view based on questionnaire_core.views.generic.QuestionnaireFormView; a simple version might look like this:

    class BasicQuestionnaireView(QuestionnaireFormView):
        template_name = 'basic_questionnaire.html'
    
        def get_questionnaire(self):
            return Questionnaire.objects.get(pk=self.kwargs.get('pk'))
    
        def get_questionnaire_result_set(self):
            if self.request.GET.get('result_set'):
                return QuestionnaireResult.objects.get(pk=self.request.GET.get('result_set'))
            return QuestionnaireResult(questionnaire=self.get_questionnaire())
    
        def get_success_url(self):
            return reverse('basic_questionnaire', args=(self.kwargs.get('pk'),))
    
        def form_valid(self, form):
            # Add current result set to the url (allows editing of the result)
            redirect = super(BasicQuestionnaireView, self).form_valid(form)
            url_params = urlencode({'result_set': form.current_result_set.pk})
            return HttpResponseRedirect('{url}?{params}'.format(url=redirect.url, params=url_params))
  3. Add the new view to your URLconf:

    url(r'^questionnaire/(?P<pk>[0-9]+)/$', BasicQuestionnaireView.as_view(), name='basic_questionnaire'),
    
  4. Run python manage.py migrate to create the questionnaire_core models.

  5. Start the development server and visit http://127.0.0.1:8000/admin/ to create a questionnaire (you'll need the Admin app enabled).

  6. Visit http://127.0.0.1:8000/questionnaire/1/ to test your first questionnaire.

Development setup

  1. Upgrade packaging tools:

    pip install --upgrade pip setuptools wheel
  2. Install Django (the example_app expects django 1.11):

    pip install Django~=1.11.0 django-ordered-model~=2.1.0 psycopg2
  3. Install tox, isort & flake8

    pip install tox isort flake8

django-questionnaire-core's People

Contributors

ferdinand-hoffmann avatar

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.