Esempio n. 1
0
def certificate_dashboard(request, course_key_string):
    """Certificate management dashboard for the support team."""

    course_key = get_course_key(course_key_string)
    course = get_course(course_key_string)
    if course is None:
        raise Http404

    # generate list of pending background tasks and filter the output
    task_types = ['certificate-generation', 'verified-certificate-generation']
    instructor_tasks = filter_instructor_task(
        get_running_instructor_tasks(course_key, task_types)
    )

    # Get list of tasks sorted by decreasing id
    instructor_tasks_history = []
    for task_type in task_types:
        instructor_tasks_history += list(filter_instructor_task(
            get_instructor_task_history(
            course_key, task_type=task_type, usage_key=None, student=None)
        ))
    instructor_tasks_history.sort(key=lambda x: -x.id)

    return render(request, 'backoffice/certificate.html', {
        'course': course,
        'certificate_base_url': settings.CERTIFICATE_BASE_URL,
        'instructor_tasks': instructor_tasks,
        'instructor_tasks_history': instructor_tasks_history,
    })
Esempio n. 2
0
def generate(request, course_id, problem_id):
    """ Submit 'generate_answers_distribution_report' task to celery.

    Args:
         course_id (str): The course id as string.
         problem_id (str): The problem id as string.

    Return:
         Redirect to Report Manager dashboard.
    """
    store = modulestore()
    course_key = get_course_key(course_id)
    problem = fetch_problem(store, course_key, problem_id)

    running_report_name = build_answers_distribution_report_name(problem)

    input_args = {'problem_id' : problem_id,
                  'running_report_name' : running_report_name}

    try:
        submit_generate_answers_distribution_report(request, course_key, input_args)
        return redirect('course-dashboard:reports-manager:dashboard', course_id)
    except AlreadyRunningError:
        messages.warning(request, _("A report on answers distribution is already running"))
        return redirect('course-dashboard:reports-manager:dashboard', course_id)
Esempio n. 3
0
def certificate_dashboard(request, course_key_string):
    """Certificate management dashboard for the support team."""

    course_key = get_course_key(course_key_string)
    course = get_course(course_key_string)
    if course is None:
        raise Http404

    # generate list of pending background tasks and filter the output
    task_types = ['certificate-generation', 'verified-certificate-generation']
    instructor_tasks = filter_instructor_task(
        get_running_instructor_tasks(course_key, task_types))

    # Get list of tasks sorted by decreasing id
    instructor_tasks_history = []
    for task_type in task_types:
        instructor_tasks_history += list(
            filter_instructor_task(
                get_instructor_task_history(course_key,
                                            task_type=task_type,
                                            usage_key=None,
                                            student=None)))
    instructor_tasks_history.sort(key=lambda x: -x.id)

    return render(
        request, 'backoffice/certificate.html', {
            'course': course,
            'certificates_directory': settings.CERTIFICATES_DIRECTORY_NAME,
            'instructor_tasks': instructor_tasks,
            'instructor_tasks_history': instructor_tasks_history,
        })
Esempio n. 4
0
def generate_certificate(request, course_key_string):
    """
    Submit the certificate-generation task to the instructor task api,
    then redirect to the certificate dashboard.
    """

    # TODO: only one function that return both the course and the course_key
    course_key = get_course_key(course_key_string)
    course = get_course(course_key_string)

    # this input dict as to be passed the celery task to operate
    # the instructor_task update api
    # see (get_task_completion_info lms/djangoapps/instructor_task/views.py)
    input_args = {'student' : '',
                  'problem_url' : '',
                  'email_id' : ''}

    if not get_university_attached_to_course(course):
        messages.warning(request, _("University doesn't exist"))
        return redirect('backoffice:certificate-dashboard', course_key_string)
    try:
        submit_generate_certificate(request, course_key, input_args)
        return redirect('backoffice:certificate-dashboard', course_key_string)
    except AlreadyRunningError:
        messages.warning(request, _("A certificate generation is already running"))
    return redirect('backoffice:certificate-dashboard', course_key_string)
Esempio n. 5
0
def generate(request, course_id, problem_id):
    """ Submit 'generate_answers_distribution_report' task to celery.

    Args:
         course_id (str): The course id as string.
         problem_id (str): The problem id as string.

    Return:
         Redirect to Report Manager dashboard.
    """
    store = modulestore()
    course_key = get_course_key(course_id)
    problem = fetch_problem(store, course_key, problem_id)

    running_report_name = build_answers_distribution_report_name(problem)

    input_args = {
        'problem_id': problem_id,
        'running_report_name': running_report_name
    }

    try:
        submit_generate_answers_distribution_report(request, course_key,
                                                    input_args)
        return redirect('course-dashboard:reports-manager:dashboard',
                        course_id)
    except AlreadyRunningError:
        messages.warning(
            request, _("A report on answers distribution is already running"))
        return redirect('course-dashboard:reports-manager:dashboard',
                        course_id)
