예제 #1
0
    def get_context (self):
        context = super(MemberDetailView, self).get_context()
        member = context['object']
        if self.request.user.is_authenticated():
            p = self.request.user.get_profile()
            watched = member in p.members
        else:
            watched = False
            
        verbs = None
        if 'verbs' in self.request.GET:
            verbs_form = VerbsForm(self.request.GET)
            if verbs_form.is_valid():
                verbs = verbs_form.cleaned_data['verbs']
        if verbs==None:
            verbs = ('proposed', 'posted')
            verbs_form = VerbsForm({'verbs': verbs})

        bills_statistics = {}
        bills_statistics['proposed'] = member.bills.count()
        bills_statistics['pre'] = member.bills.filter(Q(stage='2')|Q(stage='3')|Q(stage='4')|Q(stage='5')|Q(stage='6')).count()
        bills_statistics['first'] = member.bills.filter(Q(stage='4')|Q(stage='5')|Q(stage='6')).count()
        bills_statistics['approved'] = member.bills.filter(stage='6').count()

        bills_tags = Tag.objects.usage_for_queryset(member.bills.all(),counts=True)
        #bills_tags.sort(key=lambda x:x.count,reverse=True)
        bills_tags = tagging.utils.calculate_cloud(bills_tags)
        context.update({'watched_member': watched,
                'actions': actor_stream(member).filter(verb__in=verbs),
                'verbs_form': verbs_form,
                'bills_statistics':bills_statistics,
                'bills_tags':bills_tags,
               })
        return context
예제 #2
0
    def get_object_context (self, request, object_id):
        from actstream import actor_stream
        member = get_object_or_404(Member,pk=object_id)
        if request.user.is_authenticated():
            p = request.user.get_profile()
            watched = member in p.followed_members.all()
        else:
            watched = False
            
        verbs = None
        if 'verbs' in request.GET:
            verbs_form = VerbsForm(request.GET)
            if verbs_form.is_valid():
                verbs = verbs_form.cleaned_data['verbs']
        if verbs==None:
            verbs = ('proposed', 'posted')
            verbs_form = VerbsForm({'verbs': verbs})

        bills_statistics = {}
        bills_statistics['proposed'] = member.bills.count()
        bills_statistics['pre'] = member.bills.filter(Q(stage='2')|Q(stage='3')|Q(stage='4')|Q(stage='5')|Q(stage='6')).count()
        bills_statistics['first'] = member.bills.filter(Q(stage='4')|Q(stage='5')|Q(stage='6')).count()
        bills_statistics['approved'] = member.bills.filter(stage='6').count()

        return {'watched_member': watched,
                'actions': actor_stream(member).filter(verb__in=verbs),
                'verbs_form': verbs_form,
                'bills_statistics':bills_statistics,
               }
예제 #3
0
파일: views.py 프로젝트: IgKh/Open-Knesset
    def get_context (self):
        context = super(MemberDetailView, self).get_context()
        member = context['object']
        if self.request.user.is_authenticated():
            p = self.request.user.get_profile()
            watched = member in p.members
        else:
            watched = False
            
        verbs = None
        if 'verbs' in self.request.GET:
            verbs_form = VerbsForm(self.request.GET)
            if verbs_form.is_valid():
                verbs = verbs_form.cleaned_data['verbs']
        if verbs==None:
            verbs = ('proposed', 'posted')
            verbs_form = VerbsForm({'verbs': verbs})

        bills_statistics = {}
        bills_statistics['proposed'] = member.bills.count()
        bills_statistics['pre'] = member.bills.filter(Q(stage='2')|Q(stage='3')|Q(stage='4')|Q(stage='5')|Q(stage='6')).count()
        bills_statistics['first'] = member.bills.filter(Q(stage='4')|Q(stage='5')|Q(stage='6')).count()
        bills_statistics['approved'] = member.bills.filter(stage='6').count()

        bills_tags = Tag.objects.usage_for_queryset(member.bills.all(),counts=True)
        #bills_tags.sort(key=lambda x:x.count,reverse=True)
        bills_tags = tagging.utils.calculate_cloud(bills_tags)

        agendas = Agenda.objects.get_selected_for_instance(member, top=3, bottom=3)
        agendas = agendas['top'] + agendas['bottom']
        for agenda in agendas:
            agenda.watched=False
        if self.request.user.is_authenticated():
            watched_agendas = self.request.user.get_profile().agendas
            for watched_agenda in watched_agendas:
                if watched_agenda in agendas:
                    agendas[agendas.index(watched_agenda)].watched = True
                else:
                    watched_agenda.score = watched_agenda.member_score(member)
                    watched_agenda.watched = True
                    agendas.append(wathced_agenda)
        agendas.sort(key=attrgetter('score'), reverse=True)
        
        context.update({'watched_member': watched,
                'actions': actor_stream(member).filter(verb__in=verbs),
                'verbs_form': verbs_form,
                'bills_statistics':bills_statistics,
                'bills_tags':bills_tags,
                'agendas':agendas
               })
        return context
