Esempio n. 1
0
def student_papersummarize(request):
    student, res = getSpByRequest(request, 'login')
    if not student and res:
        return res
    paperid = request.GET.get('paperid')
    passed = request.GET.get('passed')
    try:
        paper = Paper.objects.get(id=paperid)
        questionseq = pickle.loads(str(paper.questionseq))
    except:
        return HttpResponse("paper does not exist")
    if paper and questionseq:
        question_set = Question.objects.filter(id__in=questionseq)
        stuanswer_set = getStuanswers(question_set, student)
        if passed == '0':
            mark = _reinitanswer(stuanswer_set)
            messages.add_message(
                request, messages.INFO,
                "You failed in this paper, please don\'t be panic, you can take it again"
            )
        else:
            mark = sum(ans.mark for ans in stuanswer_set)
    else:
        mark = 0
    return render_to_response('student_assignmentsummarize.html', {
        'paper': paper,
        'mark': mark
    },
                              context_instance=RequestContext(request))
Esempio n. 2
0
def _getassignmentjson(assignments, teacher, student):
    assignment_list = []
    for a in assignments:
        papers = Paper.objects.filter(assignment=a, owner=teacher.user)
        for p in papers:
            try:
                questionseq = pickle.loads(str(p.questionseq))
                question_set = Question.objects.filter(id__in=questionseq)
                stuanswer_set = getStuanswers(question_set, student)
                count = sum(1 for sa in stuanswer_set if sa.taked)
            except Exception, e:
                logger.error(e)
                logger.error(a)
                logger.error(p)
                break
            if count == p.total:
                action = "<a href='/student/summarize/?paperid=%s'>\
                            <font color=black>View</font></a>" % str(p.id)
            else:
                action = "<a href='/student/takeassignment/?paperid=%s'>\
                            <font color=black>Take</font></a>&nbsp;&nbsp;&nbsp;\
                            &nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;\
                            <a href='/student/summarize/?paperid=%s'>\
                            <font color=black>View</font></a>" % (str(
                    p.id), str(p.id))
            assignment_list.append([a, count, p, action])
Esempio n. 3
0
def student_takeassignment(request):
    print "this is assignment"
    student, res = getSpByRequest(request, None)
    paperid = request.GET.get("paperid")
    retake = request.GET.get("retake")

    print retake, "retake"
    try:
        paper = Paper.objects.get(id=paperid)
        questionseq = pickle.loads(str(paper.questionseq))
    except:
        paper = None
        questionseq = []
    if paper and questionseq:
        try:
            assignment = paper.assignment
        except:
            assignment = None
        try:
            question_set = Question.objects.filter(id__in=questionseq)
            stuanswer_set = getStuanswers(question_set, student)
            qnameseq = list(
                Question.objects.get(id=qid).qname for qid in questionseq)
        except Exception, e:
            logger.error(e)
            stuanswer_set = []
            qnameseq = []
        #custom paper student can retake
        if retake:
            _reinitanswer(stuanswer_set)
            stuanswer_set = []
        if stuanswer_set:
            teacher_assignment_retake = retake_option(stuanswer_set)
            anscount = sum(1 for stuanswer in stuanswer_set if stuanswer.taked)
            if not teacher_assignment_retake and anscount == paper.total and paper.ptype != 'Review':
                return redirect('student_index')
            else:
                logger.debug(stuanswer_set)
                duration = stuanswer_set[0].timeleft
                logger.debug(duration)
                if duration != -1:
                    __getInstallTimer(request, duration)
                else:
                    duration = __initstuanswer(paper, question_set, student)
                    __getInstallTimer(request, duration)
        else:
            duration = __initstuanswer(paper, question_set, student)
            __getInstallTimer(request, duration)
        if assignment:
            ## HACK: disable the deadline check
            #            if assignment.deadline < datetime.now() + timedelta(seconds=duration):
            #                return HttpResponse("Test time %s is due, you haven\'t enough time: %s"
            #                                    % (assignment.deadline, timedelta(seconds=duration)))
            pass
