コード例 #1
0
 def get_for_section_by_question_id(self, section_id, user_id,
                                    user_report_id):
     """
     Get all questionAnswers for a specific section (section_id) in a dict
     where the key is the question_id, for a specific user in a specific UserReport
     :param section_id:
     :param user_id:
     :param user_report_id:
     :return:
     """
     section_api = SectionApi()
     current_section = section_api.read(section_id)
     ordered_questions = {}
     for question in current_section.questions:
         if question.id in ordered_questions:
             raise DatabaseItemAlreadyExists(
                 _('Error: two questions with the same id in one section!'))
         # Get the QuestionAnswers object
         try:
             question_answer = self.get_answer_by_question_id(
                 question.id, user_id, user_report_id)
         except DatabaseItemDoesNotExist:
             continue
         ordered_questions[question.id] = question_answer
     return ordered_questions
コード例 #2
0
ファイル: __init__.py プロジェクト: wovari/scoremodel
def v_user_report_section(user_id, user_report_id, section_id):
    section_api = SectionApi()
    if current_user.id != user_id:
        flash(_('You can only view your own reports.'))
        abort(403)
        return
    try:
        user_report = user_report_api.read(user_report_id)
    except DatabaseItemDoesNotExist as e:
        abort(404)
        return
    except Exception as e:
        flash(_('An unexpected error occurred.'))
        return redirect(url_for('site.v_index'))

    # Check whether current section is in this user_report
    if section_id not in [
            section.id for section in user_report.template.sections
    ]:
        abort(404)
        return

    current_section = section_api.read(section_id)

    # Get all question_answers for this report and order them by question_id, so we can compare
    # question.answer.answer_id to question_answers['question_id'].answer_id
    question_answers = {}
    for question_answer in user_report.question_answers:
        question_answers[question_answer.question_id] = question_answer

    benchmarks_by_section = user_report_api.benchmarks_by_section(
        user_report_id)

    # Create a color-range for the risk_factors
    risk_factors = [r.risk_factor for r in RiskFactorApi().list()]
    colored_risk_factors = Color().range(risk_factors)

    return render_template('public/section.html',
                           title=current_section.title,
                           section=current_section,
                           user_report_id=user_report_id,
                           question_answers=question_answers,
                           next_section=current_section.next_in_report,
                           previous_section=current_section.previous_in_report,
                           benchmarks_by_section=benchmarks_by_section,
                           colored_risk_factors=colored_risk_factors)