def index(request): user = request.user contributor_visible_states = ['prepared', 'editor_approved', 'approved', 'in_evaluation', 'evaluated', 'reviewed', 'published'] own_courses = Course.objects.filter(contributions__contributor=user, state__in=contributor_visible_states) represented_users = user.represented_users.all() delegated_courses = Course.objects.exclude(id__in=own_courses).filter(contributions__can_edit=True, contributions__contributor__in=represented_users, state__in=contributor_visible_states) all_courses = list(own_courses) + list(delegated_courses) all_courses.sort(key=lambda course: list(STATES_ORDERED.keys()).index(course.state)) for course in all_courses: if course.state == 'published': course.avg_grade, course.avg_deviation = calculate_average_grades_and_deviation(course) semesters = Semester.objects.all() semester_list = [dict( semester_name=semester.name, id=semester.id, is_active_semester=semester.is_active_semester, courses=[course for course in all_courses if course.semester_id == semester.id] ) for semester in semesters] template_data = dict(semester_list=semester_list, delegated_courses=delegated_courses) return render(request, "contributor_index.html", template_data)
def index(request): user = request.user contributor_visible_states = ['prepared', 'editor_approved', 'approved', 'in_evaluation', 'evaluated', 'reviewed', 'published'] own_courses = Course.objects.filter(contributions__contributor=user, state__in=contributor_visible_states) represented_users = user.represented_users.all() delegated_courses = Course.objects.exclude(id__in=own_courses).filter(contributions__can_edit=True, contributions__contributor__in=represented_users, state__in=contributor_visible_states) all_courses = list(own_courses) + list(delegated_courses) all_courses.sort(key=lambda course: list(STATES_ORDERED.keys()).index(course.state)) for course in all_courses: course.distribution = calculate_average_distribution(course) course.avg_grade = distribution_to_grade(course.distribution) semesters = Semester.objects.all() semester_list = [dict( semester_name=semester.name, id=semester.id, is_active_semester=semester.is_active_semester, courses=[course for course in all_courses if course.semester_id == semester.id] ) for semester in semesters] template_data = dict(semester_list=semester_list, delegated_courses=delegated_courses) return render(request, "contributor_index.html", template_data)
def semester_view(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) rewards_active = is_semester_activated(semester) grades_downloadable = are_grades_activated(semester) courses = get_courses_with_prefetched_data(semester) courses_by_state = [] for state in STATES_ORDERED.keys(): this_courses = [course for course in courses if course.state == state] courses_by_state.append((state, this_courses)) # semester statistics (per degree) class Stats: def __init__(self): self.num_enrollments_in_evaluation = 0 self.num_votes = 0 self.num_courses_evaluated = 0 self.num_courses = 0 self.num_comments = 0 self.num_comments_reviewed = 0 self.first_start = datetime.date(9999, 1, 1) self.last_end = datetime.date(2000, 1, 1) degree_stats = defaultdict(Stats) total_stats = Stats() for course in courses: if course.is_single_result(): continue degrees = course.degrees.all() stats_objects = [degree_stats[degree] for degree in degrees] stats_objects += [total_stats] for stats in stats_objects: if course.state in ['inEvaluation', 'evaluated', 'reviewed', 'published']: stats.num_enrollments_in_evaluation += course.num_participants stats.num_votes += course.num_voters stats.num_comments += course.num_textanswers stats.num_comments_reviewed += course.num_reviewed_textanswers if course.state in ['evaluated', 'reviewed', 'published']: stats.num_courses_evaluated += 1 stats.num_courses += 1 stats.first_start = min(stats.first_start, course.vote_start_date) stats.last_end = max(stats.last_end, course.vote_end_date) degree_stats = OrderedDict(sorted(degree_stats.items(), key=lambda x: x[0].order)) degree_stats['total'] = total_stats template_data = dict( semester=semester, courses_by_state=courses_by_state, disable_breadcrumb_semester=True, disable_if_archived="disabled" if semester.is_archived else "", rewards_active=rewards_active, grades_downloadable=grades_downloadable, num_courses=len(courses), degree_stats=degree_stats ) return render(request, "staff_semester_view.html", template_data)
def semester_view(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) courses = semester.course_set.all() courses_by_state = [] for state in STATES_ORDERED.keys(): this_courses = [course for course in courses if course.state == state] courses_by_state.append((state, this_courses)) return render_to_response("fsr_semester_view.html", dict(semester=semester, courses_by_state=courses_by_state), context_instance=RequestContext(request))
def index(request): user = request.user sorter = lambda course: STATES_ORDERED.keys().index(course.state) own_courses = list(Course.objects.filter(assignments__lecturer=user, state__in=['new', 'prepared', 'lecturerApproved', 'approved', 'inEvaluation'])) own_courses.sort(key=sorter) proxied_courses = list(Course.objects.filter(assignments__lecturer__in=user.proxied_users.all(), state__in=['new', 'prepared', 'lecturerApproved', 'approved', 'inEvaluation'])) proxied_courses.sort(key=sorter) return render_to_response("lecturer_index.html", dict(own_courses=own_courses, proxied_courses=proxied_courses), context_instance=RequestContext(request))
def semester_view(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) rewards_active = is_semester_activated(semester) grades_downloadable = are_grades_activated(semester) courses = get_courses_with_prefetched_data(semester) courses_by_state = [] for state in STATES_ORDERED.keys(): this_courses = [course for course in courses if course.state == state] courses_by_state.append((state, this_courses)) # semester statistics num_enrollments_in_evaluation = 0 num_votes = 0 num_courses_evaluated = 0 num_comments = 0 num_comments_reviewed = 0 first_start = datetime.date(9999, 1, 1) last_end = datetime.date(2000, 1, 1) for course in courses: if course.state in [ 'inEvaluation', 'evaluated', 'reviewed', 'published' ]: num_enrollments_in_evaluation += course.num_participants num_votes += course.num_voters num_comments += course.num_textanswers num_comments_reviewed += course.num_reviewed_textanswers if course.state in ['evaluated', 'reviewed', 'published']: num_courses_evaluated += 1 first_start = min(first_start, course.vote_start_date) last_end = max(last_end, course.vote_end_date) template_data = dict( semester=semester, courses_by_state=courses_by_state, disable_breadcrumb_semester=True, disable_if_archived="disabled" if semester.is_archived else "", rewards_active=rewards_active, grades_downloadable=grades_downloadable, num_enrollments_in_evaluation=num_enrollments_in_evaluation, num_votes=num_votes, first_start=first_start, last_end=last_end, num_courses=len(courses), num_courses_evaluated=num_courses_evaluated, num_comments=num_comments, num_comments_reviewed=num_comments_reviewed, ) return render(request, "staff_semester_view.html", template_data)
def semester_view(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) try: tab = int(request.GET.get('tab', '1')) except: tab = 1 courses = semester.course_set.all() courses_by_state = [] for state in STATES_ORDERED.keys(): this_courses = [course for course in courses if course.state == state] courses_by_state.append((state, this_courses)) return render_to_response("fsr_semester_view.html", dict(semester=semester, courses_by_state=courses_by_state, disable_breadcrumb_semester=True, tab=tab), context_instance=RequestContext(request))
def index(request): user = request.user show_delegated = get_parameter_from_url_or_session(request, "show_delegated", True) contributor_visible_states = [ 'prepared', 'editor_approved', 'approved', 'in_evaluation', 'evaluated', 'reviewed', 'published' ] own_evaluations = Evaluation.objects.filter( contributions__contributor=user, state__in=contributor_visible_states) displayed_evaluations = list(own_evaluations) if show_delegated: represented_users = user.represented_users.all() delegated_evaluations = Evaluation.objects.exclude( id__in=own_evaluations).filter( contributions__can_edit=True, contributions__contributor__in=represented_users, state__in=contributor_visible_states) for evaluation in delegated_evaluations: evaluation.delegated_evaluation = True displayed_evaluations += list(delegated_evaluations) displayed_evaluations.sort(key=lambda evaluation: list(STATES_ORDERED.keys( )).index(evaluation.state)) delegate_selection_form = DelegateSelectionForm() for evaluation in displayed_evaluations: evaluation.distribution = calculate_average_distribution(evaluation) evaluation.avg_grade = distribution_to_grade(evaluation.distribution) semesters = Semester.objects.all() semester_list = [ dict(semester_name=semester.name, id=semester.id, is_active_semester=semester.is_active_semester, evaluations=[ evaluation for evaluation in displayed_evaluations if evaluation.course.semester_id == semester.id ]) for semester in semesters ] template_data = dict( semester_list=semester_list, show_delegated=show_delegated, delegate_selection_form=delegate_selection_form, ) return render(request, "contributor_index.html", template_data)
def index(request): user = request.user sorter = lambda course: STATES_ORDERED.keys().index(course.state) own_courses = list(set(Course.objects.filter(contributions__can_edit=True, contributions__contributor=user, state__in=['prepared', 'lecturerApproved', 'approved', 'inEvaluation', 'evaluated', 'reviewed']))) own_courses.sort(key=sorter) represented_userprofiles = user.represented_users.all() represented_users = [profile.user for profile in represented_userprofiles] delegated_courses = list(set(Course.objects.exclude(id__in=Course.objects.filter(contributions__can_edit=True, contributions__contributor=user)).filter(contributions__can_edit=True, contributions__contributor__in=represented_users, state__in=['prepared', 'lecturerApproved', 'approved', 'inEvaluation', 'evaluated', 'reviewed']))) delegated_courses.sort(key=sorter) return render_to_response("contributor_index.html", dict(own_courses=own_courses, delegated_courses=delegated_courses), context_instance=RequestContext(request))
def semester_view(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) rewards_active = is_semester_activated(semester) grades_downloadable = are_grades_activated(semester) courses = get_courses_with_prefetched_data(semester) courses_by_state = [] for state in STATES_ORDERED.keys(): this_courses = [course for course in courses if course.state == state] courses_by_state.append((state, this_courses)) # semester statistics num_enrollments_in_evaluation = 0 num_votes = 0 num_courses_evaluated = 0 num_comments = 0 num_comments_reviewed = 0 first_start = datetime.date(9999, 1, 1) last_end = datetime.date(2000, 1, 1) for course in courses: if course.state in ['inEvaluation', 'evaluated', 'reviewed', 'published']: num_enrollments_in_evaluation += course.num_participants num_votes += course.num_voters num_comments += course.num_textanswers num_comments_reviewed += course.num_reviewed_textanswers if course.state in ['evaluated', 'reviewed', 'published']: num_courses_evaluated += 1 first_start = min(first_start, course.vote_start_date) last_end = max(last_end, course.vote_end_date) template_data = dict( semester=semester, courses_by_state=courses_by_state, disable_breadcrumb_semester=True, disable_if_archived="disabled" if semester.is_archived else "", rewards_active=rewards_active, grades_downloadable=grades_downloadable, num_enrollments_in_evaluation=num_enrollments_in_evaluation, num_votes=num_votes, first_start=first_start, last_end=last_end, num_courses=len(courses), num_courses_evaluated=num_courses_evaluated, num_comments=num_comments, num_comments_reviewed=num_comments_reviewed, ) return render(request, "staff_semester_view.html", template_data)
def semester_view(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) try: tab = int(get_tab(request)) except ValueError: tab = 1 rewards_active = is_semester_activated(semester) courses = semester.course_set.all() courses_by_state = [] for state in STATES_ORDERED.keys(): this_courses = [course for course in courses if course.state == state] courses_by_state.append((state, this_courses)) return render_to_response("fsr_semester_view.html", dict(semester=semester, courses_by_state=courses_by_state, disable_breadcrumb_semester=True, tab=tab, rewards_active=rewards_active), context_instance=RequestContext(request))
def index(request): user = request.user sorter = lambda course: STATES_ORDERED.keys().index(course.state) own_courses = list(set(Course.objects.filter(contributions__can_edit=True, contributions__contributor=user, state__in=['prepared', 'lecturerApproved', 'approved', 'inEvaluation', 'evaluated', 'reviewed', 'published']))) represented_userprofiles = user.represented_users.all() represented_users = [profile.user for profile in represented_userprofiles] delegated_courses = list(set(Course.objects.exclude(id__in=Course.objects.filter(contributions__can_edit=True, contributions__contributor=user)).filter(contributions__can_edit=True, contributions__contributor__in=represented_users, state__in=['prepared', 'lecturerApproved', 'approved', 'inEvaluation', 'evaluated', 'reviewed', 'published']))) all_courses = own_courses + delegated_courses all_courses.sort(key=sorter) semesters = Semester.objects.all() semester_list = [dict(semester_name=semester.name, id=semester.id, courses=[course for course in all_courses if course.semester_id == semester.id]) for semester in semesters] return render_to_response("contributor_index.html", dict(semester_list=semester_list, delegated_courses=delegated_courses), context_instance=RequestContext(request))
def statename(state): return STATES_ORDERED.get(state)