Repository: ciudadanointeligente/votainteligente-portal-electoral

Issue:
No notifica en wizard full que llega un mail!!!
<!---
@huboard:{"order":470.04699999999997,"milestone_order":481,"custom_state":""}
-->



Discussion:

Resolving patch:
diff --git a/popular_proposal/views.py b/popular_proposal/views.py
--- a/popular_proposal/views.py
+++ b/popular_proposal/views.py
@@ -75,6 +75,10 @@ class SubscriptionView(FormView):
     @method_decorator(login_required)
     def dispatch(self, *args, **kwargs):
         self.proposal = get_object_or_404(PopularProposal, id=self.kwargs['pk'])
+        if self.request.method == 'GET':
+            self.next_url = self.request.GET.get('next', None)
+        elif self.request.method == 'POST':
+            self.next_url = self.request.POST.get('next', None)
         return super(SubscriptionView, self).dispatch(*args, **kwargs)
 
     def get_form_kwargs(self):
@@ -86,9 +90,13 @@ def get_form_kwargs(self):
     def get_context_data(self, **kwargs):
         kwargs = super(SubscriptionView, self).get_context_data(**kwargs)
         kwargs['proposal'] = self.proposal
+        if self.next_url:
+            kwargs['next'] = self.next_url
         return kwargs
 
     def get_success_url(self):
+        if self.next_url:
+            return self.next_url
         return reverse('area', kwargs={'slug': self.proposal.area.id})
 
     def form_valid(self, form):
@@ -204,6 +212,7 @@ def done(self, form_list, **kwargs):
         temporary_data = ProposalTemporaryData.objects.create(proposer=self.request.user,
                                                               area=area,
                                                               data=data)
+        temporary_data.notify_new()
         context = self.get_context_data(form=None)
         context.update({'popular_proposal': temporary_data,
                         'area': area


Test patch:
diff --git a/popular_proposal/tests/subscribing_tests.py b/popular_proposal/tests/subscribing_tests.py
--- a/popular_proposal/tests/subscribing_tests.py
+++ b/popular_proposal/tests/subscribing_tests.py
@@ -7,6 +7,8 @@
 from unittest import skip
 from django.core.urlresolvers import reverse
 from django.template import Template, Context
+from django.test import RequestFactory
+from popular_proposal.views import SubscriptionView
 
 
 class SubscribingToPopularProposal(TestCase):
@@ -63,6 +65,21 @@ def test_liking_view(self):
         p = ProposalLike.objects.get(user=self.feli, proposal=self.proposal)
         self.assertTrue(p)
 
+
+    def test_liking_redirecting_view(self):
+        url_home = reverse('popular_proposals:home')
+        kwargs = {'pk': self.proposal.id}
+        url = reverse('popular_proposals:like_a_proposal',
+                      kwargs=kwargs)
+        self.client.login(username=self.feli,
+                          password='alvarez')
+        response_get = self.client.get(url, {'next': url_home})
+        self.assertEquals(response_get.context['next'], url_home)
+        response = self.client.post(url,
+                                    data={'next': url_home})
+        self.assertEquals(response.status_code, 302)
+        self.assertEquals(response.url, url_home)
+
     def test_popular_proposal_likers(self):
         like = ProposalLike.objects.create(user=self.feli,
                                            proposal=self.proposal)
diff --git a/popular_proposal/tests/views_tests.py b/popular_proposal/tests/views_tests.py
--- a/popular_proposal/tests/views_tests.py
+++ b/popular_proposal/tests/views_tests.py
@@ -83,7 +83,7 @@ def setUp(self):
     def test_there_is_a_page(self):
         response = self.client.get(self.url)
         self.assertEquals(response.status_code, 200)
-        self.assertTemplateUsed('popular_proposals/home.html')
+        self.assertTemplateUsed(response, 'popular_proposal/home.html')
 
     def test_brings_a_list_of_proposals(self):
         response = self.client.get(self.url, {'clasification': '', 'area': ''})
diff --git a/popular_proposal/tests/wizard_tests.py b/popular_proposal/tests/wizard_tests.py
--- a/popular_proposal/tests/wizard_tests.py
+++ b/popular_proposal/tests/wizard_tests.py
@@ -168,6 +168,7 @@ def test_user_should_accept_terms_and_conditions(self):
         self.assertTrue(form.is_valid())
 
     def test_full_wizard(self):
+        original_amount = len(mail.outbox)
         url = reverse('popular_proposals:propose_wizard_full')
         self.client.login(username=self.feli,
                           password=USER_PASSWORD)
@@ -193,3 +194,4 @@ def test_full_wizard(self):
         self.assertEquals(response.context['area'], self.arica)
         self.assertEquals(temporary_data.proposer, self.feli)
         self.assertEquals(temporary_data.area, self.arica)
+        self.assertEquals(len(mail.outbox), original_amount + 1)