예제 #4
0
    def get_context (self):
        context = super(MemberDetailView, self).get_context()
        member = context['object']
        if self.request.user.is_authenticated():
            p = self.request.user.get_profile()
            watched = member in p.members
        else:
            watched = False
            
        verbs = None
        if 'verbs' in self.request.GET:
            verbs_form = VerbsForm(self.request.GET)
            if verbs_form.is_valid():
                verbs = verbs_form.cleaned_data['verbs']
        if verbs==None:
            verbs = ('proposed', 'posted')
            verbs_form = VerbsForm({'verbs': verbs})

        presence = {}
        self.calc_percentile(member, presence, 
                             'average_weekly_presence_hours', 
                             'average_weekly_presence_hours',
                             'average_weekly_presence_hours_percentile' )
        self.calc_percentile(member, presence, 
                             'average_monthly_committee_presence', 
                             'average_monthly_committee_presence',
                             'average_monthly_committee_presence_percentile' )

        bills_statistics = {}
        self.calc_bill_stats(member,bills_statistics,'proposed')
        self.calc_bill_stats(member,bills_statistics,'pre')
        self.calc_bill_stats(member,bills_statistics,'first')
        self.calc_bill_stats(member,bills_statistics,'approved')

        bills_tags = Tag.objects.usage_for_queryset(member.bills.all(),counts=True)
        #bills_tags.sort(key=lambda x:x.count,reverse=True)
        bills_tags = tagging.utils.calculate_cloud(bills_tags)

        if self.request.user.is_authenticated():
            agendas = Agenda.objects.get_selected_for_instance(member, user=self.request.user, top=3, bottom=3)
        else:
            agendas = Agenda.objects.get_selected_for_instance(member, user=None, top=3, bottom=3)
        agendas = agendas['top'] + agendas['bottom']
        for agenda in agendas:
            agenda.watched=False
        if self.request.user.is_authenticated():
            watched_agendas = self.request.user.get_profile().agendas
            for watched_agenda in watched_agendas:
                if watched_agenda in agendas:
                    agendas[agendas.index(watched_agenda)].watched = True
                else:
                    watched_agenda.score = watched_agenda.member_score(member)
                    watched_agenda.watched = True
                    agendas.append(watched_agenda)
        agendas.sort(key=attrgetter('score'), reverse=True)
        
        factional_discipline = VoteAction.objects.filter(member = member, against_party=True)

        general_discipline_params = { 'member' : member }
        is_coalition = member.current_party.is_coalition
        if is_coalition:
            general_discipline_params['against_coalition'] = True
        else:
            general_discipline_params['against_opposition'] = True
        general_discipline = VoteAction.objects.filter(**general_discipline_params)
        
        context.update({'watched_member': watched,
                'actions': actor_stream(member).filter(verb__in=verbs),
                'verbs_form': verbs_form,
                'bills_statistics':bills_statistics,
                'bills_tags':bills_tags,
                'agendas':agendas,
                'presence':presence,
                'factional_discipline':factional_discipline,
                'general_discipline':general_discipline,
               })
        return context
