'Adds a question to the template corresponding to template_id'

@staticmethod
def add_question(template_id, name, code, notes, qtype, posn, metadata={}):

    db = current.db
    s3db = current.s3db
    qtable = s3db.survey_question
    query = ((qtable.name == name) & (qtable.code == code))
    record = db(query).select(qtable.id, limitby=(0, 1)).first()
    if record:
        qstn_id = record.id
    else:
        qstn_id = qtable.insert(name=name, code=code, notes=notes, type=qtype)
        qstn_metadata_table = s3db.survey_question_metadata
        for (descriptor, value) in metadata.items():
            qstn_metadata_table.insert(question_id=qstn_id, descriptor=descriptor, value=value)
    sectable = s3db.survey_section
    section_name = 'Background    Information'
    query = ((sectable.name == section_name) & (sectable.template_id == template_id))
    record = db(query).select(sectable.id, limitby=(0, 1)).first()
    if record:
        section_id = record.id
    else:
        section_id = sectable.insert(name=section_name, template_id=template_id, posn=0)
    qltable = s3db.survey_question_list
    query = ((qltable.question_id == qstn_id) & (qltable.template_id == template_id))
    record = db(query).select(qtable.id, limitby=(0, 1)).first()
    if (not record):
        qltable.insert(question_id=qstn_id, template_id=template_id, section_id=section_id, posn=posn)
