Example #1
0
    def test_staff_users(self, _is_course_passed):
        self.user.is_staff = True
        self.user.save()

        self.assertTrue(
            utils.is_student_pass(self.user, unicode(self.course.id)),
            msg='Should return True for Staff users regardless of their mark')
Example #2
0
 def test_using_cached_is_course_passed(self, cached_is_course_passed):
     """
     Should use the cached grade function.
     """
     with patch('edraak_certificates.utils.is_certificate_allowed',
                return_value=True):
         self.assertFalse(
             utils.is_student_pass(self.user, unicode(self.course.id)))
         self.assertEquals(1, cached_is_course_passed.call_count)
Example #3
0
def course_complete_status(request, course_id):
    """
    This view returns a json response describing if a user has
    completed (passed) a course.

    :param course_id: the id for the course to check
    """

    return JsonResponse({'complete': is_student_pass(request.user, course_id)})
Example #4
0
def preview(request, course_id):
    user = request.user

    course_key = locator.CourseLocator.from_string(course_id)
    course = modulestore().get_course(course_key)

    if is_student_pass(user, course_id):
        template = 'edraak_certificates/view.html'
    else:
        template = 'edraak_certificates/fail.html'

    return render_to_response(
        template,
        {
            'user': user,
            'cert_course':
            course,  # Course name is set to `cert_course` to avoid header design bug
        })
Example #5
0
def download_pdf(request, course_id):
    user = request.user

    course_key = locator.CourseLocator.from_string(course_id)
    course = modulestore().get_course(course_key)

    if not is_student_pass(user, course_id):
        raise Http404()

    pdf_file = generate_certificate(request, course)
    wrapper = FileWrapper(pdf_file)

    # `application/octet-stream` is to force download
    response = HttpResponse(wrapper, content_type='application/octet-stream')

    response['Content-Length'] = os.path.getsize(pdf_file.name)
    response[
        'Content-Disposition'] = "attachment; filename=Edraak-Certificate.pdf"

    return response
Example #6
0
def preview_png(request, course_id):
    user = request.user

    course_key = locator.CourseLocator.from_string(course_id)
    course = modulestore().get_course(course_key)

    if not is_student_pass(user, course_id):
        raise Http404()

    pdf_file = generate_certificate(request, course)
    image_file = NamedTemporaryFile(suffix='-cert.png')

    with Image(filename=pdf_file.name) as img:
        with img.clone() as i:
            i.save(filename=image_file.name)

    wrapper = FileWrapper(image_file)
    response = HttpResponse(wrapper, content_type='image/png')
    response['Content-Length'] = os.path.getsize(image_file.name)

    return response
Example #7
0
    def get_completed(self, obj):
        from edraak_certificates.utils import is_student_pass

        request = self.context['request']
        course_id_str = str(obj.id)
        return bool(is_student_pass(request.user, course_id_str))
Example #8
0
 def test_feature_enabled(self, _is_course_passed):
     self.assertFalse(
         utils.is_student_pass(self.user, unicode(self.course.id)),
         msg=
         'Should return True when the feature is enabled and the student have passed!'
     )
Example #9
0
 def test_feature_disabled(self, _is_course_passed):
     self.assertFalse(
         utils.is_student_pass(self.user, unicode(self.course.id)),
         msg='Should say student did not pass when the feature is disabled!'
     )
Example #10
0
def check_student_grades(request, course_id):
    return JsonResponse({
        'success': False,
        'error': is_student_pass(request.user, course_id)
    })