예제 #5
0
    def get_context_data (self, **kwargs):
        context = super(MemberDetailView, self).get_context_data(**kwargs)
        member = context['object']
        if self.request.user.is_authenticated():
            p = self.request.user.get_profile()
            watched = member in p.members
            cached_context = None
        else:
            watched = False
            cached_context = cache.get('mk_%d' % member.id, None)

        if cached_context is None:
            verbs = None
            if 'verbs' in self.request.GET:
                verbs_form = VerbsForm(self.request.GET)
                if verbs_form.is_valid():
                    verbs = verbs_form.cleaned_data['verbs']
            if verbs==None:
                verbs = ('proposed', 'posted')
                verbs_form = VerbsForm({'verbs': verbs})

            presence = {}
            self.calc_percentile(member, presence,
                                 'average_weekly_presence_hours',
                                 'average_weekly_presence_hours',
                                 'average_weekly_presence_hours_percentile' )
            self.calc_percentile(member, presence,
                                 'average_monthly_committee_presence',
                                 'average_monthly_committee_presence',
                                 'average_monthly_committee_presence_percentile' )

            bills_statistics = {}
            self.calc_bill_stats(member,bills_statistics,'proposed')
            self.calc_bill_stats(member,bills_statistics,'pre')
            self.calc_bill_stats(member,bills_statistics,'first')
            self.calc_bill_stats(member,bills_statistics,'approved')

            bills_tags = Tag.objects.usage_for_queryset(member.bills.all(),counts=True)
            #bills_tags.sort(key=lambda x:x.count,reverse=True)
            bills_tags = calculate_cloud(bills_tags)

            if self.request.user.is_authenticated():
                agendas = Agenda.objects.get_selected_for_instance(member, user=self.request.user, top=3, bottom=3)
            else:
                agendas = Agenda.objects.get_selected_for_instance(member, user=None, top=3, bottom=3)
            agendas = agendas['top'] + agendas['bottom']
            for agenda in agendas:
                agenda.watched=False
            if self.request.user.is_authenticated():
                watched_agendas = self.request.user.get_profile().agendas
                for watched_agenda in watched_agendas:
                    if watched_agenda in agendas:
                        agendas[agendas.index(watched_agenda)].watched = True
                    else:
                        watched_agenda.score = watched_agenda.member_score(member)
                        watched_agenda.watched = True
                        agendas.append(watched_agenda)
            agendas.sort(key=attrgetter('score'), reverse=True)

            factional_discipline = VoteAction.objects.filter(member = member, against_party=True)

            votes_against_own_bills = VoteAction.objects.filter(member=member,
                                                                against_own_bill=True)

            general_discipline_params = { 'member' : member }
            is_coalition = member.current_party.is_coalition
            if is_coalition:
                general_discipline_params['against_coalition'] = True
            else:
                general_discipline_params['against_opposition'] = True
            general_discipline = VoteAction.objects.filter(**general_discipline_params)

            about_videos=get_videos_queryset(member,group='about')[:1]
            if len(about_videos):
                about_video=about_videos[0]
                about_video_embed_link=about_video.embed_link
                about_video_image_link=about_video.image_link
            else:
                about_video_embed_link=''
                about_video_image_link=''

            related_videos=get_videos_queryset(member,group='related')
            related_videos=related_videos.filter(
                Q(published__gt=date.today()-timedelta(days=30))
                | Q(sticky=True)
            ).order_by('sticky').order_by('-published')[:5]

            actions = actor_stream(member).filter(verb__in=verbs)
            for a in actions:
                a.actor = member
            cached_context = {'watched_member': watched,
                'actions':actions,
                'verbs_form': verbs_form,
                'bills_statistics':bills_statistics,
                'bills_tags':bills_tags,
                'agendas':agendas,
                'presence':presence,
                'factional_discipline':factional_discipline,
                'votes_against_own_bills':votes_against_own_bills,
                'general_discipline':general_discipline,
                'about_video_embed_link':about_video_embed_link,
                'about_video_image_link':about_video_image_link,
                'related_videos':related_videos,
                'num_related_videos':related_videos.count()
               }
            if not self.request.user.is_authenticated():
                cache.set('mk_%d' % member.id, cached_context, settings.LONG_CACHE_TIME)
        context.update(cached_context)
        return context
