# Path: pinax/lms/activities/forms.py
# class SurveyForm(forms.Form):
# 
#     def __init__(self, *args, **kwargs):
# 
#         self.questions = kwargs.pop("questions")
#         super(SurveyForm, self).__init__(*args, **kwargs)
# 
#         for question in self.questions:
#             field_class = question["field_class"]
#             kwargs = {
#                 "label": question["label"],
#             }
# 
#             if question.get("help_text"):
#                 kwargs.update({"help_text": question["help_text"]})
# 
#             if question.get("required") is not None:
#                 kwargs.update({"required": question["required"]})
# 
#             kwargs.update(question.get("extra_args", {}))
#             self.fields[question["name"]] = field_class(**kwargs)
# 
# Path: pinax/lms/activities/signals.py



from django.shortcuts import redirect, render
from .forms import SurveyForm
from .signals import activity_completed
                self.session_state.data.update({"answer_%d" % data["question_number"]: answer})
                self.session_state.data.update({"question_number": data["question_number"] + 1})

                return self.valid_response(request, data)
        return self.render(request)

    def completed(self, request):
        self.session_state.mark_completed()
        data = self.session_state.data
        results = []

        for i, question in enumerate(data["questions"]):
            answer = data["answer_%d" % i]
            if answer in ["left", "L2", "L1"]:
                answer = question[1][0]
            elif answer in ["right", "R2", "R1"]:
                answer = question[1][1]
            elif answer == "0":
                answer = None
            results.append((question, answer))

        ctx = {
            "title": self.title,
            "description": self.description,
            "help_text": getattr(self, "help_text", None),
            "results": results,
            "activity_key": self.activity_state.activity_key,
            "answer_template": self.answer_template,
        }
        ctx.update(self.extra_context)

# Path: pinax/lms/activities/forms.py
# class SurveyForm(forms.Form):
# 
#     def __init__(self, *args, **kwargs):
# 
#         self.questions = kwargs.pop("questions")
#         super(SurveyForm, self).__init__(*args, **kwargs)
# 
#         for question in self.questions:
#             field_class = question["field_class"]
#             kwargs = {
#                 "label": question["label"],
#             }
# 
#             if question.get("help_text"):
#                 kwargs.update({"help_text": question["help_text"]})
# 
#             if question.get("required") is not None:
#                 kwargs.update({"required": question["required"]})
# 
#             kwargs.update(question.get("extra_args", {}))
#             self.fields[question["name"]] = field_class(**kwargs)
# 
# Path: pinax/lms/activities/signals.py



# Path: pinax/lms/activities/base.py
from django.shortcuts import redirect, render
from .forms import SurveyForm
from .signals import activity_completed

                self.session_state.data.update({"answer_%d" % data["question_number"]: answer})
                self.session_state.data.update({"question_number": data["question_number"] + 1})

                return self.valid_response(request, data)
        return self.render(request)

    def completed(self, request):
        self.session_state.mark_completed()
        data = self.session_state.data
        results = []

        for i, question in enumerate(data["questions"]):
            answer = data["answer_%d" % i]
            if answer in ["left", "L2", "L1"]:
                answer = question[1][0]
            elif answer in ["right", "R2", "R1"]:
                answer = question[1][1]
            elif answer == "0":
                answer = None
            results.append((question, answer))

        ctx = {
            "title": self.title,
            "description": self.description,
            "help_text": getattr(self, "help_text", None),
            "results": results,
            "activity_key": self.activity_state.activity_key,
            "answer_template": self.answer_template,
        }
        ctx.update(self.extra_context)

        activity_completed.send(sender=self, activity_key=self.activity_key, activity_session_state=self.session_state, request=request)