Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     user = kwargs.pop('user', None)
     self.assessment = kwargs.pop('assessment', None)
     super(TagsCopyForm, self).__init__(*args, **kwargs)
     self.fields['assessment'].widget.attrs['class'] = 'span12'
     self.fields['assessment'].queryset = Assessment.get_viewable_assessments(
         user, exclusion_id=self.assessment.id)
Ejemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     user = kwargs.pop('user', None)
     self.assessment = kwargs.pop('assessment', None)
     super(TagsCopyForm, self).__init__(*args, **kwargs)
     self.fields['assessment'].widget.attrs['class'] = 'span12'
     self.fields['assessment'].queryset = Assessment.get_viewable_assessments(
         user, exclusion_id=self.assessment.id)
Ejemplo n.º 3
0
    def get_form_kwargs(self):
        kwargs = super(SearchNew, self).get_form_kwargs()

        # check if we have a template to use
        pk = tryParseInt(self.request.GET.get("initial"), -1)

        if pk > 0:
            obj = self.model.objects.filter(pk=pk).first()
            permitted_assesments = Assessment.get_viewable_assessments(
                self.request.user, exclusion_id=self.assessment.pk
            )
            if obj and obj.assessment in permitted_assesments:
                kwargs["initial"] = model_to_dict(obj)

        return kwargs
Ejemplo n.º 4
0
    def get_form_kwargs(self):
        kwargs = super(BaseCreate, self).get_form_kwargs()

        # all inputs require a parent field
        kwargs['parent'] = self.parent

        # check if we have an object-template to be used
        pk = tryParseInt(self.request.GET.get('initial'), -1)

        if pk > 0:
            initial = self.model.objects.filter(pk=pk).first()
            if initial and initial.get_assessment() in \
                    Assessment.get_viewable_assessments(self.request.user, public=True):
                kwargs['initial'] = model_to_dict(initial)

        return kwargs
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        kwargs.pop('assessment', None)

        super(SearchSelectorForm, self).__init__(*args, **kwargs)

        for fld in self.fields.keys():
            self.fields[fld].widget.attrs['class'] = 'span11'

        assessment_pks = Assessment.get_viewable_assessments(user)\
                                   .values_list('pk', flat=True)

        self.fields['searches'].queryset = self.fields['searches'].queryset\
                                               .filter(assessment__in=assessment_pks)\
                                               .exclude(title="Manual import")\
                                               .order_by('assessment_id')
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        assessment = kwargs.pop('assessment', None)

        super(SearchSelectorForm, self).__init__(*args, **kwargs)

        for fld in self.fields.keys():
            self.fields[fld].widget.attrs['class'] = 'span11'

        assessment_pks = Assessment.get_viewable_assessments(user)\
                                   .values_list('pk', flat=True)

        self.fields['searches'].queryset = self.fields['searches'].queryset\
                                               .filter(assessment__in=assessment_pks)\
                                               .exclude(title="Manual import")\
                                               .order_by('assessment_id')
Ejemplo n.º 7
0
    def get_form_kwargs(self):
        kwargs = super(SearchNew, self).get_form_kwargs()

        # check if we have a template to use
        try:
            pk = int(self.request.GET.get('initial', -1))
        except ValueError:
            pk = -1

        if pk > 0:
            obj = self.model.objects.filter(pk=pk).first()
            permitted_assesments = Assessment.get_viewable_assessments(
                self.request.user, exclusion_id=self.assessment.pk)
            if obj and obj.assessment in permitted_assesments:
                kwargs['initial'] = model_to_dict(obj)

        return kwargs
Ejemplo n.º 8
0
    def get_form_kwargs(self):
        kwargs = super(SearchNew, self).get_form_kwargs()

        # check if we have a template to use
        try:
            pk = int(self.request.GET.get('initial', -1))
        except ValueError:
            pk = -1

        if pk > 0:
            obj = self.model.objects.filter(pk=pk).first()
            permitted_assesments = Assessment.get_viewable_assessments(
                self.request.user, exclusion_id=self.assessment.pk)
            if obj and obj.assessment in permitted_assesments:
                kwargs['initial'] = model_to_dict(obj)

        return kwargs
Ejemplo n.º 9
0
    def __init__(self, *args, **kwargs):
        user = kwargs.pop("user", None)
        kwargs.pop("assessment", None)

        super(SearchSelectorForm, self).__init__(*args, **kwargs)

        for fld in self.fields.keys():
            self.fields[fld].widget.attrs["class"] = "span11"

        assessment_pks = Assessment.get_viewable_assessments(user).values_list("pk", flat=True)

        self.fields["searches"].queryset = (
            self.fields["searches"]
            .queryset.filter(assessment__in=assessment_pks)
            .exclude(title="Manual import")
            .order_by("assessment_id")
        )
def make_new_assessment(request):
    name = request.POST['Assessment name']
    description = request.POST['description']
    course_id = request.POST['course id']
    start_dt = request.POST['start date']
    end_dt = request.POST['end date']

    valid = False
    
    # Validate Date Format
    if regex_search(r'[0-9]+\-[0-9]+\-[0-9]+', start_dt) and regex_search(r'[0-9]+\-[0-9]+\-[0-9]+', end_dt):
        st_dt_list = start_dt.split('-')
        end_dt_list = end_dt.split('-')
        valid = True
    else:
        messages.error(request, "Error: Incorrect date format. Use yyyy-mm-dd")
        return make_new_assessment(request)

    if valid:
    # -----------if starts here -------------------------   
        # Create an instance of assessment
        assessment = Assessment(
                        name = name.title(), 
                        description = description, 
                        start_date = start_dt, 
                        end_date = end_dt, 
                        course = Course.objects.get(pk=course_id),
                        )
        assessment.save()
        
        # Add questions to the assessment
        idx = 0
        more_questions = True
        # while more_questions: # keeps checking if more questions
        for idx in range(1000):
            try:
                question_text = request.POST['question-{}'.format(idx)]
                answer_type = request.POST['answer type-{}'.format(idx)]
            except MultiValueDictKeyError: # this error means no more questions
                question_text = False
                answer_type = False
            if question_text == False: # if no more questions - break
                more_questions = False
                # break
            else:
                # Check which answer type
                if answer_type == "Free Response":
                    type_answer = Question.TYPE_TEXT
                else:
                    type_answer = Question.TYPE_Rating
                # Create an instance of question
                new_question = Question(
                                        question_text=question_text,
                                        type_answer=type_answer,
                                        )
                new_question.save()
                # Save this new question into the assessment's ManytoMany field
                assessment.questions.add(new_question)
                assessment.save()
            # # update counter
            # idx += 1

        messages.error(request, 'New assessment created')
    # ---------------if ends here-------------

    # messages.error(request, 'New course creation is successful!')

    return all_assessments(request) # go to all assessment page
Ejemplo n.º 11
0
 def __init__(self, *args, **kwargs):
     user = kwargs.pop("user", None)
     self.assessment = kwargs.pop("assessment", None)
     super(TagsCopyForm, self).__init__(*args, **kwargs)
     self.fields["assessment"].widget.attrs["class"] = "span12"
     self.fields["assessment"].queryset = Assessment.get_viewable_assessments(user, exclusion_id=self.assessment.id)