예제 #6
0
    def get_context_data (self, **kwargs):
        context = super(MemberDetailView, self).get_context_data(**kwargs)
        member = context['object']
        verbs = None
        if 'verbs' in self.request.GET:
            verbs_form = VerbsForm(self.request.GET)
            if verbs_form.is_valid():
                verbs = verbs_form.cleaned_data['verbs']
        if verbs==None:
            verbs = ('proposed', 'posted')
            verbs_form = VerbsForm({'verbs': verbs})
        if self.request.user.is_authenticated():
            p = self.request.user.get_profile()
            watched = member in p.members
            cached_context = None
        else:
            watched = False
            cached_context = cache.get('mk_%d_%s' % (member.id,
                                                     '_'.join(verbs)))

        if cached_context is None:
            presence = {}
            self.calc_percentile(member, presence,
                                 'average_weekly_presence_hours',
                                 'average_weekly_presence_hours',
                                 'average_weekly_presence_hours_percentile' )
            self.calc_percentile(member, presence,
                                 'average_monthly_committee_presence',
                                 'average_monthly_committee_presence',
                                 'average_monthly_committee_presence_percentile' )

            bills_statistics = {}
            self.calc_bill_stats(member,bills_statistics,'proposed')
            self.calc_bill_stats(member,bills_statistics,'pre')
            self.calc_bill_stats(member,bills_statistics,'first')
            self.calc_bill_stats(member,bills_statistics,'approved')

            bills_tags = Tag.objects.usage_for_queryset(member.bills.all(),counts=True)
            #bills_tags.sort(key=lambda x:x.count,reverse=True)
            bills_tags = calculate_cloud(bills_tags)

            if self.request.user.is_authenticated():
                agendas = Agenda.objects.get_selected_for_instance(member, user=self.request.user, top=3, bottom=3)
            else:
                agendas = Agenda.objects.get_selected_for_instance(member, user=None, top=3, bottom=3)
            agendas = agendas['top'] + agendas['bottom']
            for agenda in agendas:
                agenda.watched=False
            if self.request.user.is_authenticated():
                watched_agendas = self.request.user.get_profile().agendas
                for watched_agenda in watched_agendas:
                    if watched_agenda in agendas:
                        agendas[agendas.index(watched_agenda)].watched = True
                    else:
                        watched_agenda.score = watched_agenda.member_score(member)
                        watched_agenda.watched = True
                        agendas.append(watched_agenda)
            agendas.sort(key=attrgetter('score'), reverse=True)

            factional_discipline = VoteAction.objects.select_related(
                'vote').filter(member = member, against_party=True)

            votes_against_own_bills = VoteAction.objects.select_related(
                'vote').filter(member=member, against_own_bill=True)

            general_discipline_params = { 'member' : member }
            is_coalition = member.current_party.is_coalition
            if is_coalition:
                general_discipline_params['against_coalition'] = True
            else:
                general_discipline_params['against_opposition'] = True
            general_discipline = VoteAction.objects.filter(
                **general_discipline_params).select_related('vote')

            about_videos=get_videos_queryset(member,group='about')[:1]
            if len(about_videos):
                about_video=about_videos[0]
                about_video_embed_link=about_video.embed_link
                about_video_image_link=about_video.image_link
            else:
                about_video_embed_link=''
                about_video_image_link=''

            related_videos=get_videos_queryset(member,group='related')
            related_videos=related_videos.filter(
                Q(published__gt=date.today()-timedelta(days=30))
                | Q(sticky=True)
            ).order_by('sticky').order_by('-published')[:5]

            actions = actor_stream(member).filter(
                verb__in=verbs)
            for a in actions:
                a.actor = member
            cached_context = {'watched_member': watched,
                'actions':actions,
                'verbs_form': verbs_form,
                'bills_statistics':bills_statistics,
                'bills_tags':bills_tags,
                'agendas':agendas,
                'presence':presence,
                'factional_discipline':factional_discipline,
                'votes_against_own_bills':votes_against_own_bills,
                'general_discipline':general_discipline,
                'about_video_embed_link':about_video_embed_link,
                'about_video_image_link':about_video_image_link,
                'related_videos':related_videos,
                'num_related_videos':related_videos.count()
               }
            if not self.request.user.is_authenticated():
                cache.set('mk_%d_%s' % (member.id, '_'.join(verbs)),
                                        cached_context,
                                        settings.LONG_CACHE_TIME)
        context.update(cached_context)
        return context
