We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Backend candidato: hay una pregunta que tiene una alternativa en blanco.
![screen shot 2016-09-09 at 15 34 33](https://cloud.githubusercontent.com/assets/1230740/18398356/c5d5be2c-76a2-11e6-8fa6-8268cb436178.png)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `backend_candidate/views.py`
Content:
```
1 from backend_candidate.models import is_candidate, CandidacyContact, Candidacy
2 from django.http import Http404
3 from django.views.generic.base import TemplateView, RedirectView
4 from django.views.generic import View
5 from django.utils.decorators import method_decorator
6 from django.contrib.auth.decorators import login_required
7 from django.views.generic.edit import FormView
8 from django.views.generic.list import ListView
9 from django.shortcuts import get_object_or_404
10 from backend_candidate.forms import get_form_for_election
11 from elections.models import Candidate, Election, PersonalData
12 from django.core.urlresolvers import reverse
13 from django.http import HttpResponseRedirect
14 from backend_candidate.forms import get_candidate_profile_form_class
15 from popular_proposal.models import Commitment, PopularProposal
16 from django.contrib import messages
17 from django.utils.translation import ugettext as _
18 
19 
20 class BackendCandidateBase(View):
21     @method_decorator(login_required)
22     def dispatch(self, request, *args, **kwargs):
23         if not is_candidate(request.user):
24             raise Http404
25         self.user = request.user
26         candidacy_objects = CandidacyContact.objects.filter(candidacy__user=self.user)
27         used_by_candidate = True
28         for candidacy_object in candidacy_objects:
29 
30             if not candidacy_object.used_by_candidate:
31                 used_by_candidate = False
32                 candidacy_object.used_by_candidate = True
33                 candidacy_object.save()
34         if not used_by_candidate:
35             return HttpResponseRedirect(reverse('password_reset'))
36         return super(BackendCandidateBase, self).dispatch(request,
37                                                           *args,
38                                                           **kwargs)
39 
40 
41 class HomeView(BackendCandidateBase, TemplateView):
42     template_name = "backend_candidate/home.html"
43 
44     def get_context_data(self, *args, **kwargs):
45         context = super(HomeView, self).get_context_data(*args, **kwargs)
46         context['candidacies'] = self.user.candidacies.all()
47         return context
48 
49 
50 class CompleteMediaNaranjaView(FormView):
51     template_name = 'backend_candidate/complete_12_naranja.html'
52 
53     @method_decorator(login_required)
54     def dispatch(self, request, *args, **kwargs):
55         if not is_candidate(request.user):
56             raise Http404
57         self.user = request.user
58         self.election = get_object_or_404(Election, slug=self.kwargs['slug'])
59         self.candidate = get_object_or_404(Candidate,
60                                            id=self.kwargs['candidate_id'])
61         return super(CompleteMediaNaranjaView, self).dispatch(request,
62                                                               *args,
63                                                               **kwargs)
64 
65     def get_form_class(self):
66         return get_form_for_election(self.election)
67 
68     def get_form_kwargs(self):
69         kwargs = super(CompleteMediaNaranjaView, self).get_form_kwargs()
70         kwargs['candidate'] = self.candidate
71         return kwargs
72 
73     def get_context_data(self, **kwargs):
74         context = (super(CompleteMediaNaranjaView, self)
75                    .get_context_data(**kwargs))
76         context['candidate'] = self.candidate
77         context['election'] = self.election
78         return context
79 
80     def form_valid(self, form):
81         form.save()
82         messages.add_message(self.request, messages.INFO, _('Hemos guardado tus respuestas'))
83         return super(CompleteMediaNaranjaView, self).form_valid(form)
84 
85     def get_success_url(self):
86         url = reverse('backend_candidate:complete_12_naranja',
87                       kwargs={'slug': self.election.slug,
88                               'candidate_id': self.candidate.id})
89         return url
90 
91 
92 class CandidacyJoinView(RedirectView):
93     permanent = False
94     query_string = True
95 
96     @method_decorator(login_required)
97     def dispatch(self, *args, **kwargs):
98         self.contact = get_object_or_404(CandidacyContact,
99                                          identifier=self.kwargs['identifier'])
100         return super(CandidacyJoinView, self).dispatch(*args, **kwargs)
101 
102     def get_redirect_url(self, *args, **kwargs):
103         candidacy, created = Candidacy.objects.get_or_create(candidate=self.contact.candidate,
104                                                              user=self.request.user
105                                                              )
106         self.contact.candidacy = candidacy
107         self.contact.used_by_candidate = True
108         self.contact.save()
109         return reverse('backend_candidate:home')
110 
111 
112 form_class = get_candidate_profile_form_class()
113 
114 
115 class ProfileView(FormView):
116     form_class = form_class
117     template_name = 'backend_candidate/complete_profile.html'
118 
119     @method_decorator(login_required)
120     def dispatch(self, request, *args, **kwargs):
121         if not is_candidate(request.user):
122             raise Http404
123         self.user = request.user
124         self.election = get_object_or_404(Election, slug=self.kwargs['slug'])
125         self.candidate = get_object_or_404(Candidate,
126                                            id=self.kwargs['candidate_id'])
127         return super(ProfileView, self).dispatch(request, *args, **kwargs)
128 
129     def get_form_kwargs(self):
130         kwargs = super(ProfileView, self).get_form_kwargs()
131         kwargs['candidate'] = self.candidate
132         return kwargs
133 
134     def form_valid(self, form):
135         form.save()
136         messages.add_message(self.request, messages.INFO, _('Hemos actualizado tu perfil'))
137         return super(ProfileView, self).form_valid(form)
138 
139     def get_success_url(self):
140         url = reverse('backend_candidate:complete_profile',
141                       kwargs={'slug': self.election.slug,
142                               'candidate_id': self.candidate.id}
143                       )
144         return url
145 
146     def get_initial(self):
147         initial = super(ProfileView, self).get_initial()
148         labels = []
149         for field in self.form_class.base_fields:
150             labels.append(field)
151         personal_datas = PersonalData.objects.filter(candidate=self.candidate,
152                                                      label__in=labels)
153         for personal_data in personal_datas:
154             initial[str(personal_data.label)] = personal_data.value
155         return initial
156 
157     def get_context_data(self, **kwargs):
158         context = (super(ProfileView, self)
159                    .get_context_data(**kwargs))
160         context['candidate'] = self.candidate
161         context['election'] = self.election
162         return context
163 
164 
165 class MyCommitments(BackendCandidateBase, ListView):
166     model = Commitment
167     template_name = 'backend_candidate/i_have_commited.html'
168     context_object_name = 'commitments'
169 
170     @method_decorator(login_required)
171     def dispatch(self, request, *args, **kwargs):
172         if not is_candidate(request.user):
173             raise Http404
174         self.user = request.user
175         self.election = get_object_or_404(Election, slug=self.kwargs['slug'])
176         self.candidate = get_object_or_404(Candidate,
177                                            id=self.kwargs['candidate_id'])
178         return super(MyCommitments, self).dispatch(request, *args, **kwargs)
179 
180     def get_queryset(self):
181         qs = super(MyCommitments, self).get_queryset()
182         return qs.filter(candidate=self.candidate)
183 
184     def get_context_data(self, **kwargs):
185         context = (super(MyCommitments, self)
186                    .get_context_data(**kwargs))
187         context['candidate'] = self.candidate
188         context['election'] = self.election
189         return context
190 
191 
192 class ProposalsForMe(BackendCandidateBase, ListView):
193     model = PopularProposal
194     template_name = 'backend_candidate/proposals_for_me.html'
195     context_object_name = 'proposals'
196 
197     @method_decorator(login_required)
198     def dispatch(self, request, *args, **kwargs):
199         if not is_candidate(request.user):
200             raise Http404
201         self.user = request.user
202         self.election = get_object_or_404(Election, slug=self.kwargs['slug'])
203         self.candidate = get_object_or_404(Candidate,
204                                            id=self.kwargs['candidate_id'])
205         return super(ProposalsForMe, self).dispatch(request, *args, **kwargs)
206 
207     def get_queryset(self):
208         qs = super(ProposalsForMe, self).get_queryset()
209         proposals_ids = []
210         for commitment in self.candidate.commitments.all():
211             proposals_ids.append(commitment.proposal.id)
212         qs = qs.filter(area=self.election.area).exclude(id__in=proposals_ids)
213         return qs
214 
215     def get_context_data(self, **kwargs):
216         context = (super(ProposalsForMe, self)
217                    .get_context_data(**kwargs))
218         context['candidate'] = self.candidate
219         context['election'] = self.election
220         return context
```
--- 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/backend_candidate/views.py b/backend_candidate/views.py
--- a/backend_candidate/views.py
+++ b/backend_candidate/views.py
@@ -38,7 +38,7 @@
                                                           **kwargs)
 
 
