def forum_activity(request, course_id): threads = stats.forum_threads(course_id) threads_per_date = stats.forum_threads_per_day(threads) if request.GET.get("format") == "csv": return csv_response(["date", "threads"], threads_per_date, "forum-activity.csv") threads_per_day, threads_per_timestamp = formatted_dates(threads_per_date) total_threads = len(threads) most_active_thread = None least_active_thread = None most_active_user = stats.most_active_user(threads) if threads: most_active_thread = max(threads, key=lambda t: t["comments_count"]) least_active_thread = min(threads, key=lambda t: t["comments_count"]) return render(request, 'course_dashboard/forum-activity.html', { "active_tab": "forum_activity", "course_id": course_id, "threads_per_day": threads_per_day, "threads_per_timestamp": threads_per_timestamp, "most_active_thread": most_active_thread, "least_active_thread": least_active_thread, "total_threads": total_threads, "most_active_user": most_active_user, })
def users_without_proctoru_reservation(request, course_key_string): if not INSTALLED_PU: return HttpResponse('ProctorU xblock not installed') course = get_course(course_key_string) reports, last_update = get_mongo_reports(course.id) if "warn" in reports or "error" in reports: logger.error(reports) return HttpResponse('Something went wrong : {}'.format(reports)) # étudiants vérifiés - étudiants inscrit à PU (liste des étudiants avec un rapport) + étudiants sans résa # => ça donne : pas inscrit PU + sans résa verified_students = get_enrolled_verified_students( course.id).select_related("profile") students_not_registered_in_pu = set(verified_students) - set( students_registered_in_pu(reports)) cancelled_reservations = set(users_with_cancelled_reservations(reports)) enrolled_students_not_proctoru = set(students_not_registered_in_pu).union( cancelled_reservations) header = ("Name", "Username", "Email") rows = [(s.profile.name, s.username, s.email) for s in enrolled_students_not_proctoru] course_code = "{}_{}_{}".format(course.id.org, course.id.course, course.id.run) filename = 'export-verified-users-without-PU-reservations-{course}-{date}.csv'.format( date=datetime.datetime.now().strftime('%Y-%m-%d'), course=course_code) response = csv_response(header, rows, filename) return response
def enrolled_users(request, course_key_string): course = get_course(course_key_string) course_info = get_course_infos_or_404([course])[0] User.objects.select_related('profile') users = User.objects.filter( courseenrollment__course_id=course.id, courseenrollment__is_active=True).select_related('profile').order_by( 'username') search_pattern = request.GET.get('search') if search_pattern: users = users.filter( Q(username__icontains=search_pattern) | Q(email__icontains=search_pattern) | Q(profile__name__icontains=search_pattern)) if request.method == 'POST': # export as CSV course_code = "{}_{}_{}".format(course.id.org, course.id.course, course.id.run) filename = 'export-email-usernames-{course}-{date}'.format( date=datetime.datetime.now().strftime('%Y-%m-%d'), course=course_code) if search_pattern: filename += "-search_{}".format(search_pattern) filename += ".csv" csv_header = [ ugettext(u"Username"), ugettext(u"Name"), ugettext(u"Email") ] rows = [(u.username, u.profile.name, u.email) for u in users] response = csv_response(csv_header, rows, filename) return response else: paginator = Paginator(users, request=request, per_page=100) try: users = paginator.page(request.GET.get('page', 1)) except PageNotAnInteger: users = paginator.page(1) except EmptyPage: users = paginator.page(paginator.num_pages) return render( request, 'backoffice/courses/users.html', { 'course_key_string': course_key_string, 'course_info': course_info, 'tab': 'courses', 'subtab': 'users', 'users': users, 'search': search_pattern })
def courses_list(request): if request.method == 'POST': # export as CSV csv_header = [ ugettext(u"Title"), ugettext(u"University"), ugettext(u"Organisation code"), ugettext(u"Course"), ugettext(u"Run"), ugettext(u"Start date"), ugettext(u"End date"), ugettext(u"Enrollment start"), ugettext(u"Enrollment end"), ugettext(u"Students count"), ugettext(u"Effort"), ugettext(u"Image"), ugettext(u"Video"), ugettext(u"Url") ] filename = 'export-cours-%s.csv' % datetime.datetime.now().strftime( '%Y-%m-%d') course_infos = get_complete_courses_info() rows = [(ci.title, ci.university, ci.course.id.org, ci.course.id.course, ci.course.id.run, format_datetime(ci.course.start), format_datetime(ci.course.end), format_datetime(ci.course.enrollment_start), format_datetime(ci.course.enrollment_end), ci.students_count, ci.effort, ' https://%s%s' % (settings.LMS_BASE, ci.course_image_url), ci.video, ci.url) for ci in course_infos] response = csv_response(csv_header, rows, filename) return response else: search_pattern = request.GET.get('search') course_infos = get_filtered_course_infos(search_pattern=search_pattern) return render( request, 'backoffice/courses/list.html', { 'course_infos': course_infos, 'pattern': search_pattern, 'tab': 'courses', })
def student_map_response(request, course_population_by_country_code, template, course_id): top_countries = sorted( [(population, code, get_country_name(code)) for code, population in course_population_by_country_code.iteritems()], reverse=True ) if request.GET.get("format") == "csv": data_rows = [(country, population) for population, _code, country in top_countries] return csv_response(["country", "enrollments"], data_rows, "countries.csv") total_population = sum(course_population_by_country_code.values()) return render(request, template, { "active_tab": "student_map", "course_id": course_id, "course_population": course_population_by_country_code, "top_countries": top_countries, "total_population": total_population, })
def enrollment_stats_response(request, enrollments, template): if request.GET.get("format") == "csv": return csv_response(["date", "enrollments"], enrollments.per_date, "enrollments.csv") context = enrollment_stats_context(enrollments) return render(request, template, context)