Skip to content

Commit

Permalink
Todo redirecciona a completa tu perfil. Closes #570.
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Álvarez committed Sep 9, 2016
1 parent 7a83d8e commit d8c97d0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
29 changes: 19 additions & 10 deletions backend_candidate/tests/candidacy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_instanciate_candidacy(self):
self.assertTrue(candidacy.created)
self.assertTrue(candidacy.updated)


def test_user_has_candidacy(self):
self.assertFalse(is_candidate(self.feli))
candidacy = Candidacy.objects.create(user=self.feli,
Expand All @@ -92,12 +93,15 @@ def test_get_candidate_home(self):
password='alvarez')
response = self.client.get(url)
self.assertEquals(response.status_code, 404)
candidacy = Candidacy.objects.create(user=self.feli,
candidate=self.candidate
)
Candidacy.objects.create(user=self.feli,
candidate=self.candidate
)

response = self.client.get(url)
self.assertEquals(response.status_code, 200)
self.assertIn(candidacy, response.context['candidacies'])
profile_url = reverse('backend_candidate:complete_profile',
kwargs={'slug': self.candidate.election.slug,
'candidate_id': self.candidate.id})
self.assertRedirects(response, profile_url)

def test_proposals_with_a_resolution(self):

Expand Down Expand Up @@ -244,12 +248,14 @@ def test_candidacy_redirect_view(self):
self.assertRedirects(response, login_url)
self.client.login(username=self.feli.username, password='alvarez')
response = self.client.get(url)
candidate_home = reverse('backend_candidate:home')
self.assertRedirects(response, candidate_home)
self.assertTrue(Candidacy.objects.filter(candidate=self.candidate,
user=self.feli))
candidacy = Candidacy.objects.get(candidate=self.candidate,
user=self.feli)
profile_url = reverse('backend_candidate:complete_profile',
kwargs={'slug': candidacy.candidate.election.slug,
'candidate_id': candidacy.candidate.id})
self.assertRedirects(response, profile_url)
self.assertTrue(Candidacy.objects.filter(candidate=self.candidate,
user=self.feli))
contact = CandidacyContact.objects.get(id=contact.id)

self.assertEquals(contact.candidacy, candidacy)
Expand Down Expand Up @@ -364,7 +370,10 @@ def test_login_candidate_marks_her_him_as_contacted(self):
self.assertRedirects(response, change_password_url)

response = self.client.get(home_url)
self.assertEquals(response.status_code, 200)
profile_url = reverse('backend_candidate:complete_profile',
kwargs={'slug': contact.candidacy.candidate.election.slug,
'candidate_id': contact.candidacy.candidate.id})
self.assertRedirects(response, profile_url)

@override_settings(MAX_AMOUNT_OF_MAILS_TO_CANDIDATE=3)
def test_send_candidate_maximum_amount_of_times(self):
Expand Down
15 changes: 13 additions & 2 deletions backend_candidate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ def dispatch(self, request, *args, **kwargs):
**kwargs)


class HomeView(BackendCandidateBase, TemplateView):
class HomeView(BackendCandidateBase, RedirectView):
template_name = "backend_candidate/home.html"

def get_context_data(self, *args, **kwargs):
context = super(HomeView, self).get_context_data(*args, **kwargs)
context['candidacies'] = self.user.candidacies.all()
return context

def get_redirect_url(self, *args, **kwargs):
candidacy = self.user.candidacies.first()
profile_url = reverse('backend_candidate:complete_profile',
kwargs={'slug': candidacy.candidate.election.slug,
'candidate_id': candidacy.candidate.id})
return profile_url


class CompleteMediaNaranjaView(FormView):
template_name = 'backend_candidate/complete_12_naranja.html'
Expand Down Expand Up @@ -106,7 +113,11 @@ def get_redirect_url(self, *args, **kwargs):
self.contact.candidacy = candidacy
self.contact.used_by_candidate = True
self.contact.save()
return reverse('backend_candidate:home')
candidacy = self.request.user.candidacies.first()
profile_url = reverse('backend_candidate:complete_profile',
kwargs={'slug': candidacy.candidate.election.slug,
'candidate_id': candidacy.candidate.id})
return profile_url


form_class = get_candidate_profile_form_class()
Expand Down

0 comments on commit d8c97d0

Please sign in to comment.