예제 #1
0
def attendance_list(request, course, group=None):
    user = request.user
    user_is_attended = False
    user_is_attended_special_course = False
    show_academ_users = request.session.get("%s_%s_show_academ_users" % (request.user.id, course.id), True)
    msk_time = convert_datetime(localtime(now()), user.get_profile().time_zone)

    course.can_edit = course.user_can_edit_course(user)
    if course.can_be_chosen_by_extern:
        course.groups.add(course.group_with_extern)

    if group:
        groups = [group]
    else:
        groups = course.groups.all().order_by('name')

    group_x_student_x_lessons = OrderedDict()
    group_x_lesson_list = {}
    group_inactive_lessons = {}
    default_teacher = {}

    academ_students = []

    for group in groups:
        group_x_lesson_list[group] = Lesson.objects.filter(course=course, group=group).order_by('position')
        group_inactive_lessons[group] = Lesson.objects.filter(course=course,
                                                              group=group,
                                                              date_starttime__gt=msk_time
                                                              ).order_by('position')
        active_lessons_count = len(group_x_lesson_list[group]) - len(group_inactive_lessons[group])

        students = group.students.filter(is_active=True)
        not_active_students = UserProfile.objects.filter(Q(user__in=group.students.filter(is_active=True)) &
                                                         (Q(user_status__tag='not_active') | Q(
                                                             user_status__tag='academic')))
        academ_students += [x.user for x in not_active_students]
        if not show_academ_users:
            students = set(students) - set(academ_students)

        students_x_lessons = {}

        for student in students:
            if user == student:
                user_is_attended = True
                user_is_attended_special_course = True

            not_visited_lessons = []
            for lssn in group_x_lesson_list[group][:active_lessons_count]:
                if student in lssn.not_visited_students.all():
                    not_visited_lessons.append(lssn)
            students_x_lessons[student] = not_visited_lessons, active_lessons_count - len(not_visited_lessons)

        group_x_student_x_lessons[group] = students_x_lessons

        try:
            default_teacher[group] = DefaultTeacher.objects.get(course=course, group=group).teacher
        except DefaultTeacher.DoesNotExist:
            default_teacher[group] = None
    group_x_student_information = OrderedDict()
    for group, students_x_lessons in group_x_student_x_lessons.iteritems():
        group_x_student_information.setdefault(group, [])

        for student in sorted(students_x_lessons.keys(),
                              key=lambda x: u"{0} {1}".format(x.last_name, x.first_name)):
            if user == student:
                user_is_attended = True
            elif not course.user_can_see_transcript(user, student):
                continue

            group_x_student_information[group].append((student,
                                                       students_x_lessons[student][0], students_x_lessons[student][1]))
    context = {
        'course': course,
        'group_information': group_x_student_information,
        'group_lessons': group_x_lesson_list,
        'group_inactive_lessons': group_inactive_lessons,
        'default_teacher': default_teacher,
        'user': user,
        'user_is_attended': user_is_attended,
        'user_is_attended_special_course': user_is_attended_special_course,
        'user_is_teacher': course.user_is_teacher(user),
        'visible_hide_button_users': len(academ_students),
        'show_academ_students': show_academ_users
    }

    return context
