Exemplo n.º 1
0
    def get_context_data(self, **kwargs):
        ctx = super(ResultsTableSearchView, self).get_context_data(**kwargs)

        # TODO: use regions_list
        if not self.location:
            sub_regions = Location.objects.filter(region=None).order_by('name')
        elif self.location.is_region():
            sub_regions = Location.objects.filter(region=self.location, tik=None).order_by('name')
        elif self.location.is_tik():
            sub_regions = Location.objects.filter(tik=self.location).order_by('name')
        elif self.location.is_uik():
            sub_regions = []

        cik_protocols = Protocol.objects.from_cik().filter(location__in=sub_regions)

        if self.location and self.location.is_tik():
            observer_protocols = list(Protocol.objects.from_users().filter(location__in=sub_regions).filter(verified=True))
        else:
            observer_protocols = list(Protocol.objects.verified().filter(location__in=sub_regions))

        lines = []
        for location in sub_regions:
            lines.append({
                'location': location,
                'cik': results_table_data(filter(lambda p: p.location_id==location.id, cik_protocols), False),
                'observers': results_table_data(filter(lambda p: p.location_id==location.id, observer_protocols), False),
            })

        ctx.update({
            'lines': lines,
        })
        return ctx
Exemplo n.º 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
Exemplo n.º 3
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',
    }