Esempio n. 6
0
def download(request, course_key_string):
    course_key = get_course_key(course_key_string)
    file_path = tasks_api.get_file_path(course_key)
    if not file_path or not os.path.exists(file_path):
        raise Http404
    response = HttpResponse(open(file_path).read(), content_type='application/x-gzip')
    response['Content-Disposition'] = 'attachment; filename="openassessments.tar.gz"'
    return response
Esempio n. 7
0
def dashboard(request, course_id):
    """
    Will display two panels : the first one lists current processing reports,
    and the other lists all answer distribution reports corresponding to the course
    """
    course_key = get_course_key(course_id)
    answers_distribution_reports = get_reports_from_course(course_key)
    running_reports_generation = get_running_instructor_tasks(course_key, 'answers-distribution-report-generation')
    return render(request, 'course_dashboard/reports_manager/dashboard.html',
                  {"course_id": course_id,
                   "answers_distribution_reports" : answers_distribution_reports,
                   "running_reports_generation" : running_reports_generation})
Esempio n. 8
0
def generate_test_certificate(request, course_key_string):
    """
    Return the HttpResponse for downloading the certificate pdf file.
    """
    course_key = get_course_key(course_key_string)
    university = get_university_attached_to_course(course_key)
    if university:
        certificate = create_test_certificate(course_key)
        return certificate_file_response(certificate)
    else:
        messages.warning(request, _("University doesn't exist"))
        return redirect('backoffice:certificate-dashboard', course_key_string)
Esempio n. 9
0
def generate_test_certificate(request, course_key_string):
    """
    Return the HttpResponse for downloading the certificate pdf file.
    """
    course_key = get_course_key(course_key_string)
    university = get_university_attached_to_course(course_key)
    if university:
        certificate = create_test_certificate(course_key)
        return certificate_file_response(certificate)
    else:
        messages.warning(request, _("University doesn't exist"))
        return redirect('backoffice:certificate-dashboard', course_key_string)
