def courses_completed(): try: badge = Badge.objects.get(ref='coursecompleted') except Badge.DoesNotExist: print "Badge not found: coursecompleted" return users = Tracker.objects.values('user_id').distinct() courses = Course.objects.all() for u in users: user = User.objects.get(pk=u['user_id']) #loop through the courses for c in courses: # check if the user has already been awarded for this course already_completed = AwardCourse.objects.filter(award__user=user,course=c) if already_completed.count() == 0: if media_complete(user,c) and activities_complete(user,c) and quiz_complete(user,c): print "%s badge awarded to %s" % (badge, user.username) award = Award() award.badge = badge award.user = user award.description = "Course completed: " + c.get_title() award.save() am = AwardCourse() am.course = c am.award = award am.course_version = c.version am.save() return
def courses_completed(): try: badge = Badge.objects.get(ref='coursecompleted') except Badge.DoesNotExist: print "Badge not found: coursecompleted" return users = Tracker.objects.values('user_id').distinct() courses = Course.objects.all() for u in users: user = User.objects.get(pk=u['user_id']) #loop through the courses for c in courses: # check if the user has already been awarded for this course already_completed = AwardCourse.objects.filter(award__user=user, course=c) if already_completed.count() == 0: if media_complete(user, c) and activities_complete( user, c) and quiz_complete(user, c): print "%s badge awarded to %s" % (badge, user.username) award = Award() award.badge = badge award.user = user award.description = "Course completed: " + c.get_title() award.save() am = AwardCourse() am.course = c am.award = award am.course_version = c.version am.save() return
def badge_award_all_activities(badge, hours): courses = Course.objects.filter(is_draft=False, is_archived=False) for c in courses: digests = Activity.objects.filter(section__course=c).values('digest').distinct() # get all the users who've added tracker for this course in last 'hours' if hours == 0: users = User.objects.filter(tracker__course=c).distinct() else: since = timezone.now() - datetime.timedelta(hours=int(hours)) users = User.objects.filter(tracker__course=c, tracker__submitted_date__gte=since).distinct() for u in users: if AwardCourse.objects.filter(award__user=u,course=c).count() == 0: user_completed = Tracker.objects.filter(user=u, course=c, completed=True, digest__in=digests).values('digest').distinct().count() if digests.count() == user_completed: print c.title print "-----------------------------" print digests.count() print u.username + " AWARD BADGE" award = Award() award.badge = badge award.user = u award.description = "Course completed: " + c.get_title() award.save() am = AwardCourse() am.course = c am.award = award am.course_version = c.version am.save()
def badge_award_final_quiz(badge, hours): courses = Course.objects.filter(is_draft=False, is_archived=False) for c in courses: final_quiz_digest_activity = Activity.objects \ .filter(section__course=c, type=Activity.QUIZ) \ .order_by('-section__order', '-order')[:1] if final_quiz_digest_activity.count() != 1: continue final_quiz_digest = final_quiz_digest_activity[0].digest print(final_quiz_digest) print(c.title) # get all the users who've added tracker for this course in last # 'hours' if hours == 0: users = User.objects.filter(tracker__course=c) else: since = timezone.now() - datetime.timedelta(hours=int(hours)) users = User.objects.filter(tracker__course=c, tracker__submitted_date__gte=since) # exclude the users that already own this course award users = users.exclude(award__awardcourse__course=c).distinct() for u in users: user_completed = Tracker.objects \ .filter(user=u, course=c, completed=True, digest=final_quiz_digest) \ .values('digest') \ .distinct() \ .count() if user_completed > 0: print(c.title) print("-----------------------------") print(u.username + " AWARD BADGE") award = Award() award.badge = badge award.user = u award.description = STR_COURSE_COMPLETED + c.get_title() award.save() am = AwardCourse() am.course = c am.award = award am.course_version = c.version am.save()
def badge_award_final_quiz(badge, hours): courses = Course.objects.filter(is_draft=False, is_archived=False) for c in courses: final_quiz_digest_activity = Activity.objects.filter( section__course=c, type=Activity.QUIZ).order_by('-section__order', '-order')[:1] if final_quiz_digest_activity.count() != 1: continue final_quiz_digest = final_quiz_digest_activity[0].digest print final_quiz_digest print c.title print "hours: " + str(hours) # get all the users who've added tracker for this course in last 'hours' if hours == 0: users = User.objects.filter(tracker__course=c).distinct() print "hours2:" + str(hours) else: since = timezone.now() - datetime.timedelta(hours=int(hours)) users = User.objects.filter( tracker__course=c, tracker__submitted_date__gte=since).distinct() print "users:" print users for u in users: if AwardCourse.objects.filter(award__user=u, course=c).count() == 0: user_completed = Tracker.objects.filter( user=u, course=c, completed=True, digest=final_quiz_digest).values( 'digest').distinct().count() if user_completed > 0: print c.title print "-----------------------------" print u.username + " AWARD BADGE" award = Award() award.badge = badge award.user = u award.description = "Course completed: " + c.get_title() award.save() am = AwardCourse() am.course = c am.award = award am.course_version = c.version am.save()
def badge_award_all_activities(badge, hours): courses = Course.objects.filter(is_draft=False, is_archived=False).values_list('id') for c in courses: digests = Activity.objects.filter(section__course=c) \ .values_list('digest', flat=True).distinct() digests = list(digests) total_activities = len(digests) # get all the users who've added tracker for this course in last # 'hours' if hours == 0: users = User.objects.filter(tracker__course=c) else: since = timezone.now() - datetime.timedelta(hours=int(hours)) users = User.objects.filter(tracker__course=c, tracker__submitted_date__gte=since) # exclude the users that already own this course award users = users.exclude(award__awardcourse__course=c) \ .values_list('id').distinct() for u in users: user_completed = Tracker.objects.filter(user=u, course=c, completed=True, digest__in=digests) \ .values('digest').distinct().count() if user_completed >= total_activities: course_award = Course.objects.get(id=c[0]) user_awarded = User.objects.get(id=u[0]) print(course_award.title) print("-----------------------------") print(total_activities) print(user_awarded.username + " AWARD BADGE") award = Award() award.badge = badge award.user = user_awarded award.description = STR_COURSE_COMPLETED \ + course_award.get_title() award.save() am = AwardCourse() am.course = course_award am.award = award am.course_version = course_award.version am.save()
def courses_completed(hours): try: badge = Badge.objects.get(ref='coursecompleted') except Badge.DoesNotExist: print "Badge not found: coursecompleted" return print hours # create batch of course with all the digests for each course courses = Course.objects.filter(is_draft=False, is_archived=False) for c in courses: digests = Activity.objects.filter( section__course=c).values('digest').distinct() # get all the users who've added tracker for this course in last 'hours' if hours == 0: users = User.objects.filter(tracker__course=c).distinct() else: since = timezone.now() - datetime.timedelta(hours=int(hours)) users = User.objects.filter( tracker__course=c, tracker__submitted_date__gte=since).distinct() for u in users: user_completed = Tracker.objects.filter( user=u, course=c, completed=True, digest__in=digests).values('digest').distinct().count() if digests.count( ) == user_completed and AwardCourse.objects.filter( award__user=u, course=c).count() == 0: print c.title print "-----------------------------" print digests.count() print u.username + " AWARD BADGE" award = Award() award.badge = badge award.user = u award.description = "Course completed: " + c.get_title() award.save() am = AwardCourse() am.course = c am.award = award am.course_version = c.version am.save() return
def award_badge(self, course, user, badge): print(course.get_title()) print("-----------------------------") print(user.username + " AWARD BADGE") award = Award() award.badge = badge award.user = user award.description = self.STR_COURSE_COMPLETED \ + course.get_title() award.save() ac = AwardCourse() ac.course = course ac.award = award ac.course_version = course.version ac.save()
def badge_award_all_quizzes(badge, hours): courses = Course.objects.filter(is_draft=False, is_archived=False) for c in courses: digests = Activity.objects.filter( section__course=c, type=Activity.QUIZ).values('digest').distinct() # get all the users who've added tracker for this course in last 'hours' if hours == 0: users = User.objects.filter(tracker__course=c) else: since = timezone.now() - datetime.timedelta(hours=int(hours)) users = User.objects.filter(tracker__course=c, tracker__submitted_date__gte=since) # exclude the users that already own this course award users = users.exclude(award__awardcourse__course=c).distinct() for u in users: if AwardCourse.objects.filter(award__user=u, course=c).count() == 0: user_completed = Tracker.objects.filter( user=u, course=c, completed=True, type=Activity.QUIZ, digest__in=digests).values('digest').distinct().count() if digests.count() == user_completed: print(c.title) print("-----------------------------") print(digests.count()) print(u.username + " AWARD BADGE") award = Award() award.badge = badge award.user = u award.description = "Course completed: " + c.get_title() award.save() am = AwardCourse() am.course = c am.award = award am.course_version = c.version am.save()
def badge_award_final_quiz(badge, hours): courses = Course.objects.filter(is_draft=False, is_archived=False) for c in courses: final_quiz_digest_activity = Activity.objects.filter(section__course=c, type=Activity.QUIZ).order_by('-section__order','-order')[:1] if final_quiz_digest_activity.count() != 1: continue final_quiz_digest = final_quiz_digest_activity[0].digest print final_quiz_digest print c.title print "hours: " + str(hours) # get all the users who've added tracker for this course in last 'hours' if hours == 0: users = User.objects.filter(tracker__course=c).distinct() print "hours2:" + str(hours) else: since = timezone.now() - datetime.timedelta(hours=int(hours)) users = User.objects.filter(tracker__course=c, tracker__submitted_date__gte=since).distinct() print "users:" print users for u in users: if AwardCourse.objects.filter(award__user=u,course=c).count() == 0: user_completed = Tracker.objects.filter(user=u, course=c, completed=True, digest=final_quiz_digest).values('digest').distinct().count() if user_completed > 0: print c.title print "-----------------------------" print u.username + " AWARD BADGE" award = Award() award.badge = badge award.user = u award.description = "Course completed: " + c.get_title() award.save() am = AwardCourse() am.course = c am.award = award am.course_version = c.version am.save()
def courses_completed(hours): try: badge = Badge.objects.get(ref='coursecompleted') except Badge.DoesNotExist: print "Badge not found: coursecompleted" return print hours # create batch of course with all the digests for each course courses = Course.objects.filter(is_draft=False, is_archived=False) for c in courses: digests = Activity.objects.filter(section__course=c).values('digest').distinct() # get all the users who've added tracker for this course in last 'hours' if hours == 0: users = User.objects.filter(tracker__course=c).distinct() else: since = timezone.now() - datetime.timedelta(hours=int(hours)) users = User.objects.filter(tracker__course=c, tracker__submitted_date__gte=since).distinct() for u in users: user_completed = Tracker.objects.filter(user=u, course=c, completed=True, digest__in=digests).values('digest').distinct().count() if digests.count() == user_completed and AwardCourse.objects.filter(award__user=u,course=c).count() == 0: print c.title print "-----------------------------" print digests.count() print u.username + " AWARD BADGE" award = Award() award.badge = badge award.user = u award.description = "Course completed: " + c.get_title() award.save() am = AwardCourse() am.course = c am.award = award am.course_version = c.version am.save() return
def badge_award_all_activities(badge, hours): courses = Course.objects.filter(is_draft=False, is_archived=False).values_list('id') for c in courses: digests = Activity.objects.filter(section__course=c).values_list('digest', flat=True).distinct() digests = list(digests) total_activities = len(digests) # get all the users who've added tracker for this course in last 'hours' if hours == 0: users = User.objects.filter(tracker__course=c) else: since = timezone.now() - datetime.timedelta(hours=int(hours)) users = User.objects.filter(tracker__course=c, tracker__submitted_date__gte=since) # exclude the users that already own this course award users = users.exclude(award__awardcourse__course=c).values_list('id').distinct() for u in users: user_completed = Tracker.objects.filter(user=u, course=c, completed=True, digest__in=digests).values('digest').distinct().count() if user_completed >= total_activities: course_award = Course.objects.get(id=c[0]) user_awarded = User.objects.get(id=u[0]) print course_award.title print "-----------------------------" print total_activities print user_awarded.username + " AWARD BADGE" award = Award() award.badge = badge award.user = user_awarded award.description = "Course completed: " + course_award.get_title() award.save() am = AwardCourse() am.course = course_award am.award = award am.course_version = course_award.version am.save()