예제 #2
0
def tasklist_shad_cpp(request, course, seminar=None, group=None):
    user = request.user
    user_is_attended = False
    user_is_attended_special_course = False

    if seminar:
        groups = seminar.groups.all().order_by('name')
    else:
        groups = course.groups.all().order_by('name')

    course.can_edit = course.user_can_edit_course(user)
    if course.can_be_chosen_by_extern:
        course.groups.add(course.group_with_extern)

    if group:
        groups = [group]

    group_x_student_x_task_takens = OrderedDict()
    group_x_task_list = {}
    group_x_max_score = {}
    default_teacher = {}
    show_hidden_tasks = request.session.get(str(request.user.id) + '_' + str(course.id) + '_show_hidden_tasks', False)
    show_academ_users = request.session.get(str(request.user.id) + '_' + str(course.id) + '_show_academ_users', True)

    academ_students = []

    for group in groups:
        student_x_task_x_task_takens = {}

        tasks_for_groups = TaskGroupRelations.objects \
            .filter(task__course=course, group=group, deleted=False, task__parent_task=seminar) \
            .exclude(task__type=Task.TYPE_MATERIAL) \
            .distinct() \
            .order_by('position') \
            .prefetch_related('task__groups') \
            .select_related('task')

        if show_hidden_tasks:
            group_x_task_list[group] = [x.task for x in tasks_for_groups]
        else:
            group_x_task_list[group] = [x.task for x in tasks_for_groups if not x.task.is_hidden]

        group_x_max_score.setdefault(group, 0)

        for task in group_x_task_list[group]:

            if not task.is_hidden:
                if task.type == task.TYPE_SEMINAR:
                    group_x_max_score[group] += sum([x.score_max for x in task.children.all()])
                else:
                    group_x_max_score[group] += task.score_max
            if task.task_text is None:
                task.task_text = ''

        issues_students_in_group = Issue.objects \
            .filter(task__in=group_x_task_list[group], student__group__in=[group]) \
            .order_by('student')\
            .select_related("task")\
            .prefetch_related('task__groups', 'task')

        issues_x_student = defaultdict(list)
        for issue in issues_students_in_group.all():
            student_id = issue.student.id
            issues_x_student[student_id].append(issue)

        students = group.students.filter(is_active=True)
        not_active_students = UserProfile.objects.filter(
            Q(user__in=group.students.filter(is_active=True)) &
            (
                Q(user_status__tag='not_active') |
                Q(user_status__tag='academic')
            )
        )
        academ_students += [x.user for x in not_active_students]
        if not show_academ_users:
            students = set(students) - set(academ_students)

        for student in students:
            if user == student:
                user_is_attended = True
                user_is_attended_special_course = True

            student_task_takens = issues_x_student[student.id]

            task_x_task_taken = {}
            student_summ_scores = 0
            for task_taken in student_task_takens:
                task_x_task_taken[task_taken.task.id] = task_taken
                if not task_taken.task.is_hidden:
                    if task_taken.task.type == Task.TYPE_SEMINAR or \
                            task_taken.task.score_after_deadline or \
                            not (not task_taken.task.score_after_deadline and
                                 task_taken.is_status_accepted_after_deadline()):
                        student_summ_scores += task_taken.mark

            student_x_task_x_task_takens[student] = (task_x_task_taken, student_summ_scores)

        group_x_student_x_task_takens[group] = student_x_task_x_task_takens

        try:
            default_teacher[group] = DefaultTeacher.objects.get(course=course, group=group).teacher
        except DefaultTeacher.DoesNotExist:
            default_teacher[group] = None

    group_x_student_information = OrderedDict()
    for group, student_x_task_x_task_takens in group_x_student_x_task_takens.iteritems():
        group_x_student_information.setdefault(group, [])

        for student in sorted(student_x_task_x_task_takens.keys(),
                              key=lambda x: u"{0} {1}".format(x.last_name, x.first_name)):
            if user == student:
                user_is_attended = True
            elif not course.user_can_see_transcript(user, student):
                continue

            mark_id, course_mark, course_mark_int = get_course_mark(course, student)

            group_x_student_information[group].append((student,
                                                       student_x_task_x_task_takens[student][0],
                                                       student_x_task_x_task_takens[student][1],
                                                       mark_id,
                                                       course_mark,
                                                       course_mark_int))

    context = {
        'course': course,
        'course_mark_system_vals': course.mark_system.marks.all() if course.mark_system else None,
        'group_information': group_x_student_information,
        'group_tasks': group_x_task_list,
        'group_x_max_score': group_x_max_score,
        'default_teacher': default_teacher,

        'user': user,
        'user_is_attended': user_is_attended,
        'user_is_attended_special_course': user_is_attended_special_course,
        'user_is_teacher': course.user_is_teacher(user),

        'seminar': seminar,
        'visible_queue': course.user_can_see_queue(user),
        'visible_attendance_log': course.user_can_see_attendance_log(request.user),
        'visible_hide_button': Task.objects.filter(Q(course=course) & Q(is_hidden=True)).exists(),
        'show_hidden_tasks': show_hidden_tasks,
        'visible_hide_button_users': len(academ_students),
        'show_academ_users': show_academ_users

    }

    return context