示例#1
0
def save_eval(request, course_short_title):
    if request.is_ajax():

        #for key, value in request.POST.iteritems():
        #    print(key + " " + value)

        elab_id = request.POST['elaboration_id']
        publish = request.POST['publish']
        elab_parts_count = request.POST['elaboration_parts_count']
        elab_parts = simplejson.loads(request.POST['elab_parts'])
        user = CustomUser.objects.get(username=request.user.username)
        subm = Submission.objects.get(elaboration_id=elab_id)

        if publish == 'true':
            publish = True
        elif publish == 'false':
            publish = False

        re={}

        with reversion.create_revision():
            try:
                eval = Evaluation.objects.get(submission=subm)
                eval_exists = True
            except ObjectDoesNotExist:
                eval = Evaluation(submission=subm, user=user)
                eval_exists = False
                eval.evaluation_state = Evaluation.EVALUATION_STATE_EVALUATION_STARTED
                eval.save()

            for i in range (0, int(elab_parts_count)):
                elab_part_dict = elab_parts[i]
                eval_text = elab_part_dict['evaluation_text']
                eval_points = elab_part_dict['evaluation_points']
                elab_part_id = elab_part_dict['elaboration_part_id']

                eval_text = strip_tags(eval_text)

                if eval_points == '':
                    eval_points = None

                elab_part = ElaborationPart.objects.get(id=elab_part_id)

                if eval_exists:
                    #eval = Evaluation.objects.get(submission=subm)
                    subm_part = SubmissionPart.objects.get(elaboration_part=elab_part, submission=subm)
                    eval_part = EvaluationPart.objects.get(evaluation=eval, submission_part=subm_part)
                    eval_part.feedback = eval_text
                    eval_part.assigned_points = eval_points
                    eval_part.save()
                    re['response']='updated'
                else:
                    subm_part = SubmissionPart.objects.get(submission=subm, elaboration_part=elab_part)
                    EvaluationPart(evaluation=eval, submission_part=subm_part, feedback=eval_text, assigned_points=eval_points).save()
                    re['response']='created'


            #create a version of all elaboration + submission objects
            #at the time of the first evaluation of a new submission
            if not eval_exists or eval.evaluation_state==Evaluation.EVALUATION_STATE_NO_EVALUATION:
                elab = Elaboration.objects.get(id=elab_id)

                elab.save()
                subm.save()

                for i in range (0, int(elab_parts_count)):

                    elab_part_dict = elab_parts[i]
                    elab_part_id = elab_part_dict['elaboration_part_id']

                    elab_part = ElaborationPart.objects.get(id=elab_part_id)
                    subm_part = SubmissionPart.objects.get(submission=subm, elaboration_part=elab_part)

                    elab_part.save()
                    subm_part.save()

            #save states
            if publish:
                subm.submission_state=Submission.SUBMISSION_STATE_EVALUATED
                eval.evaluation_state = Evaluation.EVALUATION_STATE_EVALUATION_PUBLISHED
            else:
                subm.submission_state=Submission.SUBMISSION_STATE_WAITING_FOR_EVALUATION
                eval.evaluation_state = Evaluation.EVALUATION_STATE_EVALUATION_STARTED

            eval.creation_date=timezone.localtime(timezone.now())
            eval.save()


        subm.save()

        lock = SubmissionLock.objects.get(submission=subm, user=user, release_date__gt=timezone.localtime(timezone.now()))
        lock.release_date = timezone.localtime(timezone.now())
        lock.save()
        re['lock']='resolved'

        response = simplejson.dumps(re)

        return HttpResponse(response, mimetype='application/json')
