Exemple #1
0
    def form_valid(self, form):
        # builder = MatrixBuilder()
        categories = form.cleaned_data['categories']
        # builder.set_electors_categories(categories)
        # r = builder.get_result_as_array()
        context = self.get_context_data()
        context['area'] = form.cleaned_data['area']
        context['categories'] = categories
        election_types_cache_key = 'election_types'
        election_types = cache.get(election_types_cache_key)
        if election_types is None:
            election_types = [{
                'id': k,
                'label': v
            } for k, v in Candidate.get_possible_election_kinds().items()]
            cache.set(election_types_cache_key, election_types)

        context['election_types'] = election_types
        lgbt_descriptions_cache_key = 'lgbt_descriptions_'
        lgbt_descriptions = cache.get(lgbt_descriptions_cache_key)
        if lgbt_descriptions is None:
            lgbt_descriptions = [{
                'id': "lgbt_" + str(lgbt_desc.id),
                'label': lgbt_desc.name
            } for lgbt_desc in LGBTQDescription.objects.all()]
            cache.set(lgbt_descriptions_cache_key, lgbt_descriptions)
        context['lgbt_descriptions'] = lgbt_descriptions
        return render(self.request, self.success_template, context)
 def test_get_possible_election_kinds(self):
     Election.objects.all().delete()
     e = Election.objects.create(name="Chefe da todas as coisas no universo")
     candidate = Candidate.objects.create(name="Candidate 1",
                                          cpf='1230',
                                          nome_completo=u'Candidato uno',
                                          numero='190000000560',
                                          race="preta",
                                          original_email='*****@*****.**',
                                          bio='blablablabla', 
                                          lgbt=True,
                                          candidatura_coletiva=True,
                                          renovacao_politica='Partido Perrito',
                                          email_repeated=False)
     outro_can = Candidate.objects.create(name="Candidate 1",
                                          cpf='1231',
                                          nome_completo=u'Candidato uno',
                                          numero='190000000560',
                                          race="preta",
                                          original_email='*****@*****.**',
                                          bio='blablablabla', 
                                          lgbt=True,
                                          candidatura_coletiva=True,
                                          renovacao_politica='Partido Perrito',
                                          email_repeated=False)
     e.candidates.add(candidate)
     l = Candidate.get_possible_election_kinds()
     self.assertTrue(l)
     self.assertEquals(l[l.keys()[0]], e.name)
     self.assertEquals(candidate.election_kind, l.keys()[0])
     self.assertFalse(outro_can.election_kind)
 def test_get_deputado_distrital_as_the_estadual(self):
     Election.objects.all().delete()
     e1 = Election.objects.create(name="Deputada/o Estadual")
     e2 = Election.objects.create(name="Deputada/o Distrital")
     candidate = Candidate.objects.create(name="Candidate 1",
                                          cpf='1230',
                                          nome_completo=u'Candidato uno',
                                          numero='190000000560',
                                          race="preta",
                                          original_email='*****@*****.**',
                                          bio='blablablabla', 
                                          lgbt=True,
                                          candidatura_coletiva=True,
                                          renovacao_politica='Partido Perrito',
                                          email_repeated=False)
     e1.candidates.add(candidate)
     l = Candidate.get_possible_election_kinds()
     self.assertEquals(len(l), 1)
     self.assertEquals(l[l.keys()[0]], e1.name)
    def form_valid(self, form):
        # builder = MatrixBuilder()
        categories = form.cleaned_data['categories']
        # builder.set_electors_categories(categories)
        # r = builder.get_result_as_array()
        context = self.get_context_data()
        context['area'] = form.cleaned_data['area']
        context['categories'] = categories
        election_types_cache_key = 'election_types'
        election_types = cache.get(election_types_cache_key)
        if election_types is None:
            election_types = [{'id': k, 'label': v} for k, v in Candidate.get_possible_election_kinds().items()]
            cache.set(election_types_cache_key, election_types)

        context['election_types'] = election_types
        lgbt_descriptions_cache_key = 'lgbt_descriptions_'
        lgbt_descriptions = cache.get(lgbt_descriptions_cache_key)
        if lgbt_descriptions is None:
            lgbt_descriptions = [{'id': "lgbt_" + str(lgbt_desc.id),
                                  'label': lgbt_desc.name}  for lgbt_desc in LGBTQDescription.objects.all()]
            cache.set(lgbt_descriptions_cache_key, lgbt_descriptions)
        context['lgbt_descriptions'] = lgbt_descriptions
        return render(self.request, self.success_template, context)