Esempio n. 4
0
def _getassignmentjson(assignments, teacher, student):
    assignment_list = []
    for a in assignments:
        papers = Paper.objects.filter(assignment=a, owner=teacher.user)
        for p in papers:
            try:
                questionseq = pickle.loads(str(p.questionseq))
                question_set = Question.objects.filter(id__in=questionseq)
                stuanswer_set = getStuanswers(question_set, student)
                print stuanswer_set, "stuanswer"
                count = sum(1 for sa in stuanswer_set if sa.taked)
                print p.total
                print count, "count"

            except Exception, e:
                logger.error(e)
                logger.error(a)
                logger.error(p)
                break
            if count == p.total:
                retake = retake_option(stuanswer_set)
                print retake
                # for stud_ans in stuanswer_set:
                #     stud_ans.attempted_count += attempt_flag
                #     stud_ans.save()
                # retake_access = False
                #
                # else:
                if retake:
                    action = "<a href='/student/takeassignment/?paperid=%s'>\
                             <font color=black>ReTake</font></a>&nbsp;&nbsp;&nbsp;\
                             &nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;\
                             <a href='/student/summarize/?paperid=%s'>\
                             <font color=black>View</font></a>" % (str(
                        p.id), str(p.id))

                else:
                    action = "<a href='/student/summarize/?paperid=%s'>\
                            <font color=black>View</font></a>" % str(p.id)

            else:
                action = "<a href='/student/takeassignment/?paperid=%s'>\
                            <font color=black>Take</font></a>&nbsp;&nbsp;&nbsp;\
                            &nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;\
                            <a href='/student/summarize/?paperid=%s'>\
                            <font color=black>View</font></a>" % (str(
                    p.id), str(p.id))
            assignment_list.append([a, count, p, action])
Esempio n. 5
0
def student_checktime(request):
    student, res = getSpByRequest(request, None)
    startkey = "%s_%s" % (settings.EXAM_TIMEOUT_PREFIX, "start")
    totalkey = "%s_%s" % (settings.EXAM_TIMEOUT_PREFIX, "total")
    starttime = request.session[startkey]
    totaltime = request.session[totalkey]
    curtime = datetime.now()
    paperid = request.POST.get('paperid')
    saverequest = request.POST.get('save')
    if saverequest:
        try:
            p = Paper.objects.get(id=paperid)
            question_set = Question.objects.filter(
                paper=p, infocompleted=Question.ALLCOMPLETED)
            stuanswer_set = getStuanswers(question_set, student)
            logger.debug("stuanswer len: %s" % len(stuanswer_set))
            for stuanswer in stuanswer_set:
                timeleft = stuanswer.timeleft
                stuanswer.timeleft = timeleft - (curtime - starttime).seconds
                stuanswer.save()
        except Exception, e:
            logger.error("%s:can\'t save timeleft" % e)
        response_data = {'timeout': 'false'}
Esempio n. 6
0
@login_required
def student_submitpaper(request):
    student, res = getSpByRequest(request, None)
    response_data = {'state': 'failure'}
    try:
        paperid = request.POST.get('paperid')
        p = Paper.objects.get(id=int(paperid))
        questionseq = pickle.loads(str(p.questionseq))
    except Exception, e:
        logger.error(e)
        return HttpResponse('paper not found')

    try:
        question_set = Question.objects.filter(id__in=questionseq)
        stuanswer_set = getStuanswers(question_set, student)
    except Exception, e:
        response_data['state'] = e
        logger.error(e)
    if stuanswer_set:
        totalmark = 0
        for ans in stuanswer_set:
            totalmark += ans.mark
            ans.taked = True
            ans.save()
        if totalmark < p.passpoint:
            response_data['state'] = 'failed'
        else:
            response_data['state'] = 'passed'
    return HttpResponse(simplejson.dumps(response_data),
                        mimetype="application/json")