def render_list(self,request, **kwargs): qs = self.queryset.all() info = request.GET.get('info','votes') ec = dict(self.extra_context) or {} if 'extra_context' in kwargs: ec.update(kwargs['extra_context']) ec['friend_pages'] = [['.?info=abc',_('By ABC'), False], ['.?info=votes', _('By number of votes'), False]] if info=='votes': qs = qs.annotate(extra=Count('votes')).order_by('-extra') ec['past_mks'] = ec['past_mks'].annotate(extra=Count('votes')).order_by('-extra') ec['friend_pages'][1][2] = True ec['norm_factor'] = float(qs[0].extra)/50 ec['title'] = "%s %s" % (_('Members'), _('By number of votes')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='abc': ec['friend_pages'][0][2] = True ec['title'] = _('Members') return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, **kwargs)
def render_list(self,request, **kwargs): ec = dict(self.extra_context) or {} if 'extra_context' in kwargs: ec.update(kwargs['extra_context']) selected_mks = request.session.get('selected_mks',dict()) qs = self.queryset.all() for o in qs: if o.id in selected_mks: o.selected = True next = request.GET.get('next',None) if next: path = request.get_full_path() ec['next'] = path[path.find('=')+1:] return ListDetailView.render_list(self, request, queryset = qs, extra_context = ec, **kwargs)
def render_list(self,request, **kwargs): qs = self.queryset.all() info = request.GET.get('info','votes') ec = dict(self.extra_context) or {} if 'extra_context' in kwargs: ec.update(kwargs['extra_context']) ec['friend_pages'] = [['.?info=abc',_('By ABC'), False], ['.?info=votes', _('By number of votes per month'), False], ['.?info=presence', _('By average weekly hours of presence'), False], ['.?info=committees', _('By average monthly committee meetings'), False], ['.?info=graph', _('Graphical view'), False]] if info=='votes': qs = list(qs) for x in qs: x.extra = x.voting_statistics.average_votes_per_month() qs.sort(key=lambda x:x.extra, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.voting_statistics.average_votes_per_month() ec['past_mks'].sort(key=lambda x:x.extra, reverse=True) ec['friend_pages'][1][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By number of votes per month')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='abc': ec['friend_pages'][0][2] = True ec['title'] = _('Members') if info=='presence': qs = list(qs) for x in qs: x.extra = x.average_weekly_presence() qs.sort(key=lambda x:x.extra or 0, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.average_weekly_presence() ec['past_mks'].sort(key=lambda x:x.extra or 0, reverse=True) ec['friend_pages'][2][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By average weekly hours of presence')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='committees': qs = list(qs) for x in qs: x.extra = x.committee_meetings_per_month() qs.sort(key=lambda x:x.extra or 0, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.committee_meetings_per_month() ec['past_mks'].sort(key=lambda x:x.extra or 0, reverse=True) ec['friend_pages'][2][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By average monthly committee meetings')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='graph': ec['friend_pages'][4][2] = True ec['title'] = "%s %s" % (_('Members'), _('Graphical view')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_graph.html', **kwargs) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, **kwargs)
def render_list(self,request, **kwargs): qs = self.queryset.all() info = request.GET.get('info','seats') ec = {} if self.extra_context: ec.update(self.extra_context) if 'extra_context' in kwargs: ec.update(kwargs['extra_context']) ec['coalition'] = qs.filter(is_coalition=True) ec['opposition'] = qs.filter(is_coalition=False) ec['friend_pages'] = [['.',_('By Number of seats'), False], ['.?info=votes-per-seat', _('By votes per seat'), False], ['.?info=discipline', _('By factional discipline'), False], ['.?info=coalition-discipline', _('By coalition/opposition discipline'), False], ] if info: if info=='seats': ec['coalition'] = ec['coalition'].annotate(extra=Sum('number_of_seats')).order_by('-extra') ec['opposition'] = ec['opposition'].annotate(extra=Sum('number_of_seats')).order_by('-extra') ec['friend_pages'][0][2] = True ec['norm_factor'] = 1 ec['baseline'] = 0 ec['title'] = "%s" % (_('Parties')) if info=='votes-per-seat': m = 0 for p in ec['coalition']: p.extra = p.voting_statistics.votes_per_seat() if p.extra > m: m = p.extra for p in ec['opposition']: p.extra = p.voting_statistics.votes_per_seat() if p.extra > m: m = p.extra ec['friend_pages'][1][2] = True ec['norm_factor'] = m/20 ec['baseline'] = 0 ec['title'] = "%s" % (_('Parties')) if info=='discipline': m = 100 for p in ec['coalition']: p.extra = p.voting_statistics.discipline() if p.extra < m: m = p.extra for p in ec['opposition']: p.extra = p.voting_statistics.discipline() if p.extra < m: m = p.extra ec['friend_pages'][2][2] = True ec['norm_factor'] = (100.0-m)/15 ec['baseline'] = m - 2 ec['title'] = "%s" % (_('Parties')) if info=='coalition-discipline': m = 100 for p in ec['coalition']: p.extra = p.voting_statistics.coalition_discipline() if p.extra < m: m = p.extra for p in ec['opposition']: p.extra = p.voting_statistics.coalition_discipline() if p.extra < m: m = p.extra ec['friend_pages'][3][2] = True ec['norm_factor'] = (100.0-m)/15 ec['baseline'] = m - 2 ec['title'] = "%s" % (_('Parties')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, **kwargs)
def render_list(self,request, **kwargs): qs = self.queryset.all() info = request.GET.get('info','bills_pre') ec = dict(self.extra_context) or {} if 'extra_context' in kwargs: ec.update(kwargs['extra_context']) ec['friend_pages'] = [['.?info=abc',_('By ABC'), False], ['.?info=bills_proposed',_('By number of bills proposed'), False], ['.?info=bills_pre',_('By number of bills pre-approved'), False], ['.?info=bills_first',_('By number of bills first-approved'), False], ['.?info=bills_approved',_('By number of bills approved'), False], ['.?info=votes', _('By number of votes per month'), False], ['.?info=presence', _('By average weekly hours of presence'), False], ['.?info=committees', _('By average monthly committee meetings'), False], ['.?info=graph', _('Graphical view'), False]] if info=='abc': ec['friend_pages'][0][2] = True ec['title'] = _('Members') if info=='bills_proposed': qs = list(qs) for x in qs: x.extra = x.bills.count() qs.sort(key=lambda x:x.extra, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.bills.count() ec['past_mks'].sort(key=lambda x:x.extra, reverse=True) ec['friend_pages'][1][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By number of bills proposed')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='bills_pre': qs = list(qs) for x in qs: x.extra = x.bills.filter(Q(stage='2')|Q(stage='3')|Q(stage='4')|Q(stage='5')|Q(stage='6')).count() qs.sort(key=lambda x:x.extra, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.bills.filter(Q(stage='2')|Q(stage='3')|Q(stage='4')|Q(stage='5')|Q(stage='6')).count() ec['past_mks'].sort(key=lambda x:x.extra, reverse=True) ec['friend_pages'][2][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By number of bills pre-approved')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='bills_first': qs = list(qs) for x in qs: x.extra = x.bills.filter(Q(stage='4')|Q(stage='5')|Q(stage='6')).count() qs.sort(key=lambda x:x.extra, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.bills.filter(Q(stage='4')|Q(stage='5')|Q(stage='6')).count() ec['past_mks'].sort(key=lambda x:x.extra, reverse=True) ec['friend_pages'][3][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By number of bills first-approved')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='bills_approved': qs = list(qs) for x in qs: x.extra = x.bills.filter(stage='6').count() qs.sort(key=lambda x:x.extra, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.bills.filter(stage='6').count() ec['past_mks'].sort(key=lambda x:x.extra, reverse=True) ec['friend_pages'][4][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By number of bills approved')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='votes': qs = list(qs) vs = list(MemberVotingStatistics.objects.all()) vs = dict(zip([x.member_id for x in vs],vs)) for x in qs: x.extra = vs[x.id].average_votes_per_month() qs.sort(key=lambda x:x.extra, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.voting_statistics.average_votes_per_month() ec['past_mks'].sort(key=lambda x:x.extra, reverse=True) ec['friend_pages'][5][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By number of votes per month')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='presence': qs = list(qs) for x in qs: x.extra = x.average_weekly_presence() qs.sort(key=lambda x:x.extra or 0, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.average_weekly_presence() ec['past_mks'].sort(key=lambda x:x.extra or 0, reverse=True) ec['friend_pages'][6][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By average weekly hours of presence')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='committees': qs = list(qs) for x in qs: x.extra = x.committee_meetings_per_month() qs.sort(key=lambda x:x.extra or 0, reverse=True) ec['past_mks'] = list(ec['past_mks']) for x in ec['past_mks']: x.extra = x.committee_meetings_per_month() ec['past_mks'].sort(key=lambda x:x.extra or 0, reverse=True) ec['friend_pages'][7][2] = True ec['norm_factor'] = float(qs[0].extra)/50.0 ec['title'] = "%s %s" % (_('Members'), _('By average monthly committee meetings')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_list_with_bars.html', **kwargs) if info=='graph': ec['friend_pages'][8][2] = True ec['title'] = "%s %s" % (_('Members'), _('Graphical view')) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, template_name='mks/member_graph.html', **kwargs) return ListDetailView.render_list(self,request, queryset=qs, extra_context=ec, **kwargs)