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


Python models.Award類代碼示例

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


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

示例1: get_points

def get_points(request):
    if not request.user.is_authenticated():
        return {'points': 0, 'badges':0 }
    else:
        points = Points.get_userscore(request.user)
        if points is None:
            points = 0
        badges = Award.get_userawards(request.user)
        if badges is None:
            badges = 0
    return {'points': points, 'badges':badges }
開發者ID:mohideen-openwave,項目名稱:django-oppia,代碼行數:11,代碼來源:context_processors.py

示例2: courses_completed

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,代碼行數:30,代碼來源:awards.py

示例3: badge_award_all_activities

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,代碼行數:31,代碼來源:awards.py

示例4: update_summary

    def update_summary(self,
                       last_tracker_pk=0, newest_tracker_pk=0,  # range of tracker ids to process
                       last_points_pk=0, newest_points_pk=0     # range of points ids to process
                       ):

        first_tracker = (last_tracker_pk == 0)
        first_points = (last_points_pk == 0)

        t = time.time()
        self_trackers = Tracker.objects.filter(user=self.user, course=self.course, pk__gt=last_tracker_pk, pk__lte=newest_tracker_pk)

        ### Add the values that are directly obtained from the last pks
        self.total_activity = (0 if first_tracker else self.total_activity) + self_trackers.count()
        self.total_downloads = (0 if first_tracker else self.total_downloads) + self_trackers.filter(type='download').count()

        filters = {
            'user': self.user,
            'course': self.course,
            'pk__gt': last_points_pk
        }
        if newest_points_pk > 0:
            filters['pk__lte'] = newest_points_pk
        new_points = Points.objects.filter( ** filters).aggregate(total=Sum('points'))['total']

        if new_points:
            self.points = (0 if first_points else self.points) + new_points

        ### Values that need to be recalculated (as the course digests may vary)
        self.pretest_score = Course.get_pre_test_score(self.course, self.user)
        self.quizzes_passed = Course.get_no_quizzes_completed(self.course, self.user)
        self.badges_achieved = Award.get_userawards(self.user, self.course)
        self.completed_activities = Course.get_activities_completed(self.course, self.user)
        self.media_viewed = Course.get_media_viewed(self.course, self.user)

        ### Update the data in the database
        self.save()

        elapsed_time = time.time() - t
        print('took %.2f seconds' % elapsed_time)
開發者ID:DigitalCampus,項目名稱:django-oppia,代碼行數:39,代碼來源:user_course_summary.py

示例5: badge_award_final_quiz

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,代碼行數:42,代碼來源:awards.py

示例6: courses_completed

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,代碼行數:41,代碼來源:awards.py

示例7: badge_award_all_activities

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,代碼行數:37,代碼來源:awards.py

示例8: created_quizzes

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,代碼行數:24,代碼來源:awards.py

示例9: dehydrate_badges

 def dehydrate_badges(self,bundle):
     badges = Award.get_userawards(bundle.request.user)
     return badges
開發者ID:QCInvestments,項目名稱:django-oppia,代碼行數:3,代碼來源:resources.py


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