Beispiel #1
0
    def get_context_data(self, **kwargs):
        ctx = super(BaseMainView, self).get_context_data(**kwargs)

        ctx.update(main_page_context())

        self.location = Location.objects.country()

        self.location_query = get_roles_query(self.location)

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

        self.tabs = [
            ('main', u'Что делать?', reverse('main'), 'main/view.html'),
            ('wall', u'Комментарии: %i' % self.info['comments']['count'], reverse('wall'), 'locations/wall.html'),
            ('participants', u'Участники', reverse('participants'), 'locations/participants.html'),
            ('elections', u'Выборы', reverse('elections'), 'locations/elections.html'),
        ]

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

        ctx.update({
            'info': self.info,
            'show_date': True,
        })

        #self.data_location = ctx['data_location']

        ctx.update(self.update_context())
        return ctx
Beispiel #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
Beispiel #3
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)

        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
Beispiel #4
0
def participants_context(view):
    role_type = view.request.GET.get('type', 'voter' if view.location.is_uik() else '')
    if not role_type in ROLE_TYPES:
        role_type = 'voter' if view.location.is_uik() else ''

    # TODO: use pagination
    if role_type == '':
        query = view.location_query
        if view.location.date:
            related = view.location.related()
            query = get_roles_query(related.get(None, view.location))

        profile_ids = EntityLocation.objects.filter(query).values_list('entity_id', flat=True).distinct()[:100]
        profiles = Profile.objects.filter(id__in=profile_ids, user__is_active=True)
    else:
        roles = Role.objects.filter(view.location_query).filter(type=role_type).select_related('profile').distinct()[:100]
        profiles = sorted(set(role.profile for role in roles), key=lambda profile: unicode(profile))

    return {
        'participants': profiles,
        'selected_role_type': role_type,
    }
Beispiel #5
0
    def get_context_data(self, **kwargs):
        ctx = super(ListSearchView, self).get_context_data(**kwargs)

        query = get_roles_query(self.location)
        if self.role_type:
            query = query & Q(type=self.role_type)

        # TODO: when role_type='' query is not correct
        profile_ids = Role.objects.filter(query).values_list('user', flat=True)
        people = Profile.objects.filter(id__in=profile_ids) \
                .exclude(user__email='', user__is_active=False, id__in=self.inactive_ids) \
                .only('username', 'show_name', 'first_name', 'last_name').order_by('username')

        result_count = len(people)

        # TODO: temporary limit until pagination is introduced
        people = people[:100]

        ctx.update({
            'people': people,
            'result_count': result_count,
        })
        return ctx