def get_contest_problems(request): if request.method != 'POST': return HttpResponseForbidden() lang = request.user.get_profile().language course = get_object_or_404(Course, id=request.POST['course_id']) if not course.user_can_edit_course(request.user): return HttpResponseForbidden() contest_id = request.POST['contest_id'] is_error = False error = '' problems = [] got_info, contest_info = get_contest_info(contest_id, lang=lang) if "You're not allowed to view this contest." in contest_info: return HttpResponse(json.dumps({'problems': problems, 'is_error': True, 'error': _(u"net_prav_na_kontest")}), content_type="application/json") problem_req = requests.get(PROBLEMS_API.format(lang=lang, cont_id=str(contest_id)), headers=HEADERS) problem_req = problem_req.json() if 'error' in problem_req: is_error = True if 'IndexOutOfBoundsException' in problem_req['error']['name']: error = _(u'kontesta_ne_sushestvuet') else: error = _(u'oshibka_kontesta') + ' ' + problem_req['error']['message'] else: problems = problem_req['result']['problems'] contest_info_problems = contest_info['problems'] if 'endTime' in contest_info: deadline_msk = datetime.datetime.strptime(contest_info['endTime'][:-9], '%Y-%m-%dT%H:%M:%S') contest_info_deadline = convert_datetime(deadline_msk, settings.CONTEST_TIME_ZONE, request.user.get_profile().time_zone) contest_info_deadline = contest_info_deadline.strftime('%Y,%m,%d,%H,%M') else: contest_info_deadline = None problems = problems + contest_info_problems + [{'deadline': contest_info_deadline}] return HttpResponse(json.dumps({'problems': problems, 'is_error': is_error, 'error': error}), content_type="application/json")
def get_contest_problems(request): if request.method != 'POST': return HttpResponseForbidden() lang = request.user.profile.language course = get_object_or_404(Course, id=request.POST['course_id']) if not course.user_can_edit_course(request.user): return HttpResponseForbidden() contest_id = request.POST['contest_id'] is_error = False error = '' problems = [] got_info, contest_info = get_contest_info(contest_id, lang=lang) if "You're not allowed to view this contest." in contest_info: return HttpResponse(json.dumps({'problems': problems, 'is_error': True, 'error': _(u"net_prav_na_kontest")}), content_type="application/json") problem_req = requests.get(PROBLEMS_API.format(lang=lang, cont_id=str(contest_id)), headers=HEADERS) problem_req = problem_req.json() if 'error' in problem_req: is_error = True if 'IndexOutOfBoundsException' in problem_req['error']['name']: error = _(u'kontesta_ne_sushestvuet') else: error = _(u'oshibka_kontesta') + ' ' + problem_req['error']['message'] else: problems = problem_req['result']['problems'] contest_info_problems = contest_info['problems'] if 'endTime' in contest_info: deadline_msk = datetime.datetime.strptime(contest_info['endTime'][:-9], '%Y-%m-%dT%H:%M:%S') contest_info_deadline = convert_datetime(deadline_msk, settings.CONTEST_TIME_ZONE, request.user.profile.time_zone) contest_info_deadline = contest_info_deadline.strftime('%Y,%m,%d,%H,%M') else: contest_info_deadline = None problems = problems + contest_info_problems + [{'deadline': contest_info_deadline}] return HttpResponse(json.dumps({'problems': problems, 'is_error': is_error, 'error': error}), content_type="application/json")
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
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