Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     """
     This method creates text field for each choice.  The choice's text value is used as
     initial data.
     Creates extra field for adding a new choice. 
     """    
     super(MultipleChoiceEditForm, self).__init__(*args, **kwargs)
     self.fields["concept"] = forms.ModelChoiceField(queryset=get_concept_list(),
                                                     initial = self.instance.content_object)
     self.fields["correct"] = forms.ChoiceField(label=_("Correct Choice"),
                                                choices=self.choices(),
                                                initial=self.instance.correct_option.id,
                                                widget=forms.RadioSelect)
     # Create fields for choices and indices
     # choice_1, index_1, choice_2, index_2, ...
     i = 1
     for choice in self.instance.multiplechoiceoption_set.all():
         self.fields["choice_%d" % choice.id] = forms.CharField(label=_("Choice"),
                                                                required=False,
                                                                initial=choice.text)
         self.fields["index_%d" % choice.id] = forms.IntegerField(label=_("Order"),
                                                                  required=False,
                                                                  initial=choice.index,
                                                                  validators=[
                                                                  MaxValueValidator(MAX_CHOICES),
                                                                  MinValueValidator(1)])
         i = i + 1
     if(i <= MAX_CHOICES):
         self.fields["choice_new"] = forms.CharField(label=_("Add A Choice:"), required=False)
         self.fields["index_new"] = forms.IntegerField(label=_("Order"), required=False)
Ejemplo n.º 2
0
def get_data(exam):
    mc = {}
    fr = {}
    for concept in get_concept_list():
        concept_type = ContentType.objects.get_for_model(concept)
        fr_question_list = FreeResponseQuestion.objects.filter(
            exam=exam, content_type__pk=concept_type.id, object_id=concept.id)
        mc_question_list = MultipleChoiceQuestion.objects.filter(
            exam=exam, content_type__pk=concept_type.id, object_id=concept.id)
        fr[concept] = fr_question_list
        mc[concept] = mc_question_list
    return [fr, mc]
Ejemplo n.º 3
0
def get_data(exam):
    mc = {}
    fr = {}
    for concept in get_concept_list():
        concept_type = ContentType.objects.get_for_model(concept)
        fr_question_list = FreeResponseQuestion.objects.filter(exam = exam,
                                                               content_type__pk=concept_type.id,
                                                               object_id=concept.id)
        mc_question_list = MultipleChoiceQuestion.objects.filter(exam = exam,
                                                               content_type__pk=concept_type.id,
                                                               object_id=concept.id)
        fr[concept] = fr_question_list
        mc[concept] = mc_question_list
    return [fr, mc]
Ejemplo n.º 4
0
 def get_data(self, **kwargs):
     """
     Returns 2 dictionaries (in a tuple), each dict maps each concept to a list of
     all associated questions of that question type.
     """
     mc = {}
     fr = {}
     for concept in get_concept_list():
         concept_type = ContentType.objects.get_for_model(concept)
         fr[concept] = FreeResponseQuestion.objects.filter(exam = self.object,
                                                           content_type__pk=concept_type.id,
                                                           object_id=concept.id)
         mc_qSet= MultipleChoiceQuestion.objects.filter(exam = self.object,
                                                             content_type__pk=concept_type.id,
                                                             object_id=concept.id)
         mc_list = []
         for q in mc_qSet:
             mc_list.append([q, q.multiplechoiceoption_set.all()])
         mc[concept] = mc_list
     return (fr, mc)
Ejemplo n.º 5
0
 def get_data(self, **kwargs):
     """
     Returns 2 dictionaries (in a tuple), each dict maps each concept to a list of
     all associated questions of that question type.
     """
     mc = {}
     fr = {}
     for concept in get_concept_list():
         concept_type = ContentType.objects.get_for_model(concept)
         fr[concept] = FreeResponseQuestion.objects.filter(
             exam=self.object,
             content_type__pk=concept_type.id,
             object_id=concept.id)
         mc_qSet = MultipleChoiceQuestion.objects.filter(
             exam=self.object,
             content_type__pk=concept_type.id,
             object_id=concept.id)
         mc_list = []
         for q in mc_qSet:
             mc_list.append([q, q.multiplechoiceoption_set.all()])
         mc[concept] = mc_list
     return (fr, mc)
Ejemplo n.º 6
0
class SelectConceptForm(forms.Form):
    """
    A form for selecting a concept
    """
    concept = forms.ModelChoiceField(queryset=get_concept_list(),
                                     to_field_name="name", )
Ejemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     super(FreeResponseEditForm, self).__init__(*args, **kwargs)
     self.fields["concept"] = forms.ModelChoiceField(queryset=get_concept_list(),
                                                     initial = self.instance.content_object)
Ejemplo n.º 8
0
 def setUp(self):
     get_concept_list()
     self.user = set_up_user()
     self.user.profile.is_contrib = True
     self.user.profile.save()
     self.client.login(email=self.user.email, password='******')
Ejemplo n.º 9
0
 def setUp(self):
     get_concept_list()
     self.user = set_up_user()
Ejemplo n.º 10
0
 def setUp(self):
     get_concept_list()
     self.user = set_up_user()
     self.user.is_staff = True
     self.user.save()
     self.client.login(email=self.user.email, password='******')