コード例 #1
0
    def render(self, context):
        try:
            object = template.resolve_variable(self.object, context)
        except template.VariableDoesNotExist:
            return ''

        vote_counts = Vote.objects.get_object_votes(object)
        votes = dict.fromkeys(possible_votes.keys(), 0)
        votes.update(vote_counts)
        votes[2] = votes[-1]  # we cannot index -1 in templates.
        context[self.context_var] = votes
        return ''
コード例 #2
0
    def render(self, context):
        try:
            object = template.resolve_variable(self.object, context)
        except template.VariableDoesNotExist:
            return ''

        vote_counts = Vote.objects.get_object_votes(object)
        votes = dict.fromkeys( possible_votes.keys(), 0 )
        votes.update(vote_counts)
        votes[2] = votes[-1] # we cannot index -1 in templates.
        context[self.context_var] = votes
        return ''
コード例 #3
0
ファイル: voting_tags.py プロジェクト: conrado/democracygame
    def render(self, context):
        try:
            objects = template.resolve_variable(self.objects, context)
        except template.VariableDoesNotExist:
            return ''
        
        counts_on_objects = Vote.objects.get_for_objects_in_bulk(objects)

        for object_id in counts_on_objects.keys(): 
            vote_counts = dict.fromkeys( possible_votes.keys() , 0 )
            vote_counts.update( counts_on_objects[object_id])
            vote_counts[2] = vote_counts[-1] # template does not allow -1
            counts_on_objects[object_id] = vote_counts

        context[self.context_var] = counts_on_objects 
        return ''
コード例 #4
0
    def render(self, context):
        try:
            objects = template.resolve_variable(self.objects, context)
        except template.VariableDoesNotExist:
            return ''

        counts_on_objects = Vote.objects.get_for_objects_in_bulk(objects)

        for object_id in counts_on_objects.keys():
            # all vote types default to 0.
            vote_counts = dict.fromkeys(possible_votes.keys(), 0)
            vote_counts.update(counts_on_objects[object_id])
            vote_counts[2] = vote_counts[-1] # we cannot index -1 in templates.
            vote_counts.pop(-1)
            counts_on_objects[object_id] = vote_counts

        context[self.context_var] = counts_on_objects
        return ''
コード例 #5
0
    def render(self, context):
        try:
            objects = template.resolve_variable(self.objects, context)
        except template.VariableDoesNotExist:
            return ''

        counts_on_objects = Vote.objects.get_for_objects_in_bulk(objects)

        for object_id in counts_on_objects.keys():
            # all vote types default to 0.
            vote_counts = dict.fromkeys(possible_votes.keys(), 0)
            vote_counts.update(counts_on_objects[object_id])
            vote_counts[2] = vote_counts[
                -1]  # we cannot index -1 in templates.
            vote_counts.pop(-1)
            counts_on_objects[object_id] = vote_counts

        context[self.context_var] = counts_on_objects
        return ''