def get_monthly_score(self): ''' Gets the score from this month's ScoreCounter, or creates it if it doesn't already exist. ''' counter = ScoreCounter.objects.get_or_create(user=self.user, when=get_current_month_datetime())[0] return counter.score
def rankings(request, template_name='rankings/rankings.html'): rankings = ScoreCounter.objects.filter(when=get_current_month_datetime( )).select_related('user').order_by('-score') paginator = Paginator(rankings, settings.USERS_PER_PAGE) # TODO: Allow rankings other than the top "N" to be seen? context = dict(rankings=paginator.page(1)) return render_to_response(template_name, context, RequestContext(request))
def get_monthly_rank(self): ''' Gets the score from this month's ScoreCounter, or creates it if it doesn't already exist. ''' now_month = get_current_month_datetime() counter = ScoreCounter.objects.get_or_create(user=self.user, when=now_month)[0] # a User's rank is also essentially a count of how many Users have a # score greater than the current user + 1 return ScoreCounter.objects.order_by('-score').filter(when__gte=now_month, score__gt=counter.score).count() + 1
def add_monthly_score(self, value): counter = ScoreCounter.objects.get_or_create(user=self.user, when=get_current_month_datetime())[0] counter.score += value counter.save()