當前位置: 首頁>>代碼示例>>Python>>正文


Python Award.user方法代碼示例

本文整理匯總了Python中oppia.models.Award.user方法的典型用法代碼示例。如果您正苦於以下問題:Python Award.user方法的具體用法?Python Award.user怎麽用?Python Award.user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oppia.models.Award的用法示例。


在下文中一共展示了Award.user方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: courses_completed

# 需要導入模塊: from oppia.models import Award [as 別名]
# 或者: from oppia.models.Award import user [as 別名]
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
開發者ID:DigitalCampus,項目名稱:django-swaziland-oppia,代碼行數:32,代碼來源:awards.py

示例2: badge_award_all_activities

# 需要導入模塊: from oppia.models import Award [as 別名]
# 或者: from oppia.models.Award import user [as 別名]
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() 
開發者ID:VTRMobile,項目名稱:django-oppia,代碼行數:33,代碼來源:awards.py

示例3: badge_award_final_quiz

# 需要導入模塊: from oppia.models import Award [as 別名]
# 或者: from oppia.models.Award import user [as 別名]
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() 
開發者ID:iSchool-Zambia,項目名稱:django-ischool-oppia,代碼行數:44,代碼來源:awards.py

示例4: courses_completed

# 需要導入模塊: from oppia.models import Award [as 別名]
# 或者: from oppia.models.Award import user [as 別名]
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
開發者ID:DigitalCampus,項目名稱:django-maf-oppia,代碼行數:43,代碼來源:awards.py

示例5: badge_award_all_activities

# 需要導入模塊: from oppia.models import Award [as 別名]
# 或者: from oppia.models.Award import user [as 別名]
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()
開發者ID:QCInvestments,項目名稱:django-oppia,代碼行數:39,代碼來源:awards.py

示例6: created_quizzes

# 需要導入模塊: from oppia.models import Award [as 別名]
# 或者: from oppia.models.Award import user [as 別名]
def created_quizzes(num):    
    badge_ref = 'create'+str(num)+'quiz'
    try:
        badge = Badge.objects.get(ref=badge_ref)
    except Badge.DoesNotExist:
        print "Badge not found: " + badge_ref
        return
    
    # get all the ppl who've created more than 10 quizzes
    users = User.objects.annotate(total=Count('quiz')).filter(total__gt=num)
    for u in users:
        # find out how many awards this user already has
        no_awards = Award.objects.filter(badge=badge,user=u).count()
        if (no_awards*num)+num <= u.total:
            # how many awards to make?
            make_awards = int((u.total - (no_awards*num))/num)
            for i in range(0,make_awards):
                a = Award()
                a.user = u
                a.badge = badge
                a.description = badge.description
                a.save()
                print a.description + " award made to " + u.username
    return
開發者ID:DigitalCampus,項目名稱:django-swaziland-oppia,代碼行數:26,代碼來源:awards.py


注:本文中的oppia.models.Award.user方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。