Giter Site home page Giter Site logo

django-domande's Introduction

django-domande's People

Contributors

bulkan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

django-domande's Issues

Saving wrong answers

Hi,

there seems to be a very subtle but NASTY bug that causes domande to save wrong answers on choice questions. I'm sorry I currently don't have time for a full pull request, but this should provide enough information to fix it!

Description of the bug

In forms.py, we take the IDs of choice answers that were selected by the user. Then we search for the corresponding choice objects and add them to the choiceanswer. The code looks like this:

        real_answer = self.cleaned_data.get('answer')
        ...
        choices = Choice.objects.filter(id__in=real_answer)

The goal here is to take the ID of all selected answers as strings and get the corresponding choice objects. But there's a problem: real_answer is a list if the question is multiple choice. But if it's a single choice question (radio buttons), then it's a string! That means that the query Choice.objects.filter(id__in=real_answer) goes awry and does a search for IDs containing the real string ID!

This is especially bad, because it will only show if you have more than 9 choice objects. Example: A choice question is answered with real_answer "22". The query looks for any choice where the ID contains one of the chars in "22", for example Choice(id=2).

FIX

We need to make sure that real_answer is always a list, so the following should suffice but still needs to be tested!
Note the "elif": If real_answer is empty, we can't make it a list since that would foil the lookup again.

        from survey.models import ChoiceAnswer, Choice
        real_answer = self.cleaned_data.get('answer')
        if not real_answer:
            if self.fields['answer'].required:
                raise forms.ValidationError, 'Required'
                return
        elif not isinstance(real_answer, list):
            real_answer = [real_answer]
        choices = Choice.objects.filter(id__in=real_answer)

PS: Here's another potential gotcha: We can't use real_answer = list(real_answer) because that would split the string into a list!

Anyway, hope that helps!

Customizable error messages

  • add error_message field to Question model
  • in the form when creating field pass self.question.error_message as the message field if its defined

selectable validators

Each Question should have a user selectable list of validators associated with it.

phone number, postcode, numbers only, letters only.

# inside of QuestionForm 

def answer_clean(self, value):
    for validator in self.question.validators:
         validator(value)

django 1.7

@bulkan The south app is at end of the life, and also most of the import statements also not working with this app.

can update with all the latest changes with Django 1.7?

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.