예제 #1
0
def main_page_context():
    inactive_ids = UserMap.objects.filter(verified=False).values_list('user', flat=True)
    total_counter = User.objects.exclude(email='').filter(is_active=True) \
            .exclude(id__in=inactive_ids).count()

    cik_protocols_by_location = dict((p.location_id, p) for p in Protocol.objects.from_cik() \
            .filter(location__region=None))

    protocols_by_location = dict((p.location_id, p) \
            for p in Protocol.objects.verified().filter(location__region=None))

    results_protocol = Protocol(p9=0, p10=0, p19=0, p20=0, p21=0, p22=0, p23=0)
    for loc_id in cik_protocols_by_location:
        #if protocols_by_location[loc_id].p10 == 0:
        #    p = cik_protocols_by_location[loc_id]
        #else:
        p = protocols_by_location[loc_id]

        for field in ('p9', 'p10', 'p19', 'p20', 'p21', 'p22', 'p23'):
            setattr(results_protocol, field, getattr(results_protocol, field)+getattr(p, field))

    protocol_data = results_table_data([results_protocol])

    sub_regions = regions_list()
    return {
        'counters': get_roles_counters(None),
        'locations': sub_regions,
        'sub_regions': sub_regions,
        'organizations': OrganizationCoverage.objects.organizations_at_location(None),
        'total_counter': total_counter,
        'protocol_data': protocol_data,

        'disqus_identifier': 'main',
    }
예제 #2
0
    def get_context_data(self, **kwargs):
        ctx = super(BaseLocationView, self).get_context_data(**kwargs)

        loc_id = int(kwargs['loc_id'])
        try:
            self.location = location = Location.objects.select_related().get(id=loc_id)
        except Location.DoesNotExist:
            raise Http404(u'Избирательный округ не найден')

        # TODO: different query generators might be needed for different data types
        self.location_query = get_roles_query(location)

        dialog = self.request.GET.get('dialog', '')
        if not dialog in ROLE_TYPES and not dialog in ('web_observer',):
            dialog = ''

        signed_up_in_uik = False
        if self.request.user.is_authenticated():
            voter_roles = Role.objects.filter(user=self.request.profile, type='voter').select_related('location')
            if voter_roles:
                signed_up_in_uik = voter_roles[0].location.is_uik()

        counters = get_roles_counters(location)

        verified_protocols = list(Protocol.objects.verified().filter(location=location))

        try:
            cik_protocols = [Protocol.objects.from_cik().get(location=location)]
        except Protocol.DoesNotExist:
            cik_protocols = []

        cik_data = results_table_data(cik_protocols)
        protocol_data = results_table_data(verified_protocols)

        ctx.update({
            'loc_id': kwargs['loc_id'],
            'view': kwargs['view'],
            'current_location': location,

            'locations': regions_list(),
            'sub_regions': regions_list(location),

            'dialog': dialog,
            'signed_up_in_uik': signed_up_in_uik,
            'disqus_identifier': 'location/' + str(location.id),

            'counters': counters,

            'add_commission_member_form': CommissionMemberForm(),
            'become_web_observer_form': WebObserverForm(),

            'verified_protocols': verified_protocols,
            'protocol_data': protocol_data,
            'cik_data': cik_data,
        })

        ctx.update(self.update_context())
        return ctx
예제 #3
0
파일: views.py 프로젝트: mikpanko/elections
def main_page_context():
    total_counter = User.objects.filter(is_active=True).count()

    country = Location.objects.country()
    sub_regions = subregion_list(country)
    return {
        'counters': get_roles_counters(Location.objects.country()),
        'total_counter': total_counter,
    }
예제 #4
0
파일: views.py 프로젝트: mikpanko/elections
    def get_context_data(self, **kwargs):
        ctx = super(BaseLocationView, self).get_context_data(**kwargs)

        loc_id = int(kwargs['loc_id'])
        try:
            self.location = location = Location.objects.select_related().get(id=loc_id)
        except Location.DoesNotExist:
            raise Http404(u'Избирательный округ не найден')

        # TODO: different query generators might be needed for different data types
        self.location_query = get_roles_query(location)

        self.info = location.info(related=True)

        self.tabs = [
            ('wall', u'Комментарии: %i' % self.info['comments']['count'], reverse('location_wall', args=[location.id]), 'locations/wall.html'),
            ('participants', u'Участники', reverse('location_participants', args=[location.id]), 'locations/participants.html'),
            ('info', u'Информация', reverse('location_info', args=[location.id]), 'locations/info.html'),
            ('elections', u'Выборы', reverse('location_elections', args=[location.id]), 'locations/elections.html'),
            ('violations', u'Нарушения', reverse('location_violations', args=[location.id]), 'locations/violations.html'),
        ]

        ctx.update(entity_tabs_view(self))
        ctx.update(breadcrumbs_context(location))

        self.data_location = ctx['data_location']

        ctx.update({
            'loc_id': kwargs['loc_id'],

            'info': self.info,
            'show_date': True,

            'counters': get_roles_counters(location),

            'add_commission_member_form': CommissionMemberForm(),
            'become_web_observer_form': WebObserverForm(),

            'ROLE_CHOICES': ROLE_CHOICES_PLURAL,
        })

        ctx.update(self.update_context())
        return ctx