Exemplo n.º 1
0
def transcript(request, course_slug=None):
    user = request.user
    course_list = user.courses_as_student.all()
    course_transcript = None
    template_name = 'courses/transcript.html'
    if course_slug:
        template_name = 'courses/transcript_course.html'
        course_transcript = get_object_or_404(Course, slug=course_slug)
        course_list = course_list.filter(slug=course_slug)
    courses_info = []
    use_old_calculus = settings.COURSES_USING_OLD_TRANSCRIPT
    for course in course_list:
        cert_url = ''
        total_mark, units_info = get_course_mark(course, user)
        award = None
        passed = False
        if course.threshold is not None and float(
                course.threshold) <= total_mark:
            passed = True
            cert_url = settings.CERTIFICATE_URL % {
                'courseid': course.id,
                'email': user.email.lower()
            }
            badge = course.completion_badge
            if badge is not None:
                try:
                    award = Award.objects.get(badge=badge, user=user)
                except Award.DoesNotExist:
                    award = Award(badge=badge, user=user)
                    award.save()
        total_weight_unnormalized, unit_course_counter, course_units = get_course_intermediate_calculations(
            course)

        units_info_ordered = []
        for unit in course_units:
            uinfo = next((u for u in units_info if u['unit_id'] == unit.pk), {
                'relative_mark': 0,
                'mark': 0
            })
            uinfo['unit'] = unit
            normalized_unit_weight = normalize_unit_weight(
                unit, unit_course_counter, total_weight_unnormalized)
            uinfo['normalized_weight'] = normalized_unit_weight
            unit_class = get_unit_badge_class(unit)
            uinfo['badge_class'] = unit_class
            units_info_ordered.append(uinfo)
        courses_info.append({
            'course': course,
            'units_info': units_info_ordered,
            'mark': total_mark,
            'award': award,
            'passed': passed,
            'cert_url': cert_url,
            'use_old_calculus': use_old_calculus,
        })
    return render_to_response(template_name, {
        'courses_info': courses_info,
        'course_transcript': course_transcript,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
def transcript(request):
    """
    Transcript is the main view of the user progress, here the user is show with
    the overall progress per course, quallifications and badges if he obtained
    any. We also give the access to the certification.

    :permissions: login
    :context: course, units_info, mark, award, passed, cert_url, use_old_calculus

    .. versionadded:: 0.1
    """
    course_list = request.user.courses_as_student.all()
    courses_info = []
    cert_url = ''
    for course in course_list:
        use_old_calculus = False
        if course.slug in settings.COURSES_USING_OLD_TRANSCRIPT:
            use_old_calculus = True
        total_mark, units_info = calculate_course_mark(course, request.user)
        award = None
        passed = False
        if course.threshold is not None and float(
                course.threshold) <= total_mark:
            passed = True
            cert_url = settings.CERTIFICATE_URL % {
                'courseid': course.id,
                'email': request.user.email.lower()
            }
            badge = course.completion_badge
            if badge is not None:
                try:
                    award = Award.objects.get(badge=badge, user=request.user)
                except Award.DoesNotExist:
                    award = Award(badge=badge, user=request.user)
                    award.save()
        for idx, uinfo in enumerate(units_info):
            unit_class = get_unit_badge_class(uinfo['unit'])
            units_info[idx]['badge_class'] = unit_class
            if (not use_old_calculus and uinfo['unit'].unittype == 'n') or \
                    not units_info[idx]['use_unit_in_total']:
                units_info[idx]['hide'] = True
        courses_info.append({
            'course': course,
            'units_info': units_info,
            'mark': total_mark,
            'award': award,
            'passed': passed,
            'cert_url': cert_url,
            'use_old_calculus': use_old_calculus,
        })
    return render_to_response('courses/transcript.html', {
        'courses_info': courses_info,
    },
                              context_instance=RequestContext(request))