def get_context(self, *args, **kwargs):
        context = super(AgendaListView, self).get_context(*args, **kwargs)
        # optimization - create query for votes per agenda
        # store in context as dictionary votes[agendaid]=<votenum>
        agenda_votes_results = Agenda.objects.values("id").annotate(Count("votes"))
        agenda_votes = dict(map(lambda vote:(vote["id"],str(vote["votes__count"])),agenda_votes_results))
        parties_lookup = {party.id: party.name for
                          party in Party.current_knesset.all()}

        allAgendaPartyVotes = cache.get('AllAgendaPartyVotes')

        if not allAgendaPartyVotes:
            # filtering for current knesset is done here

            allAgendaPartyVotes = queries.getAllAgendaPartyVotes()

            for agenda_id, party_votes in allAgendaPartyVotes.iteritems():
                allAgendaPartyVotes[agenda_id] = [
                    x for x in party_votes if x[0] in parties_lookup]

            cache.set('AllAgendaPartyVotes', allAgendaPartyVotes, 1800)

        if self.request.user.is_authenticated():
            p = self.request.user.get_profile()
            watched = p.agendas
        else:
            watched = None
        agendaEditorIds = queries.getAgendaEditorIds()
        allEditorIds = list(set(chain.from_iterable(agendaEditorIds.values())))
        editors = User.objects.filter(id__in=allEditorIds)
        context['agenda_editors'] = agendaEditorIds
        context['editors'] = dict(map(lambda obj:(obj.id,obj),editors))
        context['watched'] = watched
        context['agenda_votes']=agenda_votes
        context['agenda_party_values']=allAgendaPartyVotes
        context['parties_lookup']=parties_lookup
        return context
dataset/ETHPy150Open ofri/Open-Knesset/agendas/views.py/AgendaListView.get_context/original