def METHOD_NAME(request, statuses=None):
    user = request.user
    if not user.is_staff:
        raise PermissionDenied
    if statuses:
        user_statuses = []
        for status_id in statuses.split('_'):
            if status_id:
                user_statuses.append(get_object_or_404(UserStatus, id=int(status_id)))
        profiles = UserProfile.objects.filter(user_status__in=user_statuses).all()
    elif user.is_staff and 'from_staff' in request.GET and 'user_ids_send_mail_counter' in request.session:
        student_ids = request.session['user_ids_send_mail_' + request.GET['from_staff']]
        profiles = UserProfile.objects.filter(user_id__in=student_ids).all()
    students = set()
    for profile in profiles:
        students.add(profile.user)
    marks = StudentCourseMark.objects.filter(student__in=students).order_by('course')
    courses = set()
    for mark in marks:
        courses.add(mark.course)
    students_with_marks = []
    for student in students:
        entry = {}
        marks_for_student = []
        entry['name'] = student.get_full_name()
        entry['url'] = student.get_absolute_url()
        for course in courses:
            if course.get_user_group(student):
                if marks.filter(student=student, course=course).exclude(mark__isnull=True):
                    mark = marks.get(student=student, course=course).mark
                    mark = mark.name, mark.name_int
                else:
                    mark = '--', '-1'
            else:
                mark = ('--', '-2')
            marks_for_student.append(mark)
        entry['marks'] = marks_for_student
        students_with_marks.append(entry)
    context = {
        'students': students_with_marks,
        'courses': courses,
    }
    return render(request, 'gradebook.html', context)