Exemplo n.º 1
0
    def avatar(self):
        from mainsite.helpers import gravatar_image_url

        if self.avatar_url:
            return self.avatar_url
        if self.twitter_profile_image_url:
            return self.twitter_profile_image_url
        default = getattr(settings, 'DEFAULT_AVATAR_URL', None)
        return gravatar_image_url(self.user.email, default=default)
Exemplo n.º 2
0
    def avatar(self):
        from mainsite.helpers import gravatar_image_url

        if self.avatar_url:
            return self.avatar_url
        if self.twitter_profile_image_url:
            return self.twitter_profile_image_url
        default = getattr(settings, 'DEFAULT_AVATAR_URL', None)
        return gravatar_image_url(self.user.email, default=default)
Exemplo n.º 3
0
    def get_context_data(self, **kwargs):
        queryset = self.object.gameaction_set.all()
        last_seen = self.kwargs.get('last_seen', None)
        if last_seen:
            turn, color = last_seen.split('.')
            queryset = queryset.filter(
                models.Q(turn__gt=turn) | models.Q(turn=turn, color__gt=color))

        #colors = PieceColor.objects.all()[:self.object.num_players]
        colors = []
        players = []
        for gp in self.object.gameplayer_set.all().order_by('turn_order'):
            players.append({
                'username':
                unicode(gp.player),
                'gravatar':
                gravatar_image_url(gp.player.user.email),
            })
            if gp.color:
                colors.append(gp.color)

        state = {
            'turn':
            "%s.%s" % (self.object.turn_number, self.object.turn_color),
            'moves': [],
            'my_colors': [],
            'colors': [c.name.lower() for c in colors],
            'players': players,
        }

        if self.request.user.is_authenticated():
            player = self.request.user.get_profile()
            for gp in self.object.gameplayer_set.filter(
                    models.Q(player=player) | models.Q(controller=player)):
                state['my_colors'].append(gp.turn_order)

        for move in queryset:
            state['moves'].append({
                'to_coord': move.to_coord,
                'from_coord': move.from_coord,
                'turn': move.turn,
                'color': move.color,
                'piece': move.piece,
                'expr': move.expression,
            })
        return state
Exemplo n.º 4
0
    def get_context_data(self, **kwargs):
        queryset = self.object.gameaction_set.all()
        last_seen = self.kwargs.get('last_seen', None)
        if last_seen:
            turn, color = last_seen.split('.')
            queryset = queryset.filter(models.Q(turn__gt=turn) | models.Q(turn=turn,color__gt=color))

        #colors = PieceColor.objects.all()[:self.object.num_players]
        colors = []
        players = []
        for gp in self.object.gameplayer_set.all().order_by('turn_order'):
            players.append({
                'username': unicode(gp.player),
                'gravatar': gravatar_image_url(gp.player.user.email),
            })
            if gp.color:
                colors.append(gp.color)

        state = {
            'turn': "%s.%s" % (self.object.turn_number, self.object.turn_color),
            'moves': [],
            'my_colors': [],
            'colors': [c.name.lower() for c in colors],
            'players': players,
        }

        if self.request.user.is_authenticated():
            player = self.request.user.get_profile()
            for gp in self.object.gameplayer_set.filter(models.Q(player=player) | models.Q(controller=player)):
                state['my_colors'].append(gp.turn_order)

        for move in queryset:
            state['moves'].append({
                'to_coord': move.to_coord,
                'from_coord': move.from_coord,
                'turn': move.turn,
                'color': move.color,
                'piece': move.piece,
                'expr': move.expression,
            })
        return state