Esempio n. 10
0
def download(request, course_id, answers_distribution_report):
    course_key = get_course_key(course_id)

    file_path = shared.get_path(ANSWERS_DISTRIBUTION_REPORTS_DIRECTORY,
                                course_key.org, course_key.course,
                                answers_distribution_report)

    if not file_path or not os.path.exists(file_path):
        raise Http404

    response = HttpResponse(open(file_path).read(), content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="{}"'.format(remove_accents(answers_distribution_report))
    return response
Esempio n. 11
0
def download(request, course_id, answers_distribution_report):
    course_key = get_course_key(course_id)

    file_path = shared.get_path(ANSWERS_DISTRIBUTION_REPORTS_DIRECTORY,
                                course_key.org, course_key.course,
                                answers_distribution_report)

    if not file_path or not os.path.exists(file_path):
        raise Http404

    response = HttpResponse(open(file_path).read(), content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="{}"'.format(
        remove_accents(answers_distribution_report))
    return response
Esempio n. 12
0
def generate_certificate(_xmodule_instance_args, _entry_id, course_id, _task_input, action_name):
    """
    Generate a certificate for graduated students
    """

    course = modulestore().get_course(course_id, depth=2)
    course_key = get_course_key(str(course_id))
    course_display_name = unicode(course.display_name).encode('utf-8')
    university = University.objects.get(code=course.location.org)
    certificate_base_filename = "attestation_suivi_" + (course_id.to_deprecated_string().replace('/', '_')) + '_'

    start_time = time()
    start_date = datetime.now(UTC)
    status_interval = 1
    enrolled_students = get_enrolled_students(course_id)
    teachers = get_teachers_list_from_course(course_id.to_deprecated_string())
    task_progress = TaskProgress(action_name, enrolled_students.count(), start_time)

    # generate a test certificate
    test_certificate = create_test_certificate(course, course_key, university)

    all_status = {status.notpassing: 0,
                  status.error: 0,
                  status.downloadable: 0,
                  'test_certificate_filename' : test_certificate.filename}

    for count, student in enumerate(enrolled_students):
        task_progress.attempted += 1
        if task_progress.attempted % status_interval == 0:
            task_progress.update_task_state(extra_meta=all_status)
        if certificate_status_for_student(student, course_id)['status'] != status.downloadable:
            if university.certificate_logo:
                logo_path = os.path.join(university.certificate_logo.url, university.certificate_logo.path)
            else:
                logo_path = None
            student_status = generate_fun_certificate(student, course_id,
                                                  course_display_name, course,
                                                  teachers, university.name,
                                                  logo_path, certificate_base_filename,
                                                  False, False, False)
            if student_status:
                all_status[student_status] += 1
                task_progress.succeeded += 1
            else:
                task_progress.failed += 1
        else:
            all_status[status.downloadable] += 1

    return task_progress.update_task_state(extra_meta=all_status)
Esempio n. 13
0
def generate_test_certificate(request, course_key_string):
    """
    Return the HttpResponse for downloading the certificate pdf file.
    """

    # TODO: only one function that return both the course and the course_key
    course_key = get_course_key(course_key_string)
    course = get_course(course_key_string)

    university = get_university_attached_to_course(course)
    messages.warning(request, _("University doesn't exist"))
    if university is not None:
        certificate = create_test_certificate(course, course_key, university)
        return certificate_file_response(certificate)
    else:
        return redirect('backoffice:certificate-dashboard', course_key_string)
Esempio n. 14
0
def generate_certificate(request, course_key_string):
    """
    Submit the certificate-generation task to the instructor task api,
    then redirect to the certificate dashboard.
    """
    course_key = get_course_key(course_key_string)

    if not get_university_attached_to_course(course_key):
        messages.warning(request, _("University doesn't exist"))
        return redirect('backoffice:certificate-dashboard', course_key_string)
    try:
        submit_generate_certificate(request, course_key)
        return redirect('backoffice:certificate-dashboard', course_key_string)
    except AlreadyRunningError:
        messages.warning(request, _("A certificate generation is already running"))
    return redirect('backoffice:certificate-dashboard', course_key_string)
Esempio n. 15
0
def dashboard(request, course_id):
    """
    Will display two panels : the first one lists current processing reports,
    and the other lists all answer distribution reports corresponding to the course
    """
    course_key = get_course_key(course_id)
    answers_distribution_reports = get_reports_from_course(course_key)
    running_reports_generation = get_running_instructor_tasks(
        course_key, ['answers-distribution-report-generation'])
    return render(
        request, 'course_dashboard/reports_manager/dashboard.html', {
            "course_id": course_id,
            "active_tab": "reports",
            "answers_distribution_reports": answers_distribution_reports,
            "running_reports_generation": running_reports_generation
        })
    def handle(self, *args, **options):
        try:
            course_key_string, username, grade = args
        except ValueError:
            raise CommandError("Wrong arguments ; usage: 'course-key-string' 'user' 'grade'")

        try:
            student = User.objects.get(username=username)
        except django.contrib.auth.models.DoesNotExist:
            raise CommandError("Unknown student username: {}".format(username))

        try:
            grade = float(grade)
        except ValueError:
            raise CommandError("Grade should be a float, not: {}".format(grade))


        course_key = get_course_key(course_key_string)
        course = modulestore().get_course(course_key, depth=2)

        status = generate_fun_verified_certificate(student, course, grade)
        print("User : {} -- status : {}".format(student.username, status))
Esempio n. 17
0
def certificate_dashboard(request, course_key_string):
    """
    Will display
    . Two panels, pending and previous certificate generation tasks.
    . Two buttons : one two generate a test certificate and the other to trigger a certificate generation task.
    """

    # TODO: only one function that return both the course and the course_key
    course_key = get_course_key(course_key_string)
    course = get_course(course_key_string)

    # generate list of pending background tasks and filter the output
    instructor_tasks = filter_instructor_task(get_running_instructor_tasks(course_key, task_type='certificate-generation'))
    instructor_tasks_history = filter_instructor_task(get_instructor_task_history(course_key, task_type='certificate-generation',
                                                                                  usage_key=None, student=None))

    return render(request, 'backoffice/certificate.html', {
            'course': course,
            'certificate_base_url' : settings.CERTIFICATE_BASE_URL,
            'instructor_tasks' : instructor_tasks,
            'instructor_tasks_history' : instructor_tasks_history,
        })
Esempio n. 18
0
def generate(request, course_id, problem_module_id):
    """
    launch the generate_answers_distribution_report task and redirect to  dashboard
    """

    course_key = get_course_key(course_id)

    ## Get the name of the problem module and of its ancestors
    store = modulestore()
    problem_module = get_problem_module(course_id, problem_module_id)
    add_ancestors_names_to_problem_module(problem_module[0], store)
    running_report_name = u"{}-{}-{}/{}.csv".format(course_key.org,
                                                    course_key.course,
                                                    problem_module[0].ancestors_names['great_grandparent'][:100],
                                                    problem_module[0].display_name[:100])

    input_args = {'problem_module_id' : problem_module_id, 'running_report_name' : running_report_name}

    try:
        submit_generate_answers_distribution_report(request, course_key, input_args)
        return redirect('course-dashboard:answers-distribution-reports-manager:dashboard', course_id)
    except AlreadyRunningError:
        messages.warning(request, _("A report on answers distribution is already running"))
        return redirect('course-dashboard:answers-distribution', course_id)
Esempio n. 19
0
def prepare(request, course_key_string):
    course_key = get_course_key(course_key_string)
    if not tasks_api.is_task_running(course_key):
        tasks_api.submit_preparation_task(request, course_key)
    return redirect('backoffice:ora2-submissions:status',
                    course_key_string=course_key_string)