We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
No notifica en wizard full que llega un mail!!!
<!---
@huboard:{"order":470.04699999999997,"milestone_order":481,"custom_state":""}
-->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `popular_proposal/views.py`
Content:
```
1 from django.views.generic.edit import FormView, UpdateView
2 from popular_proposal.forms import (ProposalForm,
3                                     SubscriptionForm,
4                                     get_form_list,
5                                     AreaForm,
6                                     UpdateProposalForm,
7                                     ProposalFilterForm,
8                                     )
9 from django.core.urlresolvers import reverse
10 from django.shortcuts import get_object_or_404
11 from popolo.models import Area
12 from django.utils.decorators import method_decorator
13 from django.contrib.auth.decorators import login_required
14 from django.views.generic.base import TemplateView
15 from django.views.generic.detail import DetailView
16 from popular_proposal.models import (PopularProposal,
17                                      ProposalTemporaryData,
18                                      ProposalLike)
19 from django.shortcuts import render_to_response
20 from formtools.wizard.views import SessionWizardView
21 from collections import OrderedDict
22 from django.views.generic import View
23 from django.http import JsonResponse, HttpResponseNotFound
24 from django_filters.views import FilterView
25 from django.views.generic.list import ListView
26 from popular_proposal.forms import ProposalAreaFilterForm
27 from popular_proposal.filters import ProposalAreaFilter
28 
29 
30 class ProposalCreationView(FormView):
31     template_name = 'popular_proposal/create.html'
32     form_class = ProposalForm
33 
34     @method_decorator(login_required)
35     def dispatch(self, *args, **kwargs):
36         self.area = get_object_or_404(Area, id=self.kwargs['slug'])
37         return super(ProposalCreationView, self).dispatch(*args, **kwargs)
38 
39     def get_context_data(self, **kwargs):
40         kwargs = super(ProposalCreationView, self).get_context_data(**kwargs)
41         kwargs['area'] = self.area
42         return kwargs
43 
44     def get_form_kwargs(self):
45         kwargs = super(ProposalCreationView, self).get_form_kwargs()
46         kwargs['proposer'] = self.request.user
47         kwargs['area'] = self.area
48         return kwargs
49 
50     def form_valid(self, form):
51         form.save()
52         return super(ProposalCreationView, self).form_valid(form)
53 
54     def get_success_url(self):
55         return reverse('popular_proposals:thanks', kwargs={'pk': self.area.id})
56 
57 
58 class ThanksForProposingView(TemplateView):
59     template_name = 'popular_proposal/thanks.html'
60 
61     def dispatch(self, *args, **kwargs):
62         self.area = get_object_or_404(Area, id=self.kwargs['pk'])
63         return super(ThanksForProposingView, self).dispatch(*args, **kwargs)
64 
65     def get_context_data(self, **kwargs):
66         kwargs = super(ThanksForProposingView, self).get_context_data(**kwargs)
67         kwargs['area'] = self.area
68         return kwargs
69 
70 
71 class SubscriptionView(FormView):
72     template_name = 'popular_proposal/new_subscription.html'
73     form_class = SubscriptionForm
74 
75     @method_decorator(login_required)
76     def dispatch(self, *args, **kwargs):
77         self.proposal = get_object_or_404(PopularProposal, id=self.kwargs['pk'])
78         return super(SubscriptionView, self).dispatch(*args, **kwargs)
79 
80     def get_form_kwargs(self):
81         kwargs = super(SubscriptionView, self).get_form_kwargs()
82         kwargs['user'] = self.request.user
83         kwargs['proposal'] = self.proposal
84         return kwargs
85 
86     def get_context_data(self, **kwargs):
87         kwargs = super(SubscriptionView, self).get_context_data(**kwargs)
88         kwargs['proposal'] = self.proposal
89         return kwargs
90 
91     def get_success_url(self):
92         return reverse('area', kwargs={'slug': self.proposal.area.id})
93 
94     def form_valid(self, form):
95         form.subscribe()
96         return super(SubscriptionView, self).form_valid(form)
97 
98 
99 class HomeView(FilterView):
100     model = PopularProposal
101     template_name = 'popular_proposal/home.html'
102     layout = 'base.html'
103 
104     def get_queryset(self):
105         qs = super(HomeView, self).get_queryset()
106         return qs
107 
108     def get_context_data(self, **kwargs):
109         context = super(HomeView, self).get_context_data(**kwargs)
110         initial = self.request.GET
111         context['form'] = ProposalFilterForm(initial=initial)
112         context['layout'] = self.layout
113         return context
114 
115     def get_context_object_name(self, object_list):
116         return 'popular_proposals'
117 
118 
119 class PopularProposalDetailView(DetailView):
120     model = PopularProposal
121     template_name = 'popular_proposal/detail.html'
122     context_object_name = 'popular_proposal'
123     layout = 'base.html'
124 
125     def get_context_data(self, *args, **kwargs):
126         context = super(PopularProposalDetailView, self).get_context_data(*args, **kwargs)
127         context['layout'] = self.layout
128         return context
129 
130 
131 wizard_form_list = get_form_list()
132 
133 
134 class ProposalWizardBase(SessionWizardView):
135     form_list = wizard_form_list
136     template_name = 'popular_proposal/wizard/form_step.html'
137 
138     def get_template_names(self):
139         form = self.get_form(step=self.steps.current)
140         template_name = getattr(form, 'template', self.template_name)
141         return template_name
142 
143     def get_previous_forms(self):
144         return []
145 
146     def get_form_list(self):
147         form_list = OrderedDict()
148         previous_forms = self.get_previous_forms()
149         my_list = previous_forms + get_form_list(user=self.request.user)
150         counter = 0
151         for form_class in my_list:
152             form_list[str(counter)] = form_class
153             counter += 1
154         self.form_list = form_list
155         return form_list
156 
157 
158 class ProposalWizard(ProposalWizardBase):
159     @method_decorator(login_required)
160     def dispatch(self, request, *args, **kwargs):
161         self.area = get_object_or_404(Area, id=self.kwargs['slug'])
162 
163         return super(ProposalWizard, self).dispatch(request, *args, **kwargs)
164 
165     def done(self, form_list, **kwargs):
166         data = {}
167         [data.update(form.cleaned_data) for form in form_list]
168         t_data = ProposalTemporaryData.objects.create(proposer=self.request.user,
169                                                       area=self.area,
170                                                       data=data)
171         t_data.notify_new()
172         return render_to_response('popular_proposal/wizard/done.html', {
173             'popular_proposal': t_data,
174             'area': self.area
175         })
176 
177     def get_context_data(self, form, **kwargs):
178         context = super(ProposalWizard, self).get_context_data(form, **kwargs)
179         context['area'] = self.area
180         context['preview_data'] = self.get_all_cleaned_data()
181         return context
182 
183 
184 full_wizard_form_list = [AreaForm, ] + wizard_form_list
185 
186 
187 class ProposalWizardFull(ProposalWizardBase):
188     form_list = full_wizard_form_list
189     template_name = 'popular_proposal/wizard/form_step.html'
190 
191     @method_decorator(login_required)
192     def dispatch(self, request, *args, **kwargs):
193         return super(ProposalWizardFull, self).dispatch(request,
194                                                         *args,
195                                                         **kwargs)
196 
197     def get_previous_forms(self):
198         return [AreaForm, ]
199 
200     def done(self, form_list, **kwargs):
201         data = {}
202         [data.update(form.cleaned_data) for form in form_list]
203         area = data['area']
204         temporary_data = ProposalTemporaryData.objects.create(proposer=self.request.user,
205                                                               area=area,
206                                                               data=data)
207         context = self.get_context_data(form=None)
208         context.update({'popular_proposal': temporary_data,
209                         'area': area
210                         })
211         return render_to_response('popular_proposal/wizard/done.html',
212                                   context)
213 
214     def get_context_data(self, *args, **kwargs):
215         context = super(ProposalWizardFull, self).get_context_data(*args, **kwargs)
216         data = self.get_all_cleaned_data()
217         if 'area' in data:
218             context['area'] = data['area']
219         context['preview_data'] = self.get_all_cleaned_data()
220         
221         return context
222 
223 
224 class PopularProposalUpdateView(UpdateView):
225     form_class = UpdateProposalForm
226     template_name = 'popular_proposal/update.html'
227     model = PopularProposal
228     context_object_name = 'popular_proposal'
229 
230     @method_decorator(login_required)
231     def dispatch(self, request, *args, **kwargs):
232         return super(PopularProposalUpdateView, self).dispatch(request,
233                                                                *args,
234                                                                **kwargs)
235 
236     def get_queryset(self):
237         qs = super(PopularProposalUpdateView, self).get_queryset()
238         qs = qs.filter(proposer=self.request.user)
239         return qs
240 
241 
242 class UnlikeProposalView(View):
243     def dispatch(self, request, *args, **kwargs):
244         if not self.request.user.is_authenticated():
245             return HttpResponseNotFound()
246         self.pk = self.kwargs.pop('pk')
247         self.like = get_object_or_404(ProposalLike,
248                                       pk=self.pk,
249                                       user=self.request.user)
250         return super(UnlikeProposalView, self).dispatch(request,
251                                                         *args,
252                                                         **kwargs)
253 
254     def post(self, request, **kwargs):
255         self.like.delete()
256         return JsonResponse({'deleted_item': self.pk})
257 
258 
259 class ProposalsPerArea(ListView):
260     model = PopularProposal
261     layout = 'base.html'
262     template_name = 'popular_proposal/area.html'
263     context_object_name = 'popular_proposals'
264 
265     def dispatch(self, request, *args, **kwargs):
266         self.area = get_object_or_404(Area, id=self.kwargs['slug'])
267         return super(ProposalsPerArea, self).dispatch(request, *args, **kwargs)
268 
269     def get_context_data(self):
270         context = super(ProposalsPerArea, self).get_context_data()
271         context['layout'] = self.layout
272         initial = self.request.GET or None
273         context['form'] = ProposalAreaFilterForm(area=self.area,
274                                                  initial=initial)
275         return context
276 
277     def get_queryset(self):
278         kwargs = {'data': self.request.GET or None,
279                   'area': self.area
280                   }
281         filterset = ProposalAreaFilter(**kwargs)
282         return filterset
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
     @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_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 @@
         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

{"golden_diff": "diff --git a/popular_proposal/views.py b/popular_proposal/views.py\n--- a/popular_proposal/views.py\n+++ b/popular_proposal/views.py\n@@ -75,6 +75,10 @@\n     @method_decorator(login_required)\n     def dispatch(self, *args, **kwargs):\n         self.proposal = get_object_or_404(PopularProposal, id=self.kwargs['pk'])\n+        if self.request.method == 'GET':\n+            self.next_url = self.request.GET.get('next', None)\n+        elif self.request.method == 'POST':\n+            self.next_url = self.request.POST.get('next', None)\n         return super(SubscriptionView, self).dispatch(*args, **kwargs)\n \n     def get_form_kwargs(self):\n@@ -86,9 +90,13 @@\n     def get_context_data(self, **kwargs):\n         kwargs = super(SubscriptionView, self).get_context_data(**kwargs)\n         kwargs['proposal'] = self.proposal\n+        if self.next_url:\n+            kwargs['next'] = self.next_url\n         return kwargs\n \n     def get_success_url(self):\n+        if self.next_url:\n+            return self.next_url\n         return reverse('area', kwargs={'slug': self.proposal.area.id})\n \n     def form_valid(self, form):\n@@ -204,6 +212,7 @@\n         temporary_data = ProposalTemporaryData.objects.create(proposer=self.request.user,\n                                                               area=area,\n                                                               data=data)\n+        temporary_data.notify_new()\n         context = self.get_context_data(form=None)\n         context.update({'popular_proposal': temporary_data,\n                         'area': area\n", "issue": "No notifica en wizard full que llega un mail!!!\n<!---\n@huboard:{\"order\":470.04699999999997,\"milestone_order\":481,\"custom_state\":\"\"}\n-->\n\n", "before_files": [{"content": "from django.views.generic.edit import FormView, UpdateView\nfrom popular_proposal.forms import (ProposalForm,\n                                    SubscriptionForm,\n                                    get_form_list,\n                                    AreaForm,\n                                    UpdateProposalForm,\n                                    ProposalFilterForm,\n                                    )\nfrom django.core.urlresolvers import reverse\nfrom django.shortcuts import get_object_or_404\nfrom popolo.models import Area\nfrom django.utils.decorators import method_decorator\nfrom django.contrib.auth.decorators import login_required\nfrom django.views.generic.base import TemplateView\nfrom django.views.generic.detail import DetailView\nfrom popular_proposal.models import (PopularProposal,\n                                     ProposalTemporaryData,\n                                     ProposalLike)\nfrom django.shortcuts import render_to_response\nfrom formtools.wizard.views import SessionWizardView\nfrom collections import OrderedDict\nfrom django.views.generic import View\nfrom django.http import JsonResponse, HttpResponseNotFound\nfrom django_filters.views import FilterView\nfrom django.views.generic.list import ListView\nfrom popular_proposal.forms import ProposalAreaFilterForm\nfrom popular_proposal.filters import ProposalAreaFilter\n\n\nclass ProposalCreationView(FormView):\n    template_name = 'popular_proposal/create.html'\n    form_class = ProposalForm\n\n    @method_decorator(login_required)\n    def dispatch(self, *args, **kwargs):\n        self.area = get_object_or_404(Area, id=self.kwargs['slug'])\n        return super(ProposalCreationView, self).dispatch(*args, **kwargs)\n\n    def get_context_data(self, **kwargs):\n        kwargs = super(ProposalCreationView, self).get_context_data(**kwargs)\n        kwargs['area'] = self.area\n        return kwargs\n\n    def get_form_kwargs(self):\n        kwargs = super(ProposalCreationView, self).get_form_kwargs()\n        kwargs['proposer'] = self.request.user\n        kwargs['area'] = self.area\n        return kwargs\n\n    def form_valid(self, form):\n        form.save()\n        return super(ProposalCreationView, self).form_valid(form)\n\n    def get_success_url(self):\n        return reverse('popular_proposals:thanks', kwargs={'pk': self.area.id})\n\n\nclass ThanksForProposingView(TemplateView):\n    template_name = 'popular_proposal/thanks.html'\n\n    def dispatch(self, *args, **kwargs):\n        self.area = get_object_or_404(Area, id=self.kwargs['pk'])\n        return super(ThanksForProposingView, self).dispatch(*args, **kwargs)\n\n    def get_context_data(self, **kwargs):\n        kwargs = super(ThanksForProposingView, self).get_context_data(**kwargs)\n        kwargs['area'] = self.area\n        return kwargs\n\n\nclass SubscriptionView(FormView):\n    template_name = 'popular_proposal/new_subscription.html'\n    form_class = SubscriptionForm\n\n    @method_decorator(login_required)\n    def dispatch(self, *args, **kwargs):\n        self.proposal = get_object_or_404(PopularProposal, id=self.kwargs['pk'])\n        return super(SubscriptionView, self).dispatch(*args, **kwargs)\n\n    def get_form_kwargs(self):\n        kwargs = super(SubscriptionView, self).get_form_kwargs()\n        kwargs['user'] = self.request.user\n        kwargs['proposal'] = self.proposal\n        return kwargs\n\n    def get_context_data(self, **kwargs):\n        kwargs = super(SubscriptionView, self).get_context_data(**kwargs)\n        kwargs['proposal'] = self.proposal\n        return kwargs\n\n    def get_success_url(self):\n        return reverse('area', kwargs={'slug': self.proposal.area.id})\n\n    def form_valid(self, form):\n        form.subscribe()\n        return super(SubscriptionView, self).form_valid(form)\n\n\nclass HomeView(FilterView):\n    model = PopularProposal\n    template_name = 'popular_proposal/home.html'\n    layout = 'base.html'\n\n    def get_queryset(self):\n        qs = super(HomeView, self).get_queryset()\n        return qs\n\n    def get_context_data(self, **kwargs):\n        context = super(HomeView, self).get_context_data(**kwargs)\n        initial = self.request.GET\n        context['form'] = ProposalFilterForm(initial=initial)\n        context['layout'] = self.layout\n        return context\n\n    def get_context_object_name(self, object_list):\n        return 'popular_proposals'\n\n\nclass PopularProposalDetailView(DetailView):\n    model = PopularProposal\n    template_name = 'popular_proposal/detail.html'\n    context_object_name = 'popular_proposal'\n    layout = 'base.html'\n\n    def get_context_data(self, *args, **kwargs):\n        context = super(PopularProposalDetailView, self).get_context_data(*args, **kwargs)\n        context['layout'] = self.layout\n        return context\n\n\nwizard_form_list = get_form_list()\n\n\nclass ProposalWizardBase(SessionWizardView):\n    form_list = wizard_form_list\n    template_name = 'popular_proposal/wizard/form_step.html'\n\n    def get_template_names(self):\n        form = self.get_form(step=self.steps.current)\n        template_name = getattr(form, 'template', self.template_name)\n        return template_name\n\n    def get_previous_forms(self):\n        return []\n\n    def get_form_list(self):\n        form_list = OrderedDict()\n        previous_forms = self.get_previous_forms()\n        my_list = previous_forms + get_form_list(user=self.request.user)\n        counter = 0\n        for form_class in my_list:\n            form_list[str(counter)] = form_class\n            counter += 1\n        self.form_list = form_list\n        return form_list\n\n\nclass ProposalWizard(ProposalWizardBase):\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        self.area = get_object_or_404(Area, id=self.kwargs['slug'])\n\n        return super(ProposalWizard, self).dispatch(request, *args, **kwargs)\n\n    def done(self, form_list, **kwargs):\n        data = {}\n        [data.update(form.cleaned_data) for form in form_list]\n        t_data = ProposalTemporaryData.objects.create(proposer=self.request.user,\n                                                      area=self.area,\n                                                      data=data)\n        t_data.notify_new()\n        return render_to_response('popular_proposal/wizard/done.html', {\n            'popular_proposal': t_data,\n            'area': self.area\n        })\n\n    def get_context_data(self, form, **kwargs):\n        context = super(ProposalWizard, self).get_context_data(form, **kwargs)\n        context['area'] = self.area\n        context['preview_data'] = self.get_all_cleaned_data()\n        return context\n\n\nfull_wizard_form_list = [AreaForm, ] + wizard_form_list\n\n\nclass ProposalWizardFull(ProposalWizardBase):\n    form_list = full_wizard_form_list\n    template_name = 'popular_proposal/wizard/form_step.html'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        return super(ProposalWizardFull, self).dispatch(request,\n                                                        *args,\n                                                        **kwargs)\n\n    def get_previous_forms(self):\n        return [AreaForm, ]\n\n    def done(self, form_list, **kwargs):\n        data = {}\n        [data.update(form.cleaned_data) for form in form_list]\n        area = data['area']\n        temporary_data = ProposalTemporaryData.objects.create(proposer=self.request.user,\n                                                              area=area,\n                                                              data=data)\n        context = self.get_context_data(form=None)\n        context.update({'popular_proposal': temporary_data,\n                        'area': area\n                        })\n        return render_to_response('popular_proposal/wizard/done.html',\n                                  context)\n\n    def get_context_data(self, *args, **kwargs):\n        context = super(ProposalWizardFull, self).get_context_data(*args, **kwargs)\n        data = self.get_all_cleaned_data()\n        if 'area' in data:\n            context['area'] = data['area']\n        context['preview_data'] = self.get_all_cleaned_data()\n        \n        return context\n\n\nclass PopularProposalUpdateView(UpdateView):\n    form_class = UpdateProposalForm\n    template_name = 'popular_proposal/update.html'\n    model = PopularProposal\n    context_object_name = 'popular_proposal'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        return super(PopularProposalUpdateView, self).dispatch(request,\n                                                               *args,\n                                                               **kwargs)\n\n    def get_queryset(self):\n        qs = super(PopularProposalUpdateView, self).get_queryset()\n        qs = qs.filter(proposer=self.request.user)\n        return qs\n\n\nclass UnlikeProposalView(View):\n    def dispatch(self, request, *args, **kwargs):\n        if not self.request.user.is_authenticated():\n            return HttpResponseNotFound()\n        self.pk = self.kwargs.pop('pk')\n        self.like = get_object_or_404(ProposalLike,\n                                      pk=self.pk,\n                                      user=self.request.user)\n        return super(UnlikeProposalView, self).dispatch(request,\n                                                        *args,\n                                                        **kwargs)\n\n    def post(self, request, **kwargs):\n        self.like.delete()\n        return JsonResponse({'deleted_item': self.pk})\n\n\nclass ProposalsPerArea(ListView):\n    model = PopularProposal\n    layout = 'base.html'\n    template_name = 'popular_proposal/area.html'\n    context_object_name = 'popular_proposals'\n\n    def dispatch(self, request, *args, **kwargs):\n        self.area = get_object_or_404(Area, id=self.kwargs['slug'])\n        return super(ProposalsPerArea, self).dispatch(request, *args, **kwargs)\n\n    def get_context_data(self):\n        context = super(ProposalsPerArea, self).get_context_data()\n        context['layout'] = self.layout\n        initial = self.request.GET or None\n        context['form'] = ProposalAreaFilterForm(area=self.area,\n                                                 initial=initial)\n        return context\n\n    def get_queryset(self):\n        kwargs = {'data': self.request.GET or None,\n                  'area': self.area\n                  }\n        filterset = ProposalAreaFilter(**kwargs)\n        return filterset", "path": "popular_proposal/views.py"}], "after_files": [{"content": "from django.views.generic.edit import FormView, UpdateView\nfrom popular_proposal.forms import (ProposalForm,\n                                    SubscriptionForm,\n                                    get_form_list,\n                                    AreaForm,\n                                    UpdateProposalForm,\n                                    ProposalFilterForm,\n                                    )\nfrom django.core.urlresolvers import reverse\nfrom django.shortcuts import get_object_or_404\nfrom popolo.models import Area\nfrom django.utils.decorators import method_decorator\nfrom django.contrib.auth.decorators import login_required\nfrom django.views.generic.base import TemplateView\nfrom django.views.generic.detail import DetailView\nfrom popular_proposal.models import (PopularProposal,\n                                     ProposalTemporaryData,\n                                     ProposalLike)\nfrom django.shortcuts import render_to_response\nfrom formtools.wizard.views import SessionWizardView\nfrom collections import OrderedDict\nfrom django.views.generic import View\nfrom django.http import JsonResponse, HttpResponseNotFound\nfrom django_filters.views import FilterView\nfrom django.views.generic.list import ListView\nfrom popular_proposal.forms import ProposalAreaFilterForm\nfrom popular_proposal.filters import ProposalAreaFilter\n\n\nclass ProposalCreationView(FormView):\n    template_name = 'popular_proposal/create.html'\n    form_class = ProposalForm\n\n    @method_decorator(login_required)\n    def dispatch(self, *args, **kwargs):\n        self.area = get_object_or_404(Area, id=self.kwargs['slug'])\n        return super(ProposalCreationView, self).dispatch(*args, **kwargs)\n\n    def get_context_data(self, **kwargs):\n        kwargs = super(ProposalCreationView, self).get_context_data(**kwargs)\n        kwargs['area'] = self.area\n        return kwargs\n\n    def get_form_kwargs(self):\n        kwargs = super(ProposalCreationView, self).get_form_kwargs()\n        kwargs['proposer'] = self.request.user\n        kwargs['area'] = self.area\n        return kwargs\n\n    def form_valid(self, form):\n        form.save()\n        return super(ProposalCreationView, self).form_valid(form)\n\n    def get_success_url(self):\n        return reverse('popular_proposals:thanks', kwargs={'pk': self.area.id})\n\n\nclass ThanksForProposingView(TemplateView):\n    template_name = 'popular_proposal/thanks.html'\n\n    def dispatch(self, *args, **kwargs):\n        self.area = get_object_or_404(Area, id=self.kwargs['pk'])\n        return super(ThanksForProposingView, self).dispatch(*args, **kwargs)\n\n    def get_context_data(self, **kwargs):\n        kwargs = super(ThanksForProposingView, self).get_context_data(**kwargs)\n        kwargs['area'] = self.area\n        return kwargs\n\n\nclass SubscriptionView(FormView):\n    template_name = 'popular_proposal/new_subscription.html'\n    form_class = SubscriptionForm\n\n    @method_decorator(login_required)\n    def dispatch(self, *args, **kwargs):\n        self.proposal = get_object_or_404(PopularProposal, id=self.kwargs['pk'])\n        if self.request.method == 'GET':\n            self.next_url = self.request.GET.get('next', None)\n        elif self.request.method == 'POST':\n            self.next_url = self.request.POST.get('next', None)\n        return super(SubscriptionView, self).dispatch(*args, **kwargs)\n\n    def get_form_kwargs(self):\n        kwargs = super(SubscriptionView, self).get_form_kwargs()\n        kwargs['user'] = self.request.user\n        kwargs['proposal'] = self.proposal\n        return kwargs\n\n    def get_context_data(self, **kwargs):\n        kwargs = super(SubscriptionView, self).get_context_data(**kwargs)\n        kwargs['proposal'] = self.proposal\n        if self.next_url:\n            kwargs['next'] = self.next_url\n        return kwargs\n\n    def get_success_url(self):\n        if self.next_url:\n            return self.next_url\n        return reverse('area', kwargs={'slug': self.proposal.area.id})\n\n    def form_valid(self, form):\n        form.subscribe()\n        return super(SubscriptionView, self).form_valid(form)\n\n\nclass HomeView(FilterView):\n    model = PopularProposal\n    template_name = 'popular_proposal/home.html'\n    layout = 'base.html'\n\n    def get_queryset(self):\n        qs = super(HomeView, self).get_queryset()\n        return qs\n\n    def get_context_data(self, **kwargs):\n        context = super(HomeView, self).get_context_data(**kwargs)\n        initial = self.request.GET\n        context['form'] = ProposalFilterForm(initial=initial)\n        context['layout'] = self.layout\n        return context\n\n    def get_context_object_name(self, object_list):\n        return 'popular_proposals'\n\n\nclass PopularProposalDetailView(DetailView):\n    model = PopularProposal\n    template_name = 'popular_proposal/detail.html'\n    context_object_name = 'popular_proposal'\n    layout = 'base.html'\n\n    def get_context_data(self, *args, **kwargs):\n        context = super(PopularProposalDetailView, self).get_context_data(*args, **kwargs)\n        context['layout'] = self.layout\n        return context\n\n\nwizard_form_list = get_form_list()\n\n\nclass ProposalWizardBase(SessionWizardView):\n    form_list = wizard_form_list\n    template_name = 'popular_proposal/wizard/form_step.html'\n\n    def get_template_names(self):\n        form = self.get_form(step=self.steps.current)\n        template_name = getattr(form, 'template', self.template_name)\n        return template_name\n\n    def get_previous_forms(self):\n        return []\n\n    def get_form_list(self):\n        form_list = OrderedDict()\n        previous_forms = self.get_previous_forms()\n        my_list = previous_forms + get_form_list(user=self.request.user)\n        counter = 0\n        for form_class in my_list:\n            form_list[str(counter)] = form_class\n            counter += 1\n        self.form_list = form_list\n        return form_list\n\n\nclass ProposalWizard(ProposalWizardBase):\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        self.area = get_object_or_404(Area, id=self.kwargs['slug'])\n\n        return super(ProposalWizard, self).dispatch(request, *args, **kwargs)\n\n    def done(self, form_list, **kwargs):\n        data = {}\n        [data.update(form.cleaned_data) for form in form_list]\n        t_data = ProposalTemporaryData.objects.create(proposer=self.request.user,\n                                                      area=self.area,\n                                                      data=data)\n        t_data.notify_new()\n        return render_to_response('popular_proposal/wizard/done.html', {\n            'popular_proposal': t_data,\n            'area': self.area\n        })\n\n    def get_context_data(self, form, **kwargs):\n        context = super(ProposalWizard, self).get_context_data(form, **kwargs)\n        context['area'] = self.area\n        context['preview_data'] = self.get_all_cleaned_data()\n        return context\n\n\nfull_wizard_form_list = [AreaForm, ] + wizard_form_list\n\n\nclass ProposalWizardFull(ProposalWizardBase):\n    form_list = full_wizard_form_list\n    template_name = 'popular_proposal/wizard/form_step.html'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        return super(ProposalWizardFull, self).dispatch(request,\n                                                        *args,\n                                                        **kwargs)\n\n    def get_previous_forms(self):\n        return [AreaForm, ]\n\n    def done(self, form_list, **kwargs):\n        data = {}\n        [data.update(form.cleaned_data) for form in form_list]\n        area = data['area']\n        temporary_data = ProposalTemporaryData.objects.create(proposer=self.request.user,\n                                                              area=area,\n                                                              data=data)\n        temporary_data.notify_new()\n        context = self.get_context_data(form=None)\n        context.update({'popular_proposal': temporary_data,\n                        'area': area\n                        })\n        return render_to_response('popular_proposal/wizard/done.html',\n                                  context)\n\n    def get_context_data(self, *args, **kwargs):\n        context = super(ProposalWizardFull, self).get_context_data(*args, **kwargs)\n        data = self.get_all_cleaned_data()\n        if 'area' in data:\n            context['area'] = data['area']\n        context['preview_data'] = self.get_all_cleaned_data()\n        \n        return context\n\n\nclass PopularProposalUpdateView(UpdateView):\n    form_class = UpdateProposalForm\n    template_name = 'popular_proposal/update.html'\n    model = PopularProposal\n    context_object_name = 'popular_proposal'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        return super(PopularProposalUpdateView, self).dispatch(request,\n                                                               *args,\n                                                               **kwargs)\n\n    def get_queryset(self):\n        qs = super(PopularProposalUpdateView, self).get_queryset()\n        qs = qs.filter(proposer=self.request.user)\n        return qs\n\n\nclass UnlikeProposalView(View):\n    def dispatch(self, request, *args, **kwargs):\n        if not self.request.user.is_authenticated():\n            return HttpResponseNotFound()\n        self.pk = self.kwargs.pop('pk')\n        self.like = get_object_or_404(ProposalLike,\n                                      pk=self.pk,\n                                      user=self.request.user)\n        return super(UnlikeProposalView, self).dispatch(request,\n                                                        *args,\n                                                        **kwargs)\n\n    def post(self, request, **kwargs):\n        self.like.delete()\n        return JsonResponse({'deleted_item': self.pk})\n\n\nclass ProposalsPerArea(ListView):\n    model = PopularProposal\n    layout = 'base.html'\n    template_name = 'popular_proposal/area.html'\n    context_object_name = 'popular_proposals'\n\n    def dispatch(self, request, *args, **kwargs):\n        self.area = get_object_or_404(Area, id=self.kwargs['slug'])\n        return super(ProposalsPerArea, self).dispatch(request, *args, **kwargs)\n\n    def get_context_data(self):\n        context = super(ProposalsPerArea, self).get_context_data()\n        context['layout'] = self.layout\n        initial = self.request.GET or None\n        context['form'] = ProposalAreaFilterForm(area=self.area,\n                                                 initial=initial)\n        return context\n\n    def get_queryset(self):\n        kwargs = {'data': self.request.GET or None,\n                  'area': self.area\n                  }\n        filterset = ProposalAreaFilter(**kwargs)\n        return filterset", "path": "popular_proposal/views.py"}]}