(self)
Counts both direct and delegated votes that are counted
Counts both direct and delegated votes that are counted
Counts both direct and delegated votes that are counted
def get_all_votes(self):
        '''
        Counts both direct and delegated votes that are counted
        '''

        from agora_site.agora_core.models import CastVote

        # NOTE: When you have first voted directly in a voting and then you
        # delegate your vote in the agora, it's currently not counted. It makes
        # sense because you voted directly - cancel your direct vote if you
        # want your delegation to be active in that case
        if self.ballot_is_open():
            q=self.cast_votes.filter(is_counted=True, is_direct=True, invalidated_at_date=None).values('voter__id').query

            # if ballot is open, we have yet not collected the final list of
            # delegated votes so we get it in real time from
            # agora.delegation_election
            return CastVote.objects.filter(
                # direct votes from people who can vote:
                Q(election=self, is_counted=True, is_direct=True,
                    invalidated_at_date=None)
                # indirect votes from people who have an active delegation in
                # this agora:
                | Q(election=self.agora.delegation_election, is_direct=False,
                    is_counted=True, invalidated_at_date=None)
            # This is to avoid duplicates. If you voted directly, that's what
            # counts:
            ).exclude(is_direct=False, voter__id__in=q).order_by('-casted_at_date')
        else:
            # if ballot is closed, then the delegated votes are already in 
            # self.delegated_votes
            return CastVote.objects.filter(
                # direct votes from people who can vote
                Q(election=self, is_counted=True, is_direct=True,
                    invalidated_at_date=None)
                # delegated votes from people who delegated for this election
                | Q(id__in=self.delegated_votes.values('id').query))
def get_all_votes ( self ) : from agora_site . agora_core . models import CastVote # NOTE: When you have first voted directly in a voting and then you # delegate your vote in the agora, it's currently not counted. It makes # sense because you voted directly - cancel your direct vote if you # want your delegation to be active in that case if self . ballot_is_open ( ) : q = self . cast_votes . filter ( is_counted = True , is_direct = True , invalidated_at_date = None ) . values ( 'voter__id' ) . query # if ballot is open, we have yet not collected the final list of # delegated votes so we get it in real time from # agora.delegation_election return CastVote . objects . filter ( # direct votes from people who can vote: Q ( election = self , is_counted = True , is_direct = True , invalidated_at_date = None ) # indirect votes from people who have an active delegation in # this agora: | Q ( election = self . agora . delegation_election , is_direct = False , is_counted = True , invalidated_at_date = None ) # This is to avoid duplicates. If you voted directly, that's what # counts: ) . exclude ( is_direct = False , voter__id__in = q ) . order_by ( '-casted_at_date' ) else : # if ballot is closed, then the delegated votes are already in  # self.delegated_votes return CastVote . objects . filter ( # direct votes from people who can vote Q ( election = self , is_counted = True , is_direct = True , invalidated_at_date = None ) # delegated votes from people who delegated for this election | Q ( id__in = self . delegated_votes . values ( 'id' ) . query ) )