示例#2
0
def create_test_challenge(request, course_short_title):
    if request.is_ajax():
        step = request.POST['step']

        if int(step)==0:
            #create a elab+subm
            print('create test elab+subm')

            elaboration = Elaboration(id=10000, main_challenge_id=200, portfolio_id=1, user_id=1)
            elaboration.creation_date=datetime.datetime(2013, 2, 16, 15, 24, 17, 345952, tzinfo=utc)
            elaboration.save()

            elaboration_part = ElaborationPart(elaboration=elaboration, sub_challenge_id=200,
                elaboration_text='this is some test text for subchallenge 1 version 1', elaboration_points=4)
            elaboration_part.save()
            elaboration_part2 = ElaborationPart(elaboration=elaboration, sub_challenge_id=201,
                elaboration_text='this is some test text for subchallenge 2 version 1', elaboration_points=4)
            elaboration_part2.save()
            submission = Submission(id=10000, elaboration=elaboration, submission_date=datetime.datetime(2013, 2, 18, 15, 24, 17, 345952, tzinfo=utc))
            submission.save()

            submission.submission_date = datetime.datetime(2013, 2, 18, 15, 24, 17, 345952, tzinfo=utc)
            submission.save()

            submission_part = SubmissionPart(submission=submission, elaboration_part=elaboration_part)
            submission_part.save()

            submission_part2 = SubmissionPart(submission=submission, elaboration_part=elaboration_part2)
            submission_part2.save()
        elif int(step)==1:
            #create a evaluation
            print('create test evaluation')
            with reversion.create_revision():

                elaboration = Elaboration.objects.get(id=10000)
                elaboration_part = ElaborationPart.objects.get(elaboration=elaboration, sub_challenge_id=200)
                elaboration_part.save()
                elaboration_part2 = ElaborationPart.objects.get(elaboration=elaboration, sub_challenge_id=201)
                elaboration_part2.save()

                submission = Submission.objects.get(id=10000)
                submission.submission_state = Submission.SUBMISSION_STATE_EVALUATED
                submission.save()

                submission_part = SubmissionPart.objects.get(submission=submission, elaboration_part = elaboration_part)
                submission_part2 = SubmissionPart.objects.get(submission=submission, elaboration_part = elaboration_part2)

                submission_part.save()
                submission_part2.save()

                evaluation = Evaluation(id=10000, submission=submission, user_id=2, creation_date=timezone.localtime(timezone.now()), evaluation_state=Evaluation.EVALUATION_STATE_EVALUATION_PUBLISHED)
                evaluation.creation_date=datetime.datetime(2013, 2, 20, 15, 24, 17, 345952, tzinfo=utc)
                evaluation.save()

                eval_part = EvaluationPart(evaluation=evaluation, submission_part=submission_part, feedback='this is version 1 of the evaluation of version 1 of the subchallenge 1', assigned_points=3)
                eval_part.save()

                eval_part2 = EvaluationPart(evaluation=evaluation, submission_part=submission_part2, feedback='this is version 1 of the evaluation of version 1 of the subchallenge 2', assigned_points=2)
                eval_part2.save()

        elif int(step)==2:
            #create a second evaluation
            print('create test 2nd eval')
            with reversion.create_revision():
                submission = Submission.objects.get(id=10000)
                elaboration = Elaboration.objects.get(id=10000)

                elaboration_part = ElaborationPart.objects.get(elaboration=elaboration, sub_challenge_id=200)
                elaboration_part2 = ElaborationPart.objects.get(elaboration=elaboration, sub_challenge_id=201)

                submission_part = SubmissionPart.objects.get(submission=submission, elaboration_part = elaboration_part)
                submission_part2 = SubmissionPart.objects.get(submission=submission, elaboration_part = elaboration_part2)

                evaluation = Evaluation.objects.get(id=10000)
                evaluation.creation_date=datetime.datetime(2013, 2, 22, 15, 24, 17, 345952, tzinfo=utc)
                evaluation.save()

                eval_part = EvaluationPart.objects.get(evaluation=evaluation, submission_part=submission_part)
                eval_part.feedback = 'this is version 2 of the evaluation of version 1 of the subchallenge 1'
                eval_part.assigned_points = 4
                eval_part.save()

                eval_part2 = EvaluationPart.objects.get(evaluation=evaluation, submission_part=submission_part2)
                eval_part2.feedback = 'this is version 2 of the evaluation of version 1 of the subchallenge 2'
                eval_part2.assigned_points = 4
                eval_part2.save()
        elif int(step)==3:
            #revise the submission
            print('revise the subm')

            submission = Submission.objects.get(id=10000)
            submission.submission_state = Submission.SUBMISSION_STATE_BEING_REVISED
            submission.save()
        elif int(step)==4:
            #create a second version of the elab + submit again
            print('create test 2nd elab+subm')
            elaboration = Elaboration.objects.get(id=10000)

            elaboration_part = ElaborationPart.objects.get(elaboration=elaboration, sub_challenge_id=200)
            elaboration_part2 = ElaborationPart.objects.get(elaboration=elaboration, sub_challenge_id=201)

            elaboration_part.elaboration_text = 'this is some test created elaboration for subchallenge 1, version 2'
            elaboration_part.save()

            elaboration_part2.elaboration_text = 'this is some test created elaboration for subchallenge 2, version 2'
            elaboration_part2.save()

            submission = Submission.objects.get(id=10000)
            submission_part = SubmissionPart.objects.get(submission = submission, elaboration_part = elaboration_part)
            submission_part2 = SubmissionPart.objects.get(submission=submission, elaboration_part = elaboration_part2)

            submission.submission_date=datetime.datetime(2013, 2, 24, 15, 24, 17, 345952, tzinfo=utc)
            submission.submission_state = Submission.SUBMISSION_STATE_WAITING_FOR_EVALUATION
            submission.save()
            submission_part.save()
            submission_part2.save()

            """
            evaluation = Evaluation.objects.get(id=10000)
            eval_part = EvaluationPart.objects.get(evaluation=evaluation, submission_part=submission_part)
            eval_part.delete()
            evaluation.delete()
             """

            evaluation = Evaluation.objects.get(id=10000)
            evaluation.creation_date=datetime.datetime(2013, 2, 26, 15, 24, 17, 345952, tzinfo=utc)
            evaluation.evaluation_state=Evaluation.EVALUATION_STATE_NO_EVALUATION
            evaluation.save()

            eval_part = EvaluationPart.objects.get(evaluation=evaluation, submission_part=submission_part)
            eval_part.feedback = ''
            eval_part.assigned_points = None
            eval_part.save()

            eval_part2 = EvaluationPart.objects.get(evaluation=evaluation, submission_part=submission_part2)
            eval_part2.feedback = ''
            eval_part2.assigned_points = None
            eval_part2.save()

        return HttpResponse({}, mimetype='application/json')