def ensure_certif(request, course_id): user_id = request.user.id username = request.user.username course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) course_tma = get_course_by_id(course_key) is_graded = course_tma.is_graded grade_cutoffs = modulestore().get_course( course_key, depth=0).grade_cutoffs['Pass'] * 100 grading_note = CourseGradeFactory().create(request.user, course_tma) #TMA GRADE TRACKING UPDATE mongo_persist = dashboardStats() collection = mongo_persist.connect() add_user = {} add_user['user_id'] = request.user.id add_user['username'] = request.user.username add_user['passed'] = grading_note.passed add_user['percent'] = grading_note.percent add_user['summary'] = grading_note.summary mongo_persist.add_user_grade_info(collection, str(course_id), add_user) # END TMA GRADE TRACKING UPDATE passed = grading_note.passed percent = float(int(grading_note.percent * 1000) / 10) overall_progress = get_overall_progress(request.user.id, course_key) context = { 'passed': passed, 'percent': percent, 'is_graded': is_graded, 'grade_cutoffs': grade_cutoffs, 'overall_progress': overall_progress } return JsonResponse(context)
def course_welcome(request, course_id): """ Display the course's welcome.html, or 404 if there is no such course. Assumes the course_id is in a valid format. """ course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) with modulestore().bulk_operations(course_key): course = get_course_by_id(course_key, depth=2) access_response = has_access(request.user, 'load', course, course_key) is_enrolled = CourseEnrollment.is_enrolled(request.user, course_key) if not is_enrolled: return redirect(reverse('about_course', args=[unicode(course_key)])) if not access_response: # The user doesn't have access to the course. If they're # denied permission due to the course not being live yet, # redirect to the dashboard page. if isinstance(access_response, StartDateError): start_date = strftime_localized(course.start, 'SHORT_DATE') params = urllib.urlencode({'notlive': start_date}) return redirect('{0}?{1}'.format(reverse('dashboard'), params)) # Otherwise, give a 404 to avoid leaking info about access # control. raise Http404("Course not found.") context = { 'request': request, 'course_id': course_key.to_deprecated_string(), 'course': course } if settings.TMA_WELCOME_PAGE_NAME == 'purple': # Get the final score for the student score = get_final_score(request, course) # Set badge if the score is greater or equal to 60% badge = score >= 60 # update context context.update({ 'score': score, 'badge': badge, 'overall_progress': get_overall_progress(request.user.id, course_key), 'accordion': render_accordion(request, course) }) # set template to purple template_name = 'course_welcome/purple.html' else: # update context context.update( {'sections': prepare_sections_with_grade(request, course)}) # set template to dots template_name = 'course_welcome/dots.html' return render_to_response(template_name, context)
def get_overall_course_progress(request): """ Description: This view kept for fetching the overall course progress. Request Parameters: course_id: course ID for which progress needs to be calculated. student_id: Student for which progress needs to be calculated. Returns: json response Assumes the course_id is in a valid format. Author: Naresh Makwana """ course_id = request.GET.get('course_id') course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) overall_progress = get_overall_progress(request.user.id, course_key) return JsonResponse({'overall_progress': overall_progress})
def ensure_certif(request, course_id): user_id = request.user.id username = request.user.username course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) course_tma = get_course_by_id(course_key) is_graded = course_tma.is_graded grade_cutoffs = modulestore().get_course( course_key, depth=0).grade_cutoffs['Pass'] * 100 grading_note = CourseGradeFactory().create(request.user, course_tma) passed = grading_note.passed percent = float(int(grading_note.percent * 1000) / 10) overall_progress = get_overall_progress(request.user.id, course_key) context = { 'passed': passed, 'percent': percent, 'is_graded': is_graded, 'grade_cutoffs': grade_cutoffs, 'overall_progress': overall_progress } return JsonResponse(context)
def get_user_overvall_course_progress(user,course_id): course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) overall_progress = get_overall_progress(user, course_id) return {'overall_progress': overall_progress}
def get_student_info(self, email): if User.objects.filter(email=email).exists(): student = User.objects.get(email=email) # List of courses user is enrolled to org_filter_out_set = '' course_org_filter = '' course_enrollments = list( get_course_enrollments(student, course_org_filter, org_filter_out_set)) #last login data_email last_login_brut = str(student.last_login) last_login = last_login_brut.split('.') #Check if microsite admin if MicrositeAdminManager.objects.filter(user=student).exists(): check_admin_microsite = True microsite_key = MicrositeAdminManager.objects.get( user=student).microsite_id microsite_admin_org = Microsite.objects.get( pk=microsite_key).key else: check_admin_microsite = False #Check wich course invited first if CourseEnrollment.objects.filter(user=student).exists(): course_id = CourseEnrollment.objects.filter( user=student).order_by('-created')[0].course_id user_org = str(course_id).split('+')[0].replace( "course-v1:", "") else: user_org = "No organization found for user" #Course counters compteur_progress = 0 compteur_finish = 0 compteur_start = 0 compteur_certified = 0 progress_courses = [] finish_courses = [] start_courses = [] certified_courses = [] _now = int(datetime.datetime.now().strftime("%s")) if len(course_enrollments) > 0: #For each course user is enrolled to for dashboard_index, enrollment in enumerate( course_enrollments): course_id = enrollment.course_overview.id user_id = student.id course_tma = get_course_by_id(enrollment.course_id) try: course_grade_factory = CourseGradeFactory().create( student, course_tma) passed = course_grade_factory.passed percent = course_grade_factory.percent except: passed = False percent = 0 course_progression = get_overall_progress( user_id, course_id) try: _end = int( enrollment.course_overview.end.strftime("%s")) except: _end = 0 _progress = True if _end > 0 and _end < _now: _progress = False #storing student results for this class q = {} q['passed'] = passed q['percent'] = float(int(percent * 1000) / 10) q['course_id'] = str(enrollment.course_id) q['duration'] = CourseDetails.fetch( enrollment.course_id).effort q['required'] = course_tma.is_required_atp q['content_data'] = course_tma.content_data q['category'] = course_tma.categ q['display_name_with_default'] = enrollment.course_overview.display_name_with_default q['course_progression'] = course_progression if passed == True: compteur_certified += 1 certified_courses.append(q) if course_progression > 0 and course_progression < 100 and passed == False and _progress == True: compteur_progress += 1 progress_courses.append(q) elif course_progression == 100 or passed or _progress == False: compteur_finish += 1 finish_courses.append(q) elif course_progression == 0 and _progress == True: compteur_start += 1 start_courses.append(q) #Candidate status if student.is_staff: status = "Staff" elif check_admin_microsite: status = "Admin Microsite" else: status = "Student" context = { 'student_id': student.id, 'status': status, 'student_mail': student.email, 'student_name': student.first_name + " " + student.last_name, 'progress_courses': compteur_progress, #'progress_courses': progress_courses, 'finished_courses': compteur_finish, #'finish_courses': finish_courses, 'started_courses': compteur_start, #'start_courses':start_courses, 'certified_courses': compteur_certified, #'certified_course' : certified_courses, 'user_org': user_org, 'last login': last_login[0] } if check_admin_microsite: context['microsite_admin_org'] = microsite_admin_org else: if UserPreprofile.objects.filter(email=email).exists(): user = UserPreprofile.objects.get(email=email) if CourseEnrollmentAllowed.objects.filter( email=email).exists(): profile = CourseEnrollmentAllowed.objects.filter( email=email).order_by('-created') course_id = profile[0].course_id user_org = str(course_id).split('+')[0].replace( "course-v1:", "") else: user_org = "No organization found for user" context = { 'student_mail': email, 'student_name': user.first_name + " " + user.last_name, 'status': "User preregistered on platform", 'user_org': user_org } else: context = { 'student_mail': email, 'status': "Unknown user", } return context
def get_student_info(self, student): # List of courses user is enrolled to org_filter_out_set = '' course_org_filter = '' course_enrollments = list( get_course_enrollments(student, course_org_filter, org_filter_out_set)) #last login data_email last_login_brut = str(student.last_login) last_login = last_login_brut.split('.') #Check if user is staff / microsite admin / student check_admin_microsite = False try: microsite_key = MicrositeAdminManager.objects.get( user=student).microsite_id user_org = microsite = Microsite.objects.get(pk=microsite_key).key check_admin_microsite = True except: user_org = "Not microsite admin" pass compteur_progress = 0 compteur_finish = 0 compteur_start = 0 compteur_certified = 0 progress_courses = [] finish_courses = [] start_courses = [] certified_courses = [] _now = int(datetime.datetime.now().strftime("%s")) if len(course_enrollments) > 0: #For each course user is enrolled to for dashboard_index, enrollment in enumerate(course_enrollments): course_id = enrollment.course_overview.id user_id = student.id course_tma = get_course_by_id(enrollment.course_id) try: course_grade_factory = CourseGradeFactory().create( student, course_tma) passed = course_grade_factory.passed percent = course_grade_factory.percent except: passed = False percent = 0 course_progression = get_overall_progress(user_id, course_id) try: _end = int(enrollment.course_overview.end.strftime("%s")) except: _end = 0 _progress = True if _end > 0 and _end < _now: _progress = False #storing student results for this class q = {} q['passed'] = passed q['percent'] = float(int(percent * 1000) / 10) q['course_id'] = str(enrollment.course_id) q['duration'] = CourseDetails.fetch( enrollment.course_id).effort q['required'] = course_tma.is_required_atp q['content_data'] = course_tma.content_data q['category'] = course_tma.categ q['display_name_with_default'] = enrollment.course_overview.display_name_with_default q['course_progression'] = course_progression if passed == True: compteur_certified += 1 certified_courses.append(q) if course_progression > 0 and course_progression < 100 and passed == False and _progress == True: compteur_progress += 1 progress_courses.append(q) elif course_progression == 100 or passed or _progress == False: compteur_finish += 1 finish_courses.append(q) elif course_progression == 0 and _progress == True: compteur_start += 1 start_courses.append(q) if student.is_staff: status = "Staff" elif check_admin_microsite: status = "Admin Microsite" else: status = "Student" context = { 'student_id': student.id, 'status': status, 'student_mail': student.email, 'student_name': student.first_name + " " + student.last_name, 'progress_courses': compteur_progress, #'progress_courses': progress_courses, 'finished_courses': compteur_finish, #'finish_courses': finish_courses, 'started_courses': compteur_start, #'start_courses':start_courses, 'certified_courses': compteur_certified, #'certified_course' : certified_courses, 'user org': user_org, 'last login': last_login[0] } return context