def saveAnswers(questions, series_id, complete_id, rvars):

    text = ""
    table = current.s3db.survey_complete
    for question in questions:
        code = question["code"]
        if (code in rvars) and rvars[code] != "":
            line = '"%s","%s"\n' % (code, rvars[code])
            text += line
    if complete_id == None:
        # Insert into database
        record_id = table.insert(series_id = series_id, answer_list = text)
        S3SurveyCompleteModel.completeOnAccept(record_id)
        return record_id
    else:
        # Update the complete_id record
        current.db(table.id == complete_id).update(answer_list = text)
        S3SurveyCompleteModel.completeOnAccept(complete_id)
        return complete_id

# =============================================================================
Insert/Update a record in survey_complete
dataset/ETHPy150Open sahana/eden/modules/s3db/survey.py/saveAnswers