예제 #7
0
    def get_context_data(self, **kwargs):
        context = super(MemberDetailView, self).get_context_data(**kwargs)
        member = context['object']
        if self.request.user.is_authenticated():
            p = self.request.user.get_profile()
            watched = member in p.members
        else:
            watched = False

        verbs = None
        if 'verbs' in self.request.GET:
            verbs_form = VerbsForm(self.request.GET)
            if verbs_form.is_valid():
                verbs = verbs_form.cleaned_data['verbs']
        if verbs == None:
            verbs = ('proposed', 'posted')
            verbs_form = VerbsForm({'verbs': verbs})

        presence = {}
        self.calc_percentile(member, presence, 'average_weekly_presence_hours',
                             'average_weekly_presence_hours',
                             'average_weekly_presence_hours_percentile')
        self.calc_percentile(member, presence,
                             'average_monthly_committee_presence',
                             'average_monthly_committee_presence',
                             'average_monthly_committee_presence_percentile')

        bills_statistics = {}
        self.calc_bill_stats(member, bills_statistics, 'proposed')
        self.calc_bill_stats(member, bills_statistics, 'pre')
        self.calc_bill_stats(member, bills_statistics, 'first')
        self.calc_bill_stats(member, bills_statistics, 'approved')

        bills_tags = Tag.objects.usage_for_queryset(member.bills.all(),
                                                    counts=True)
        #bills_tags.sort(key=lambda x:x.count,reverse=True)
        bills_tags = calculate_cloud(bills_tags)

        if self.request.user.is_authenticated():
            agendas = Agenda.objects.get_selected_for_instance(
                member, user=self.request.user, top=3, bottom=3)
        else:
            agendas = Agenda.objects.get_selected_for_instance(member,
                                                               user=None,
                                                               top=3,
                                                               bottom=3)
        agendas = agendas['top'] + agendas['bottom']
        for agenda in agendas:
            agenda.watched = False
        if self.request.user.is_authenticated():
            watched_agendas = self.request.user.get_profile().agendas
            for watched_agenda in watched_agendas:
                if watched_agenda in agendas:
                    agendas[agendas.index(watched_agenda)].watched = True
                else:
                    watched_agenda.score = watched_agenda.member_score(member)
                    watched_agenda.watched = True
                    agendas.append(watched_agenda)
        agendas.sort(key=attrgetter('score'), reverse=True)

        factional_discipline = VoteAction.objects.filter(member=member,
                                                         against_party=True)

        general_discipline_params = {'member': member}
        is_coalition = member.current_party.is_coalition
        if is_coalition:
            general_discipline_params['against_coalition'] = True
        else:
            general_discipline_params['against_opposition'] = True
        general_discipline = VoteAction.objects.filter(
            **general_discipline_params)

        context.update({
            'watched_member': watched,
            'actions': actor_stream(member).filter(verb__in=verbs),
            'verbs_form': verbs_form,
            'bills_statistics': bills_statistics,
            'bills_tags': bills_tags,
            'agendas': agendas,
            'presence': presence,
            'factional_discipline': factional_discipline,
            'general_discipline': general_discipline,
        })
        return context