Exemplo n.º 1
0
 def get_game(self):
     year = int(self.kwargs.get('year', 0))
     month = int(self.kwargs.get('month', 0))
     if not year:
         game = Game.active()           
     else:
         date = datetime.datetime(year=year, month=month, day=15)
         game = Game.active(now=date)
     if game is None:
         game = Game.objects.latest()
     return game
Exemplo n.º 2
0
 def game_boards(self):
     from july.game.models import Game
     latest = Game.active_or_latest()
     kwargs = {
         'player__user__in': self.members_by_points()
     }
     return latest.board_set.filter(**kwargs).order_by('-points')
Exemplo n.º 3
0
 def total_points(self):
     from july.game.models import Game, Player
     latest = Game.active_or_latest()
     query = Player.objects.filter(user__team=self, game=latest)
     total = query.aggregate(Sum('points'))
     points = total.get('points__sum')
     return points or 0
Exemplo n.º 4
0
 def members_by_points(self):
     from july.game.models import Game
     latest = Game.active_or_latest()
     kwargs = {
         self.rel_lookup: self
     }
     return latest.player_set.filter(**kwargs).order_by('-points')
Exemplo n.º 5
0
 def total_points(self):
     from july.game.models import Game, Player
     latest = Game.active_or_latest()
     kwargs = {self.rel_lookup: self, 'game': latest}
     query = Player.objects.filter(**kwargs)
     total = query.aggregate(Sum('points'))
     points = total.get('points__sum')
     return points or 0
Exemplo n.º 6
0
 def total_points(self):
     from july.game.models import Game, Player
     latest = Game.active_or_latest()
     kwargs = {
         self.rel_lookup: self,
         'game': latest
     }
     query = Player.objects.filter(**kwargs)
     total = query.aggregate(Sum('points'))
     points = total.get('points__sum')
     return points or 0
Exemplo n.º 7
0
def live(request):
    """Render the live view."""
    game = Game.active_or_latest()

    ctx = Context({
        'game': game,
        'user': request.user,
        'MEDIA_URL': settings.MEDIA_URL,
        'STATIC_URL': settings.STATIC_URL})

    return render_to_response('live/index.html', context_instance=ctx)
Exemplo n.º 8
0
 def run_query(self):
     if self.game is None:
         self.game = Game.active_or_latest()
     # Commit.calender returns a list of objects for each day a user has
     # commited along with the count during the day. So we can use this
     # query to get the total and the number of days.
     resp = Commit.calendar(self.game, user=self.user)
     objects = resp['objects']
     total = 0
     for obj in objects:
         total += obj.get('commit_count', 0)
     return {'game_commits': total, 'game_days': len(objects)}
Exemplo n.º 9
0
    def get_calendar(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.throttle_check(request)
        filters = {}

        game = Game.active_or_latest()
        username = request.GET.get('username')
        if username:
            filters['user__username'] = username

        # user = kwargs.get('user', None)
        calendar = Commit.calendar(game=game, **filters)
        return self.create_response(request, calendar)
Exemplo n.º 10
0
    def get_calendar(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.throttle_check(request)
        filters = {}

        game = Game.active_or_latest()
        username = request.GET.get('username')
        if username:
            filters['user__username'] = username

        # user = kwargs.get('user', None)
        calendar = Commit.calendar(game=game, **filters)
        return self.create_response(request, calendar)
Exemplo n.º 11
0
 def get_game(self):
     year = int(self.kwargs.get('year', 0))
     mon = int(self.kwargs.get('month', 0))
     day = self.kwargs.get('day')
     if day is None:
         day = 15
     day = int(day)
     if not all([year, mon]):
         now = None
     else:
         now = datetime.datetime(year=year, month=mon, day=day, tzinfo=UTC)
         logging.debug("Getting game for date: %s", now)
     return Game.active_or_latest(now=now)
Exemplo n.º 12
0
def index(request):
    """Render the home page"""
    game = Game.active_or_latest()
    stats = game.histogram

    ctx = Context({
        'stats': json.dumps(stats),
        'game': game,
        'total': sum(stats),
        'user': request.user,
        'MEDIA_URL': settings.MEDIA_URL,
        'STATIC_URL': settings.STATIC_URL})

    return render_to_response('index.html', context_instance=ctx)
Exemplo n.º 13
0
 def run_query(self):
     if self.game is None:
         self.game = Game.active_or_latest()
     # Commit.calender returns a list of objects for each day a user has
     # commited along with the count during the day. So we can use this
     # query to get the total and the number of days.
     resp = Commit.calendar(self.game, user=self.user)
     objects = resp['objects']
     total = 0
     for obj in objects:
         total += obj.get('commit_count', 0)
     return {
         'game_commits': total,
         'game_days': len(objects)
     }
Exemplo n.º 14
0
def index(request):
    """Render the home page"""
    game = Game.active_or_latest()
    stats = game.histogram if game else []
    posts = Blog.objects.filter(active=True).order_by('-posted')
    try:
        blog = posts[0]
    except:
        blog = None

    ctx = Context({
        'stats': json.dumps(stats),
        'game': game,
        'total': sum(stats),
        'user': request.user,
        'blog': blog,
        'MEDIA_URL': settings.MEDIA_URL,
        'STATIC_URL': settings.STATIC_URL})

    return render_to_response('index.html', context_instance=ctx)
Exemplo n.º 15
0
 def test_active_or_latest_past(self):
     game = self.make_game(start=self.early, end=self.yesterday)
     active = Game.active_or_latest()
     self.assertEqual(active, game)
Exemplo n.º 16
0
 def test_active_or_latest_past(self):
     game = self.make_game(start=self.early, end=self.yesterday)
     active = Game.active_or_latest()
     self.assertEqual(active, game)
Exemplo n.º 17
0
 def test_not_active(self):
     self.make_game(start=self.tomorrow, end=self.late)
     active = Game.active()
     self.assertEqual(active, None)
Exemplo n.º 18
0
 def members_by_points(self):
     from july.game.models import Game
     latest = Game.active_or_latest()
     return latest.players.filter(team=self).order_by('-player__points')
Exemplo n.º 19
0
 def test_active_or_latest(self):
     game = self.make_game()
     active = Game.active_or_latest()
     self.assertEqual(active, game)
Exemplo n.º 20
0
 def test_active_or_latest(self):
     game = self.make_game()
     active = Game.active_or_latest()
     self.assertEqual(active, game)
Exemplo n.º 21
0
 def members_by_points(self):
     from july.game.models import Game
     latest = Game.active_or_latest()
     kwargs = {self.rel_lookup: self}
     return latest.player_set.filter(**kwargs).order_by('-points')
Exemplo n.º 22
0
 def test_not_active(self):
     self.make_game(start=self.tomorrow, end=self.late)
     active = Game.active()
     self.assertEqual(active, None)
Exemplo n.º 23
0
 def game_boards(self):
     from july.game.models import Game
     latest = Game.active_or_latest()
     kwargs = {'player__user__in': self.members_by_points()}
     return latest.board_set.filter(**kwargs).order_by('-points')