I am trying to build a survey_app for researchers in were I work.  In the
past they gave me a Word document with the survey and I had to build a long
form in web2py.  Now I want them to build their own survey using this app.

In the original way of doing this the survey was one long form and in some
cases I used javascript to hide certain questions depending on particular
options selected in previous questions.

In the new app there will not be one long form, but the questions will be
shown one at a time.

I thought of handling the conditional show of questions in the following
way:

In the 'options'  table (and the IS_IN_SET part is wrong at the moment) I
have:

db.define_table('options',
                Field('question_id', db.questions),
                Field('option_number', requires = IS_NOT_EMPTY()),
                Field('option', requires = IS_NOT_EMPTY()),
                Field('dont_show_question', 'reference questions',
                  requires = IS_IN_SET(lambda row:
questionlist(row.question_id))))

where the function question list does this:

def questionlist(question_id):
    survey_id = db.questions[question_id]
    query = db.questions.id != question_id & db.questions.survey_id ==
survey_id
    questionlist = [(x.id, '%s %s' % (x.question_number,
x.question.question))
                          for x in db(query).select(db.questions.id,

db.questions.question_number,

db.questions.question)]
    return questionlist

My idea is that at the time of creating the researcher can specify which
question must be hidden when a particular option is chosen.

Then when the client answers the survey use the following tables:

db.define_table('answers',
                Field('survey_id', db.survey),
                Field('question_id', db.questions),
                Field('answer', 'text',
                  widget = advanced_editor),
                Field('option', label = 'Option number'),
                Field('sessionid', length=36,
                      writable = False, default=lambda:str(uuid.uuid4())))

db.define_table('dontshow',
                Field('sessionid', length=36,
                      requires = IS_NOT_EMPTY()),
                Field('question_id', 'reference questions', requires =
                      IS_IN_DB(db, 'questions.id', '%(question_number)s')))

The variable 'sessionid'  is created when a client starts the survey.

The second table gets its information when the client select an option
which utilizes the 'dont_show_question' field.  This is then used by the
controller to decide which questions not to show for this session.

If there is an easier way of doing this, I would like to learn from you.

Then also:  How do I correctly use the IS_IN_SET in the options table to
use the questionlist-function?

Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to