I have an application "Survey" for students where I need to update multiple
records against single table "Questions". These question features may vary
for each record as some would be multiple choices/radio/checkbox etc.
Following are my tables:

db.define_table('survey_question',
                Field('question_text', 'string', label=T('Question'),
required=True),
                Field('question_hint', 'string', label=T('Hint')),
                Field('questiontype_id', 'reference questiontype',
label=T('Type')),
                Field('questioncategory_id', 'reference category',
label=T('Category')),
                Field('question_weight', 'integer', label=T('Weight
(0-5)'), default=0, requires=IS_INT_IN_RANGE(0,5)),
                auth.signature,
                format='%(question_text)s'
                )

db.define_table('survey_question_choice',
                Field('choice_text', 'string', label=T('Text')),
                Field('choice_value', 'integer', label=T('Value')),
                Field('question_id', 'reference survey_question',
label=T('Choice')),
                auth.signature,
                format='%(choice_text)s'
                )

db.define_table('survey_question_subchoice',
                Field('choice_text', 'string', label=T('Text')),
                Field('choice_value', 'integer', label=T('Value')),
                Field('question_choice_id', 'reference
survey_question_choice', label=T('Sub Choice')),
                auth.signature,
                format='%(choice_text)s'
                )

db.define_table('survey_question_text',
                Field('question_text', 'text', label=T('Text')),
                Field('hint', 'string', label=T('Hint')),
                Field('question_id', 'reference survey_question',
label=T('Question')),
                auth.signature,
                format='%(question_text)s'
                )

db.define_table('survey_question_rating',
                Field('start_label', 'string', label=T('Start Label')),
                Field('finish_label', 'string', label=T('Finish Label')),
                Field('step_size', 'double', label=T('Step Size')),
                Field('num_stars', 'integer', label=T('Number of Stars')),
                Field('question_id', 'reference survey_question',
label=T('Question')),
                auth.signature,
                format='%(start_label)s'
                )

db.define_table('survey_response',
                Field('survey_id', 'reference survey', label=T('Survey'),
required=True),
                Field('user_id', 'reference auth_user', label=T('User')),
                Field('complete', 'boolean', required=True, default=False),
                auth.signature)

db.define_table('survey_text_response',
                Field('question_id', 'reference survey_question',
label=T('Question')),
                Field('text_value', 'string', label=T('Value')),
                auth.signature,
                migrate=True
                )

db.define_table('survey_choice_response',
                Field('response_id', 'reference survey_response',
required=True),
                Field('choice_id', 'reference survey_question_choice',
required=True),
                Field('choice_value', 'string', label=T('Value')),
                auth.signature
                )

db.define_table('survey_subchoice_response',
                Field('response_id', 'reference survey_response',
required=True),
                Field('subchoice_id', 'reference
survey_question_subchoice', required=True),
                Field('choice_value', 'string', label=T('Value')),
                auth.signature
                )

db.define_table('survey_question_order',
                Field('question_id', 'reference survey_question',
label=T('Question'), required=True),
                Field('survey_id', 'reference survey', label=T('Survey'),
required=True),
                Field('question_order', 'integer', required=True),
                auth.signature,
                format='%(order)s'
                )

db.define_table('survey_conditional_order',
                Field('question_order_id', 'reference
survey_question_order', label=T('Question Order')),
                Field('response_question_id', 'reference survey_question'),
                Field('positive_response_question_order_id', 'reference
survey_question_order'),
                Field('negative_response_question_order_id', 'reference
survey_question_order'),
                auth.signature
                )

My Views: (Under Development)

def create_question():
    form = SQLFORM.factory(db.survey_question, db.survey_question_choice,
db.survey_question_subchoice, db.survey_question_text)
    rating = SQLFORM(db.rating)
    if form.accepted:
        flash.message='Thanks for creating survey questions'
        redirect(URL('thank_you'))
    return locals()

def take_survey():
    uuid = request.args(0)
    survey = db.survey(uuid=uuid) or redirect(URL('survey'))
    if survey.requires_login:
        if not auth.user:
            redircet(URL('user/login', vars=dict(_next=URL(args=uuid))))
        vote = db.vote(survey=survey.id, created_by=auth.user.id)
        if vote:
            session.flash='You already took this survey!'
            redirect(URL('thank_you'))
    if request.post_vars:
        k = int(request.post_vars.survey_question_choice)
        survey.survey.response[k]+=1
        survey.update_record(results=survey_response)
        if survey.requires_login:
            db.vote.insert(survey=survey.id)
        redirect(URL('thank_you'))
    return locals()

def see_results():
    uuid = request.args(0)
    survey = db.survey(uuid=uuid) or redirect(URL('index'))
    if survey.created_by!=auth.user.id:
        session.flash='User not authorized'
        redirect(URL('index'))
    return locals()

I need to be able to create questions with multiple choices. Little help
will get me going.
Thanks,
Shazia

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to