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
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', }
def get_context_data(self, **kwargs): ctx = super(BaseProfileView, self).get_context_data(**kwargs) user = self.get_user() profile = user.get_profile() ctx.update({ 'profile_user': user, 'profile': profile, 'roles': profile.roles.select_related('location').order_by('type'), 'locations': regions_list(), 'links': list(profile.links.all().select_related()), 'contacts': list(profile.contacts.all()) if user.is_authenticated() else [], 'have_in_contacts': list(profile.have_in_contacts.all()), 'profile_view': self.profile_view, }) return ctx
def get_context_data(self, **kwargs): ctx = super(LocationView, self).get_context_data(**kwargs) loc_id = int(kwargs['loc_id']) try: location = Location.objects.select_related().get(id=loc_id) except Location.DoesNotExist: raise Http404(u'Избирательный округ не найден') # Get the list of role participants = {} # {role_type: [users]} query = Q(location=location) if not location.tik: query |= Q(location__tik=location) if location.region else Q(location__region=location) for role in Role.objects.filter(query).select_related('user'): participants.setdefault(role.type, []).append(role.user) # Get sub-regions sub_regions = [] voter_count = 0 if location.region is None: for loc in Location.objects.filter(region=location, tik=None).only('id', 'name').order_by('name'): sub_regions.append((loc.id, loc.name)) voter_count = Role.objects.filter(type='voter', location__region=location).count() elif location.tik is None: for loc in Location.objects.filter(tik=location).only('id', 'name').order_by('name'): sub_regions.append((loc.id, loc.name)) voter_count = Role.objects.filter(type='voter', location__tik=location).count() ctx.update({ 'loc_id': kwargs['loc_id'], 'view': kwargs['view'], 'current_location': location, 'participants': participants, 'links': list(Link.objects.filter(location=location)), 'locations': regions_list(), 'is_voter_here': self.request.user.is_authenticated() and any(self.request.user==voter.user for voter in participants.get('voter', [])), 'sub_regions': sub_regions, 'voter_count': voter_count, 'organizations': OrganizationCoverage.objects.organizations_at_location(location), }) return ctx
def __init__(self, *args, **kwargs): """ if user_id is passed - loginza was used for registration """ if 'user_map' in kwargs: # registred with loginza self.user_map = kwargs['user_map'] del kwargs['user_map'] self.user_id = self.user_map.user.id else: self.user_id = None super(BaseRegistrationForm, self).__init__(*args, **kwargs) if self.user_id: self.user_data = json.loads(self.user_map.identity.data) if self.user_data.get('email'): # TODO: if user with this email is already registered, it causes a problem self.fields['email'].widget = forms.HiddenInput() self.fields['region'].widget.choices = regions_list()
def main(request): voter_count = Role.objects.filter(type='voter').count() """ if voter_count%10 == 1: ending = u'ь' elif voter_count%10 in (2, 3, 4): ending = u'я' else: ending = u'ей' """ sub_regions = regions_list() context = { 'voter_count': voter_count, #'ending': ending, 'locations': sub_regions, 'sub_regions': sub_regions, 'organizations': OrganizationCoverage.objects.organizations_at_location(None), } return render_to_response('main.html', context_instance=RequestContext(request, context))
def get_context_data(self, **kwargs): ctx = super(BaseSearchView, self).get_context_data(**kwargs) loc_id = '' for name in ('uik', 'tik', 'region'): loc_id = self.request.GET.get(name, '') if loc_id: break try: loc_id = int(loc_id) except ValueError: self.location = None else: try: self.location = Location.objects.get(id=loc_id) except Location.DoesNotExist: self.location = None role_form = RoleTypeForm(self.request.GET) if role_form.is_valid(): self.role_type = role_form.cleaned_data['type'] else: self.role_type = '' self.inactive_ids = UserMap.objects.filter(verified=False).values_list('user', flat=True) ctx.update({ 'tab': self.tab, 'locations': regions_list(), 'location_path': str(self.location.path()) if self.location else '[]', 'role_form': role_form, 'role_name': ROLE_TYPES[self.role_type] if self.role_type else '', 'name': 'search', # requiered to highlight main menu item }) return ctx
def __init__(self, *args, **kwargs): super(CreateOrganizationForm, self).__init__(*args, **kwargs) self.fields["region"].widget.choices = regions_list()
def __init__(self, *args, **kwargs): super(ProtocolForm, self).__init__(*args, **kwargs) self.fields['region'].widget.choices = regions_list() for field in ('chairman', 'assistant', 'secretary', 'sign_time', 'complaints'): self.fields[field].required = True
def __init__(self, *args, **kwargs): super(ViolationForm, self).__init__(*args, **kwargs) self.fields['region'].widget.choices = regions_list()