All Projects → bulkan → Django Domande

bulkan / Django Domande

[UNMAINTAINED] A plugable Django app to represent generic questions on forms.

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Django Domande

Django Controlcenter
Set of widgets to build dashboards for Django projects
Stars: ✭ 866 (+5673.33%)
Mutual labels:  django
Djangoffice
Project management/CRM for small offices - Clients, Jobs, Tasks, Rates, Activities, Timesheets, Contacts, Invoices etc. etc.
Stars: ✭ 13 (-13.33%)
Mutual labels:  django
Bootcamp Kodluyoruz Org
Kodluyoruz.org icin Gelistirilen BootCamp Altyapisi
Stars: ✭ 15 (+0%)
Mutual labels:  django
Django Oml
Object Moderation Layer
Stars: ✭ 12 (-20%)
Mutual labels:  django
Pytest Django
A Django plugin for pytest.
Stars: ✭ 872 (+5713.33%)
Mutual labels:  django
Channelslightscontrol
Demo app with Django Channels to control Lights over websockets. Made for PyStPete meetup(https://www.meetup.com/Saint-Petersburg-Python-Meetup/).
Stars: ✭ 14 (-6.67%)
Mutual labels:  django
Django Ecommerce
An e-commerce website built with Django
Stars: ✭ 861 (+5640%)
Mutual labels:  django
Timed Backend
Django API for the Timed application
Stars: ✭ 15 (+0%)
Mutual labels:  django
Django Suit Daterange Filter
Filter for django-admin allowing lookups by date range
Stars: ✭ 13 (-13.33%)
Mutual labels:  django
Georide Position
get the last day deplacement of the georide tracker
Stars: ✭ 15 (+0%)
Mutual labels:  django
Requery
Store e run queries on database to help system manager of a Django website
Stars: ✭ 12 (-20%)
Mutual labels:  django
Crawl
selenium异步爬取网页图片
Stars: ✭ 13 (-13.33%)
Mutual labels:  django
Contributr
An online tool for programmers to find projects they can contribute to and project maintainers to find contributors.
Stars: ✭ 14 (-6.67%)
Mutual labels:  django
Alexa Browser Client
Alexa client in your browser. Django app.
Stars: ✭ 12 (-20%)
Mutual labels:  django
Jong
🐍 💡 JOplin Notes Generator - project replaced by https://github.com/foxmask/yeoboseyo
Stars: ✭ 15 (+0%)
Mutual labels:  django
Django Blogging System
This is blog system created using Django 1.11.4 and Python3
Stars: ✭ 11 (-26.67%)
Mutual labels:  django
Docker Taiga
Docker container for Taiga https://taiga.io
Stars: ✭ 14 (-6.67%)
Mutual labels:  django
Django Celery Beat
Celery Periodic Tasks backed by the Django ORM
Stars: ✭ 884 (+5793.33%)
Mutual labels:  django
Drf Tus
A Tus (tus.io) library for Django Rest Framework
Stars: ✭ 15 (+0%)
Mutual labels:  django
Django Bootstrap4
Bootstrap 4 integration with Django.
Stars: ✭ 877 (+5746.67%)
Mutual labels:  django

domande

Logo by @aurorachiarello

Build Status PyPi downloads

A plugable Django app to represent a generic questions on forms.

Dependencies

Here are the list of dependencies;

Installation

For stable PyPI version

pip install django-domande

To get development version

pip install git+git://github.com/bulkan/django-domande.git

In your settings.py file change INSTALLED_APPS and add;

INSTALLED_APPS = [
   ...
   'crispy-forms'   # need to add this for it's template tags to load
   'polymorphic',   # provides admin templates
   'domande'
   ...
]

Note I'm assuming you have South already installed if not add south to INSTALLED_APPS

General

domande uses model inheritence to simplify relationships to a list of questions and it does this with the help of django-polymorphic. At the moment domande supports two types of questions that are rendered differently by their accompanying forms.

A TextQuestion were the answer is a text and a ChoiceQuestion were the answer is chosen by a set of Choices. TextQuestion and ChoiceQuestion are subclasses of Question.

Example Usage

Models

Create a model with a ManyToManyField to domande.models.Question. For example a Questionnaire;

from django.db import models
from django.contrib.contenttypes import generic

from domande.models import Question, Answer

class Questionnaire(models.Model):
    name = models.CharField(max_length=256)

    questions = models.ManyToManyField(Question)

Once you add a ManyToManyField to domande.models.Question and register your model with the django admin interface the questions field will be handled uniquely. As domande.models.Questions is the parent model when you create a new one the admin inteface will display an additional step of choosing the child model to create an instance of.

View

Now you need to render the list of Questions in a view;

def questionnaire_view(request):

    # for sake of example use .get
    questionnaire = Questionnaire.objects.get(id=1)

    forms = [q.get_form()(prefix=str(q.id),
                content_object=request.user,
                question=q, form_tag=False)
                   for q in questionnaire.questions.all().get_real_instances()
               ]

    # form is a list of TextQuestionForm or ChoiceQuestionForm

domande's forms accept a content_object that is used when it creates and saves an Answer. domande doesn't know in advance what type of user or entry model you have so it uses django's builtin ContentType framework to solve this.

In the above example it uses request.user.

Template

in the template render the forms like so;

{% load crispy_forms_tags %}

<form method="post">
    {% for form in forms %}
        {% crispy form %}
    {% endfor %}
</form>

to process the validity of the forms and save the Answers;

def save_view(request, questionnaire):
    # for sake of example use .get
    questionnaire = Questionnaire.objects.get(id=questionnaire)

    forms = [q.get_form()(request.POST or None,
                prefix=str(q.id),
                content_object=request.user,
                question=q, form_tag=False)
                    for q in questionnaire.questions.all().get_real_instances()
            ]

    forms_are_valid = []

    for form in forms:
        forms_are_valid.append(valid)
        valid = form.is_valid()
        if valid:
            t = form.save()

    forms_are_valid = all(forms_are_valid)

Each question model in domande has an Answer model that relates to it. A ChoiceQuestion will use a ChoiceAnswer and a TextQuestion will use a ChoiceAnswer.

Development

  • Fork this repo, create a virtualenv and clone your fork. Then install the requirements

    pip install -r requirements.txt

  • If you have changed the models then create a migration;

    django-admin.py schemamigration --settings=domande.settings --pythonpath=$PWD

  • Please make sure existing tests pass and feel free to add more tests as you see fit.

    django-admin.py test --settings='tests.test_settings' --pythonpath=$PWD

  • Submit Pull Request

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].