-class HomeView(BackendCandidateBase, TemplateView):
+class HomeView(BackendCandidateBase, RedirectView):
     template_name = "backend_candidate/home.html"
 
     def get_context_data(self, *args, **kwargs):
@@ -46,6 +46,13 @@
         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'
@@ -106,7 +113,11 @@
         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()

{"golden_diff": "diff --git a/backend_candidate/views.py b/backend_candidate/views.py\n--- a/backend_candidate/views.py\n+++ b/backend_candidate/views.py\n@@ -38,7 +38,7 @@\n                                                           **kwargs)\n \n \n-class HomeView(BackendCandidateBase, TemplateView):\n+class HomeView(BackendCandidateBase, RedirectView):\n     template_name = \"backend_candidate/home.html\"\n \n     def get_context_data(self, *args, **kwargs):\n@@ -46,6 +46,13 @@\n         context['candidacies'] = self.user.candidacies.all()\n         return context\n \n+    def get_redirect_url(self, *args, **kwargs):\n+        candidacy = self.user.candidacies.first()\n+        profile_url = reverse('backend_candidate:complete_profile',\n+                              kwargs={'slug': candidacy.candidate.election.slug,\n+                                      'candidate_id': candidacy.candidate.id})\n+        return profile_url\n+\n \n class CompleteMediaNaranjaView(FormView):\n     template_name = 'backend_candidate/complete_12_naranja.html'\n@@ -106,7 +113,11 @@\n         self.contact.candidacy = candidacy\n         self.contact.used_by_candidate = True\n         self.contact.save()\n-        return reverse('backend_candidate:home')\n+        candidacy = self.request.user.candidacies.first()\n+        profile_url = reverse('backend_candidate:complete_profile',\n+                              kwargs={'slug': candidacy.candidate.election.slug,\n+                                      'candidate_id': candidacy.candidate.id})\n+        return profile_url\n \n \n form_class = get_candidate_profile_form_class()\n", "issue": "Backend candidato: hay una pregunta que tiene una alternativa en blanco.\n![screen shot 2016-09-09 at 15 34 33](https://cloud.githubusercontent.com/assets/1230740/18398356/c5d5be2c-76a2-11e6-8fa6-8268cb436178.png)\n\n", "before_files": [{"content": "from backend_candidate.models import is_candidate, CandidacyContact, Candidacy\nfrom django.http import Http404\nfrom django.views.generic.base import TemplateView, RedirectView\nfrom django.views.generic import View\nfrom django.utils.decorators import method_decorator\nfrom django.contrib.auth.decorators import login_required\nfrom django.views.generic.edit import FormView\nfrom django.views.generic.list import ListView\nfrom django.shortcuts import get_object_or_404\nfrom backend_candidate.forms import get_form_for_election\nfrom elections.models import Candidate, Election, PersonalData\nfrom django.core.urlresolvers import reverse\nfrom django.http import HttpResponseRedirect\nfrom backend_candidate.forms import get_candidate_profile_form_class\nfrom popular_proposal.models import Commitment, PopularProposal\nfrom django.contrib import messages\nfrom django.utils.translation import ugettext as _\n\n\nclass BackendCandidateBase(View):\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        candidacy_objects = CandidacyContact.objects.filter(candidacy__user=self.user)\n        used_by_candidate = True\n        for candidacy_object in candidacy_objects:\n\n            if not candidacy_object.used_by_candidate:\n                used_by_candidate = False\n                candidacy_object.used_by_candidate = True\n                candidacy_object.save()\n        if not used_by_candidate:\n            return HttpResponseRedirect(reverse('password_reset'))\n        return super(BackendCandidateBase, self).dispatch(request,\n                                                          *args,\n                                                          **kwargs)\n\n\nclass HomeView(BackendCandidateBase, TemplateView):\n    template_name = \"backend_candidate/home.html\"\n\n    def get_context_data(self, *args, **kwargs):\n        context = super(HomeView, self).get_context_data(*args, **kwargs)\n        context['candidacies'] = self.user.candidacies.all()\n        return context\n\n\nclass CompleteMediaNaranjaView(FormView):\n    template_name = 'backend_candidate/complete_12_naranja.html'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        self.election = get_object_or_404(Election, slug=self.kwargs['slug'])\n        self.candidate = get_object_or_404(Candidate,\n                                           id=self.kwargs['candidate_id'])\n        return super(CompleteMediaNaranjaView, self).dispatch(request,\n                                                              *args,\n                                                              **kwargs)\n\n    def get_form_class(self):\n        return get_form_for_election(self.election)\n\n    def get_form_kwargs(self):\n        kwargs = super(CompleteMediaNaranjaView, self).get_form_kwargs()\n        kwargs['candidate'] = self.candidate\n        return kwargs\n\n    def get_context_data(self, **kwargs):\n        context = (super(CompleteMediaNaranjaView, self)\n                   .get_context_data(**kwargs))\n        context['candidate'] = self.candidate\n        context['election'] = self.election\n        return context\n\n    def form_valid(self, form):\n        form.save()\n        messages.add_message(self.request, messages.INFO, _('Hemos guardado tus respuestas'))\n        return super(CompleteMediaNaranjaView, self).form_valid(form)\n\n    def get_success_url(self):\n        url = reverse('backend_candidate:complete_12_naranja',\n                      kwargs={'slug': self.election.slug,\n                              'candidate_id': self.candidate.id})\n        return url\n\n\nclass CandidacyJoinView(RedirectView):\n    permanent = False\n    query_string = True\n\n    @method_decorator(login_required)\n    def dispatch(self, *args, **kwargs):\n        self.contact = get_object_or_404(CandidacyContact,\n                                         identifier=self.kwargs['identifier'])\n        return super(CandidacyJoinView, self).dispatch(*args, **kwargs)\n\n    def get_redirect_url(self, *args, **kwargs):\n        candidacy, created = Candidacy.objects.get_or_create(candidate=self.contact.candidate,\n                                                             user=self.request.user\n                                                             )\n        self.contact.candidacy = candidacy\n        self.contact.used_by_candidate = True\n        self.contact.save()\n        return reverse('backend_candidate:home')\n\n\nform_class = get_candidate_profile_form_class()\n\n\nclass ProfileView(FormView):\n    form_class = form_class\n    template_name = 'backend_candidate/complete_profile.html'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        self.election = get_object_or_404(Election, slug=self.kwargs['slug'])\n        self.candidate = get_object_or_404(Candidate,\n                                           id=self.kwargs['candidate_id'])\n        return super(ProfileView, self).dispatch(request, *args, **kwargs)\n\n    def get_form_kwargs(self):\n        kwargs = super(ProfileView, self).get_form_kwargs()\n        kwargs['candidate'] = self.candidate\n        return kwargs\n\n    def form_valid(self, form):\n        form.save()\n        messages.add_message(self.request, messages.INFO, _('Hemos actualizado tu perfil'))\n        return super(ProfileView, self).form_valid(form)\n\n    def get_success_url(self):\n        url = reverse('backend_candidate:complete_profile',\n                      kwargs={'slug': self.election.slug,\n                              'candidate_id': self.candidate.id}\n                      )\n        return url\n\n    def get_initial(self):\n        initial = super(ProfileView, self).get_initial()\n        labels = []\n        for field in self.form_class.base_fields:\n            labels.append(field)\n        personal_datas = PersonalData.objects.filter(candidate=self.candidate,\n                                                     label__in=labels)\n        for personal_data in personal_datas:\n            initial[str(personal_data.label)] = personal_data.value\n        return initial\n\n    def get_context_data(self, **kwargs):\n        context = (super(ProfileView, self)\n                   .get_context_data(**kwargs))\n        context['candidate'] = self.candidate\n        context['election'] = self.election\n        return context\n\n\nclass MyCommitments(BackendCandidateBase, ListView):\n    model = Commitment\n    template_name = 'backend_candidate/i_have_commited.html'\n    context_object_name = 'commitments'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        self.election = get_object_or_404(Election, slug=self.kwargs['slug'])\n        self.candidate = get_object_or_404(Candidate,\n                                           id=self.kwargs['candidate_id'])\n        return super(MyCommitments, self).dispatch(request, *args, **kwargs)\n\n    def get_queryset(self):\n        qs = super(MyCommitments, self).get_queryset()\n        return qs.filter(candidate=self.candidate)\n\n    def get_context_data(self, **kwargs):\n        context = (super(MyCommitments, self)\n                   .get_context_data(**kwargs))\n        context['candidate'] = self.candidate\n        context['election'] = self.election\n        return context\n\n\nclass ProposalsForMe(BackendCandidateBase, ListView):\n    model = PopularProposal\n    template_name = 'backend_candidate/proposals_for_me.html'\n    context_object_name = 'proposals'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        self.election = get_object_or_404(Election, slug=self.kwargs['slug'])\n        self.candidate = get_object_or_404(Candidate,\n                                           id=self.kwargs['candidate_id'])\n        return super(ProposalsForMe, self).dispatch(request, *args, **kwargs)\n\n    def get_queryset(self):\n        qs = super(ProposalsForMe, self).get_queryset()\n        proposals_ids = []\n        for commitment in self.candidate.commitments.all():\n            proposals_ids.append(commitment.proposal.id)\n        qs = qs.filter(area=self.election.area).exclude(id__in=proposals_ids)\n        return qs\n\n    def get_context_data(self, **kwargs):\n        context = (super(ProposalsForMe, self)\n                   .get_context_data(**kwargs))\n        context['candidate'] = self.candidate\n        context['election'] = self.election\n        return context", "path": "backend_candidate/views.py"}], "after_files": [{"content": "from backend_candidate.models import is_candidate, CandidacyContact, Candidacy\nfrom django.http import Http404\nfrom django.views.generic.base import TemplateView, RedirectView\nfrom django.views.generic import View\nfrom django.utils.decorators import method_decorator\nfrom django.contrib.auth.decorators import login_required\nfrom django.views.generic.edit import FormView\nfrom django.views.generic.list import ListView\nfrom django.shortcuts import get_object_or_404\nfrom backend_candidate.forms import get_form_for_election\nfrom elections.models import Candidate, Election, PersonalData\nfrom django.core.urlresolvers import reverse\nfrom django.http import HttpResponseRedirect\nfrom backend_candidate.forms import get_candidate_profile_form_class\nfrom popular_proposal.models import Commitment, PopularProposal\nfrom django.contrib import messages\nfrom django.utils.translation import ugettext as _\n\n\nclass BackendCandidateBase(View):\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        candidacy_objects = CandidacyContact.objects.filter(candidacy__user=self.user)\n        used_by_candidate = True\n        for candidacy_object in candidacy_objects:\n\n            if not candidacy_object.used_by_candidate:\n                used_by_candidate = False\n                candidacy_object.used_by_candidate = True\n                candidacy_object.save()\n        if not used_by_candidate:\n            return HttpResponseRedirect(reverse('password_reset'))\n        return super(BackendCandidateBase, self).dispatch(request,\n                                                          *args,\n                                                          **kwargs)\n\n\nclass HomeView(BackendCandidateBase, RedirectView):\n    template_name = \"backend_candidate/home.html\"\n\n    def get_context_data(self, *args, **kwargs):\n        context = super(HomeView, self).get_context_data(*args, **kwargs)\n        context['candidacies'] = self.user.candidacies.all()\n        return context\n\n    def get_redirect_url(self, *args, **kwargs):\n        candidacy = self.user.candidacies.first()\n        profile_url = reverse('backend_candidate:complete_profile',\n                              kwargs={'slug': candidacy.candidate.election.slug,\n                                      'candidate_id': candidacy.candidate.id})\n        return profile_url\n\n\nclass CompleteMediaNaranjaView(FormView):\n    template_name = 'backend_candidate/complete_12_naranja.html'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        self.election = get_object_or_404(Election, slug=self.kwargs['slug'])\n        self.candidate = get_object_or_404(Candidate,\n                                           id=self.kwargs['candidate_id'])\n        return super(CompleteMediaNaranjaView, self).dispatch(request,\n                                                              *args,\n                                                              **kwargs)\n\n    def get_form_class(self):\n        return get_form_for_election(self.election)\n\n    def get_form_kwargs(self):\n        kwargs = super(CompleteMediaNaranjaView, self).get_form_kwargs()\n        kwargs['candidate'] = self.candidate\n        return kwargs\n\n    def get_context_data(self, **kwargs):\n        context = (super(CompleteMediaNaranjaView, self)\n                   .get_context_data(**kwargs))\n        context['candidate'] = self.candidate\n        context['election'] = self.election\n        return context\n\n    def form_valid(self, form):\n        form.save()\n        messages.add_message(self.request, messages.INFO, _('Hemos guardado tus respuestas'))\n        return super(CompleteMediaNaranjaView, self).form_valid(form)\n\n    def get_success_url(self):\n        url = reverse('backend_candidate:complete_12_naranja',\n                      kwargs={'slug': self.election.slug,\n                              'candidate_id': self.candidate.id})\n        return url\n\n\nclass CandidacyJoinView(RedirectView):\n    permanent = False\n    query_string = True\n\n    @method_decorator(login_required)\n    def dispatch(self, *args, **kwargs):\n        self.contact = get_object_or_404(CandidacyContact,\n                                         identifier=self.kwargs['identifier'])\n        return super(CandidacyJoinView, self).dispatch(*args, **kwargs)\n\n    def get_redirect_url(self, *args, **kwargs):\n        candidacy, created = Candidacy.objects.get_or_create(candidate=self.contact.candidate,\n                                                             user=self.request.user\n                                                             )\n        self.contact.candidacy = candidacy\n        self.contact.used_by_candidate = True\n        self.contact.save()\n        candidacy = self.request.user.candidacies.first()\n        profile_url = reverse('backend_candidate:complete_profile',\n                              kwargs={'slug': candidacy.candidate.election.slug,\n                                      'candidate_id': candidacy.candidate.id})\n        return profile_url\n\n\nform_class = get_candidate_profile_form_class()\n\n\nclass ProfileView(FormView):\n    form_class = form_class\n    template_name = 'backend_candidate/complete_profile.html'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        self.election = get_object_or_404(Election, slug=self.kwargs['slug'])\n        self.candidate = get_object_or_404(Candidate,\n                                           id=self.kwargs['candidate_id'])\n        return super(ProfileView, self).dispatch(request, *args, **kwargs)\n\n    def get_form_kwargs(self):\n        kwargs = super(ProfileView, self).get_form_kwargs()\n        kwargs['candidate'] = self.candidate\n        return kwargs\n\n    def form_valid(self, form):\n        form.save()\n        messages.add_message(self.request, messages.INFO, _('Hemos actualizado tu perfil'))\n        return super(ProfileView, self).form_valid(form)\n\n    def get_success_url(self):\n        url = reverse('backend_candidate:complete_profile',\n                      kwargs={'slug': self.election.slug,\n                              'candidate_id': self.candidate.id}\n                      )\n        return url\n\n    def get_initial(self):\n        initial = super(ProfileView, self).get_initial()\n        labels = []\n        for field in self.form_class.base_fields:\n            labels.append(field)\n        personal_datas = PersonalData.objects.filter(candidate=self.candidate,\n                                                     label__in=labels)\n        for personal_data in personal_datas:\n            initial[str(personal_data.label)] = personal_data.value\n        return initial\n\n    def get_context_data(self, **kwargs):\n        context = (super(ProfileView, self)\n                   .get_context_data(**kwargs))\n        context['candidate'] = self.candidate\n        context['election'] = self.election\n        return context\n\n\nclass MyCommitments(BackendCandidateBase, ListView):\n    model = Commitment\n    template_name = 'backend_candidate/i_have_commited.html'\n    context_object_name = 'commitments'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        self.election = get_object_or_404(Election, slug=self.kwargs['slug'])\n        self.candidate = get_object_or_404(Candidate,\n                                           id=self.kwargs['candidate_id'])\n        return super(MyCommitments, self).dispatch(request, *args, **kwargs)\n\n    def get_queryset(self):\n        qs = super(MyCommitments, self).get_queryset()\n        return qs.filter(candidate=self.candidate)\n\n    def get_context_data(self, **kwargs):\n        context = (super(MyCommitments, self)\n                   .get_context_data(**kwargs))\n        context['candidate'] = self.candidate\n        context['election'] = self.election\n        return context\n\n\nclass ProposalsForMe(BackendCandidateBase, ListView):\n    model = PopularProposal\n    template_name = 'backend_candidate/proposals_for_me.html'\n    context_object_name = 'proposals'\n\n    @method_decorator(login_required)\n    def dispatch(self, request, *args, **kwargs):\n        if not is_candidate(request.user):\n            raise Http404\n        self.user = request.user\n        self.election = get_object_or_404(Election, slug=self.kwargs['slug'])\n        self.candidate = get_object_or_404(Candidate,\n                                           id=self.kwargs['candidate_id'])\n        return super(ProposalsForMe, self).dispatch(request, *args, **kwargs)\n\n    def get_queryset(self):\n        qs = super(ProposalsForMe, self).get_queryset()\n        proposals_ids = []\n        for commitment in self.candidate.commitments.all():\n            proposals_ids.append(commitment.proposal.id)\n        qs = qs.filter(area=self.election.area).exclude(id__in=proposals_ids)\n        return qs\n\n    def get_context_data(self, **kwargs):\n        context = (super(ProposalsForMe, self)\n                   .get_context_data(**kwargs))\n        context['candidate'] = self.candidate\n        context['election'] = self.election\n        return context", "path": "backend_candidate/views.py"}]}