Beispiel #1
0
def course_participant_import(request, semester_id, course_id):
    course = get_object_or_404(Course, id=course_id)
    semester = get_object_or_404(Semester, id=semester_id)
    raise_permission_denied_if_archived(course)

    form = UserImportForm(request.POST or None, request.FILES or None)

    if form.is_valid():
        operation = request.POST.get('operation')
        if operation not in ('test', 'import'):
            raise SuspiciousOperation("Invalid POST operation")

        # Extract data from form.
        excel_file = form.cleaned_data['excel_file']

        test_run = operation == 'test'

        # Parse table.
        imported_users = UserImporter.process(request, excel_file, test_run)

        # Test run, or an error occurred while parsing -> stay and display error.
        if test_run or not imported_users:
            return render(request, "staff_course_participant_import.html", dict(course=course, form=form))
        else:
            # Add users to course participants. * converts list into parameters.
            course.participants.add(*imported_users)
            messages.success(request, "%d Participants added to course %s" % (len(imported_users), course.name))
            return redirect('staff:semester_view', semester_id)
    else:
        return render(request, "staff_course_participant_import.html", dict(course=course, form=form, semester=semester))
Beispiel #2
0
def course_import_participants(request, semester_id, course_id):
    course = get_object_or_404(Course, id=course_id)
    semester = get_object_or_404(Semester, id=semester_id)
    raise_permission_denied_if_archived(course)

    form = UserImportForm(request.POST or None, request.FILES or None)

    if form.is_valid():
        operation = request.POST.get('operation')
        if operation not in ('test', 'import'):
            raise SuspiciousOperation("Invalid POST operation")

        # Extract data from form.
        excel_file = form.cleaned_data['excel_file']

        test_run = operation == 'test'

        # Parse table.
        imported_users = UserImporter.process(request, excel_file, test_run)

        # Test run, or an error occurred while parsing -> stay and display error.
        if test_run or not imported_users:
            return render(request, "staff_import_participants.html",
                          dict(course=course, form=form))
        else:
            # Add users to course participants. * converts list into parameters.
            course.participants.add(*imported_users)
            messages.success(
                request, "%d Participants added to course %s" %
                (len(imported_users), course.name))
            return redirect('staff:semester_view', semester_id)
    else:
        return render(request, "staff_import_participants.html",
                      dict(course=course, form=form, semester=semester))
Beispiel #3
0
def user_import(request):
    form = UserImportForm(request.POST or None, request.FILES or None)
    operation = request.POST.get('operation')

    if form.is_valid():
        if operation not in ('test', 'import'):
            raise SuspiciousOperation("Invalid POST operation")

        test_run = operation == 'test'
        excel_file = form.cleaned_data['excel_file']
        UserImporter.process(request, excel_file, test_run)
        if test_run:
            return render(request, "staff_user_import.html", dict(form=form))
        return redirect('staff:user_index')
    else:
        return render(request, "staff_user_import.html", dict(form=form))
Beispiel #4
0
def user_import(request):
    form = UserImportForm(request.POST or None, request.FILES or None)
    operation = request.POST.get("operation")

    if form.is_valid():
        if operation not in ("test", "import"):
            raise PermissionDenied

        test_run = operation == "test"
        excel_file = form.cleaned_data["excel_file"]
        UserImporter.process(request, excel_file, test_run)
        if test_run:
            return render(request, "staff_user_import.html", dict(form=form))
        return redirect("staff:user_index")
    else:
        return render(request, "staff_user_import.html", dict(form=form))
Beispiel #5
0
def user_import(request):
    form = UserImportForm(request.POST or None, request.FILES or None)
    operation = request.POST.get('operation')

    if form.is_valid():
        if operation not in ('test', 'import'):
            raise SuspiciousOperation("Invalid POST operation")

        test_run = operation == 'test'
        excel_file = form.cleaned_data['excel_file']
        UserImporter.process(request, excel_file, test_run)
        if test_run:
            return render(request, "staff_user_import.html", dict(form=form))
        return redirect('staff:user_index')
    else:
        return render(request, "staff_user_import.html", dict(form=form))
Beispiel #6
0
def user_import(request):
    form = UserImportForm(request.POST or None, request.FILES or None)
    operation = request.POST.get('operation')

    if form.is_valid():
        if operation not in ('test', 'import'):
            raise PermissionDenied

        test_run = operation == 'test'
        excel_file = form.cleaned_data['excel_file']
        UserImporter.process(request, excel_file, test_run)
        if test_run:
            return render(request, "staff_user_import.html", dict(form=form))
        return redirect('evap.staff.views.user_index')       
    else:
        return render(request, "staff_user_import.html", dict(form=form))