示例#1
0
def gradeResult(request):
    render = {}
    grade = get_object_or_404(Grade, id = request.POST.get('grade'))
    resultdate = get_object_or_404(ResultDate, id = request.POST.get('resultdate'))
    render['grade'] = grade.id
    render['resultdate'] = resultdate.id
    if grade in request.user.grades.all():
        if not request.POST.get('send'):
            pupils = Pupil.objects.filter(grade = grade)
            results = []
            from math import pow
            for pupil in pupils:
                try:
                    result = Result.objects.get(resultdate = resultdate, pupil = pupil, subject = request.user.current_subject)
                    form = ResultForm(prefix = pupil.id, instance = result)
                except ObjectDoesNotExist:
                    form = ResultForm(prefix = pupil.id)
                sum = 0
                marks = Mark.objects.filter(lesson__date__range = (resultdate.startdate, resultdate.enddate), 
                                            pupil = pupil,
                                            lesson__subject = request.user.current_subject)
                for mark in marks:
                    if mark.mark:
                        sum += mark.mark
                if marks.__len__()<>0 and sum<>0:
                    sa = round(float(sum)/float(marks.__len__()), 3)
                else:
                    sa = 0
                results.append({'name': pupil.fi(), 'form': form, 'sa': sa})
            render['pupils'] = results
            return render_to_response('marks/teacher/gradeResult.html', render, context_instance = RequestContext(request))
        else:
            error = 0
            for pupil in Pupil.objects.filter(grade = grade):
                if request.POST.get('%d-mark' % pupil.id):
                    form = ResultForm(request.POST, prefix = pupil.id)
                    if form.is_valid():
                        try:
                            result = Result.objects.get(pupil = Pupil.objects.get(id = pupil.id),
                                                        resultdate = resultdate, subject = request.user.current_subject)
                        except ObjectDoesNotExist:
                            result = Result()
                        result.pupil = pupil
                        result.resultdate = resultdate
                        result.mark = form.cleaned_data['mark']
                        result.subject = request.user.current_subject
                        result.save()
                    else:
                        error = 1
            if error == 0:
                return HttpResponseRedirect('/marks/result/')
            else: 
                results = []
                pupils = Pupil.objects.filter(grade = grade)
                for pupil in pupils:
                    results.append({'name': pupil.fi(), 'form': ResultForm(request.POST, prefix = pupil.id)})
                render['pupils'] = results
                return render_to_response('marks/teacher/gradeResult.html', render, context_instance = RequestContext(request))
    else:
        return Http404
示例#2
0
    def get(self, request, request_result_id):
        '''
            Method for getting a Result based on the id provided.
        '''
        params = dict((key, val) for key, val in request.QUERY_PARAMS.iteritems())
        params['request_result_id'] = request_result_id
        form = ResultForm(params)

        if not form.is_valid():
            raise BadRequestException()

        return Response(form.submit(request))
示例#3
0
    def get(self, request, request_result_id):
        '''
            Method for getting a Result based on the id provided.
        '''
        params = dict(
            (key, val) for key, val in request.QUERY_PARAMS.iteritems())
        params['request_result_id'] = request_result_id
        form = ResultForm(params)

        if not form.is_valid():
            raise BadRequestException()

        return Response(form.submit(request))
示例#4
0
def show_result(request, url, sha1sum):
    """Show the result page - execute commands for the downloaded file."""
    form = ResultForm(request.POST or None)
    status = ""
    redirect = False
    if form.is_valid() and 'command' in request.POST:
        # Result form was submitted
        command = request.POST['command']
        if command == 'SHA1':
            # Validate SHA1 sum, output result
            if validate_sha1(url, sha1sum):
                status = "SHA1-summen er gyldig!"
            else:
                status = "SHA1-summen er IKKE gyldig, filen er korrumperet."
        if command == 'ACK':
            # Acknowledge receipt of document
            acknowledge_document(url)
            status = "Dokumentet er afsluttet, stiller tilbage ..."
            redirect = True
    else:
        # No ack or sha1 command submitted, just render
        # result page.
        """
        We fetch an example image if such exists.
        """
        print "POST: " + str(request.POST)
        """
        image = get_thumbnail_image(request.POST['template'])
        if image != "":
            image = TEMPLATE_URL + image
        else:
            image = "media/files/styling/trans.gif"
        """

    return render_to_response('new_result_page.html', {
        'url': url,
        'sha1sum': sha1sum,
        'status': status,
        'form': form,
        'redirect': redirect,
        'broker_url': BROKER_BASE_URL
    },
                              context_instance=RequestContext(request))
示例#5
0
    def post(self, request, debateid):
        form = ResultForm(request.POST)

        if form.is_valid():
            result = Debate.objects.get(id=debateid).result
            print form.cleaned_data
            result.ogsp1 = form.cleaned_data['ogsp1']
            result.ogsp2 = form.cleaned_data['ogsp2']
            result.oosp1 = form.cleaned_data['oosp1']
            result.oosp2 = form.cleaned_data['oosp1']
            result.cgsp1 = form.cleaned_data['cgsp1']
            result.cgsp2 = form.cleaned_data['cgsp2']
            result.cosp1 = form.cleaned_data['cosp1']
            result.cosp2 = form.cleaned_data['cosp2']

            result.add_positions_from_speaks()

        else:
            return HttpResponseBadRequest()

        result.full_clean()
        result.save()
        return HttpResponse(result.id)