Ejemplo n.º 1
0
 def test_get_register_form(self):
     template_str = get_template('login/user_register.html')
     form = RegistrationForm()
     rendered_template = template_str.render(Context({'form': form}))
     template = Template(
         "{% load votainteligente_extras %}{% user_register %}")
     self.assertEqual(template.render(Context({})), rendered_template)
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super(HomeView, self).get_context_data(**kwargs)
        context['form'] = ElectionSearchByTagsForm()

        featured_elections = cache.get('featured_elections')
        if featured_elections is None:
            featured_elections = Election.objects.filter(highlighted=True)
            cache.set('featured_elections', featured_elections, 600)
        context['featured_elections'] = featured_elections

        context['searchable_elections_enabled'] = True
        context['register_new_form'] = RegistrationForm()
        context['login_form'] = AuthenticationForm()
        context['group_login_form'] = GroupCreationForm()
        total_proposals = cache.get('total_proposals')
        if total_proposals is None:
            total_proposals = PopularProposal.objects.count()
            cache.set('total_proposals', total_proposals, 600)
        context['total_proposals'] = total_proposals
        proposals_with_likers = cache.get('proposals_with_likers')
        if proposals_with_likers is None:
            proposals_with_likers = PopularProposal.ordered.by_likers()[:9]
            cache.set('proposals_with_likers', proposals_with_likers, 600)
        context['proposals_with_likers'] = proposals_with_likers
        return context
Ejemplo n.º 3
0
 def test_variable_is_field(self):
     template = Template("{% load votainteligente_extras %}{% if field|is_field  %}si{% else %}no{% endif %}")
     field = forms.CharField(required=False, label='Busca tu comuna')
     self.assertEqual(template.render(Context({'field': field})), 'si')
     data = {'username': '******',
             'password1': 'feroz',
             'password2': 'feroz',
             'email': '*****@*****.**'}
     form = RegistrationForm(data=data)
     field = form.fields['username']
     self.assertEqual(template.render(Context({'field': field})), 'si')
     self.assertEqual(template.render(Context({'field': 'esto es un string'})), 'no')
Ejemplo n.º 4
0
    def get_context_data(self, **kwargs):
        context = super(HomeView, self).get_context_data(**kwargs)
        context['form'] = ElectionSearchByTagsForm()

        featured_elections = cache.get('featured_elections')
        if featured_elections is None:
            featured_elections = Election.objects.filter(highlighted=True)
            cache.set('featured_elections', featured_elections, 600)
        context['featured_elections'] = featured_elections

        context['searchable_elections_enabled'] = True
        context['register_new_form'] = RegistrationForm()
        context['login_form'] = AuthenticationForm()
        context['group_login_form'] = GroupCreationForm()
        total_proposals = cache.get('total_proposals')
        if total_proposals is None:
            total_proposals = PopularProposal.objects.count()
            cache.set('total_proposals', total_proposals, 600)
        context['total_proposals'] = total_proposals
        proposals_with_likers = cache.get('proposals_with_likers')
        if proposals_with_likers is None:
            proposals_with_likers = PopularProposal.ordered.by_likers()[:9]
            cache.set('proposals_with_likers', proposals_with_likers, 600)
        context['proposals_with_likers'] = proposals_with_likers
        featured_proposals = cache.get('featured_proposals')
        if featured_proposals is None:
            featured_proposals = PopularProposal.objects.filter(
                featured=True).filter(
                    content_type__app_label="popular_proposal")
            cache.set('featured_proposals', featured_proposals, 600)
        context['featured_proposals'] = featured_proposals
        featured_candidates = cache.get('featured_candidates')
        if featured_candidates is None:
            featured_candidates = Candidate.objects.filter(
                commitments__isnull=False).filter(
                    elections__name="Presidencia")
            cache.set('featured_candidates', featured_candidates)
        context['candidates'] = featured_candidates
        return context
Ejemplo n.º 5
0
def user_register():
    form = RegistrationForm()
    return {'form': form}