本文整理匯總了Python中oppia.models.Award.get_userawards方法的典型用法代碼示例。如果您正苦於以下問題:Python Award.get_userawards方法的具體用法?Python Award.get_userawards怎麽用?Python Award.get_userawards使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oppia.models.Award
的用法示例。
在下文中一共展示了Award.get_userawards方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_points
# 需要導入模塊: from oppia.models import Award [as 別名]
# 或者: from oppia.models.Award import get_userawards [as 別名]
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 }
示例2: update_summary
# 需要導入模塊: from oppia.models import Award [as 別名]
# 或者: from oppia.models.Award import get_userawards [as 別名]
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)
示例3: dehydrate_badges
# 需要導入模塊: from oppia.models import Award [as 別名]
# 或者: from oppia.models.Award import get_userawards [as 別名]
def dehydrate_badges(self,bundle):
badges = Award.get_userawards(User.objects.get(username__exact=bundle.data['username']))
return badges