def semester_reward_points(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) courses = Course.objects.filter(semester=semester) participants = set() for course in courses: for participant in course.participants.all(): if can_user_use_reward_points(participant.userprofile): participants.add(participant) participants = sorted(participants, key=attrgetter('last_name', 'first_name')) data = [] for participant in participants: number_of_courses = Course.objects.filter(semester=semester, participants=participant).count() number_of_courses_voted_for = Course.objects.filter(semester=semester, voters=participant).count() earned_reward_points = RewardPointGranting.objects.filter(semester=semester, user_profile=participant.userprofile).exists() data.append((participant, number_of_courses_voted_for, number_of_courses, earned_reward_points)) return render_to_response("rewards_semester_reward_points_view.html", dict(semester=semester, data=data, disable_breadcrumb_semester=False), context_instance=RequestContext(request))
def semester_reward_points(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) courses = Course.objects.filter(semester=semester) participants = set() for course in courses: for participant in course.participants.all(): if can_user_use_reward_points(participant): participants.add(participant) participants = sorted(participants, key=attrgetter('last_name', 'first_name')) data = [] for participant in participants: number_of_required_courses = Course.objects.filter( semester=semester, participants=participant, is_required_for_reward=True).count() number_of_required_courses_voted_for = Course.objects.filter( semester=semester, voters=participant, is_required_for_reward=True).count() number_of_optional_courses = Course.objects.filter( semester=semester, participants=participant, is_required_for_reward=False).count() number_of_optional_courses_voted_for = Course.objects.filter( semester=semester, voters=participant, is_required_for_reward=False).count() earned_reward_points = RewardPointGranting.objects.filter( semester=semester, user_profile=participant).exists() data.append( (participant, number_of_required_courses_voted_for, number_of_required_courses, number_of_optional_courses_voted_for, number_of_optional_courses, earned_reward_points)) template_data = dict(semester=semester, data=data, disable_breadcrumb_semester=False) return render(request, "rewards_semester_reward_points_view.html", template_data)
def semester_reward_points(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) courses = Course.objects.filter(semester=semester) participants = set() for course in courses: for participant in course.participants.all(): if can_user_use_reward_points(participant): participants.add(participant) participants = sorted(participants, key=attrgetter('last_name', 'first_name')) data = [] for participant in participants: number_of_required_courses = Course.objects.filter(semester=semester, participants=participant, is_required_for_reward=True).count() number_of_required_courses_voted_for = Course.objects.filter(semester=semester, voters=participant, is_required_for_reward=True).count() number_of_optional_courses = Course.objects.filter(semester=semester, participants=participant, is_required_for_reward=False).count() number_of_optional_courses_voted_for = Course.objects.filter(semester=semester, voters=participant, is_required_for_reward=False).count() earned_reward_points = RewardPointGranting.objects.filter(semester=semester, user_profile=participant).exists() data.append((participant, number_of_required_courses_voted_for, number_of_required_courses, number_of_optional_courses_voted_for, number_of_optional_courses, earned_reward_points)) template_data = dict(semester=semester, data=data, disable_breadcrumb_semester=False) return render(request, "rewards_semester_reward_points_view.html", template_data)
def semester_participation_export(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) participants = UserProfile.objects.filter(courses_participating_in__semester=semester).distinct().order_by("username") filename = "Evaluation-{}-{}_participation.csv".format(semester.name, get_language()) response = HttpResponse(content_type="text/csv") response["Content-Disposition"] = "attachment; filename=\"{}\"".format(filename) writer = csv.writer(response, delimiter=";") writer.writerow([_('Username'), _('Can use reward points'), _('#Required courses voted for'), _('#Required courses'), _('#Optional courses voted for'), _('#Optional courses'), _('Earned reward points')]) for participant in participants: number_of_required_courses = semester.course_set.filter(participants=participant, is_required_for_reward=True).count() number_of_required_courses_voted_for = semester.course_set.filter(voters=participant, is_required_for_reward=True).count() number_of_optional_courses = semester.course_set.filter(participants=participant, is_required_for_reward=False).count() number_of_optional_courses_voted_for = semester.course_set.filter(voters=participant, is_required_for_reward=False).count() earned_reward_points = RewardPointGranting.objects.filter(semester=semester, user_profile=participant).exists() writer.writerow([ participant.username, can_user_use_reward_points(participant), number_of_required_courses_voted_for, number_of_required_courses, number_of_optional_courses_voted_for, number_of_optional_courses, earned_reward_points ]) return response
def can_use_reward_points(user): return can_user_use_reward_points(user)
def check_user(user): from evap.rewards.tools import can_user_use_reward_points return can_user_use_reward_points(user)
def check_user(user): from evap.rewards.tools import can_user_use_reward_points if not user.is_authenticated(): return False return can_user_use_reward_points(UserProfile.get_for_user(user=user))