diff --git a/data/fit4cybersecurity/context-questions.json b/data/fit4cybersecurity/context-questions.json index fb6e7645..1197f68a 100644 --- a/data/fit4cybersecurity/context-questions.json +++ b/data/fit4cybersecurity/context-questions.json @@ -3,7 +3,7 @@ "label": "What is your sector?", "service_category": "Context", "section": "__context", - "qtype": "SS", + "qtype": "SO", "maxPoints": 0, "answers": [ { diff --git a/data/survey4operators/context-questions.json b/data/survey4operators/context-questions.json index e239b60c..db51ed93 100644 --- a/data/survey4operators/context-questions.json +++ b/data/survey4operators/context-questions.json @@ -3,7 +3,7 @@ "label": "What is your sector?", "service_category": "Context", "section": "__context", - "qtype": "SS", + "qtype": "SO", "maxPoints": 0, "answers": [ { diff --git a/static/survey/js/chart.js b/static/survey/js/chart.js index 2ac94a06..8e63ddc3 100644 --- a/static/survey/js/chart.js +++ b/static/survey/js/chart.js @@ -1,5 +1,5 @@ $(document).ready(function () { - if (chartData && chartLabels) { + if (typeof chartData !== 'undefined' && typeof chartLabels !== 'undefined') { let ctx = document.getElementById('result-chart'); let resultChart = new Chart(ctx, { type: 'radar', diff --git a/survey/forms.py b/survey/forms.py index 11b3ae6d..86c1adec 100644 --- a/survey/forms.py +++ b/survey/forms.py @@ -37,10 +37,18 @@ def __init__(self, tanswers=None, *args, **kwargs): elif answers_field_type == "SS": self.fields["answers"] = forms.ChoiceField( required=False, - choices=question_answers, + choices=[], + widget=forms.Select(), + label="", + ) + elif answers_field_type == "SO": + self.fields["answers"] = forms.ChoiceField( + required=False, + choices=[], widget=forms.Select(), label="", ) + tanswers = sort_tuple_alphabetically(tanswers, 1) elif answers_field_type[0] == "S": self.fields["answers"] = forms.ChoiceField( required=True, diff --git a/survey/globals.py b/survey/globals.py index 2f60e4f3..aa4190c6 100644 --- a/survey/globals.py +++ b/survey/globals.py @@ -64,6 +64,7 @@ ("M", "Multiple Choice"), ("S", "Single Choice"), ("SS", "Single Select Choice"), + ("SO", "Single Select Ordered Choice "), ("T", "Free text"), ("MT", "Multiple Choice + Free Text"), ("ST", "Single Choice + Free Text"), diff --git a/survey/viewLogic.py b/survey/viewLogic.py index bf49f1a0..cc2a8ebe 100644 --- a/survey/viewLogic.py +++ b/survey/viewLogic.py @@ -76,7 +76,7 @@ def handle_start_survey(request: HttpRequest, lang: str) -> Union[Dict, SurveyUs question_answers = SurveyQuestionAnswer.objects.order_by("aindex").filter( question=question ) - tuple_answers = get_answer_choices(question_answers, lang) + tuple_answers = [(qa["id"], _(qa["label"])) for qa in question_answers.values()] except Exception as e: raise e forms[question.id] = AnswerMChoice( @@ -95,7 +95,7 @@ def handle_start_survey(request: HttpRequest, lang: str) -> Union[Dict, SurveyUs question_answers = SurveyQuestionAnswer.objects.order_by( "aindex" ).filter(question=question) - tuple_answers = get_answer_choices(question_answers, lang) + tuple_answers = [(qa["id"], _(qa["label"])) for qa in question_answers.values()] except Exception as e: raise e @@ -124,7 +124,6 @@ def handle_start_survey(request: HttpRequest, lang: str) -> Union[Dict, SurveyUs question_answers = SurveyQuestionAnswer.objects.order_by( "aindex" ).filter(question=question) - tuple_answers = get_answer_choices(question_answers, lang) except Exception as e: raise e @@ -136,7 +135,7 @@ def handle_start_survey(request: HttpRequest, lang: str) -> Union[Dict, SurveyUs return { "title": title, "forms": forms, - "questions_per_id": {question.id: question for question in questions}, + "questions_per_id": {question.id: _(question.label) for question in questions}, "action": action, "choosen_lang": lang, }