We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Przyjazny komunikat o aktualizacji wiarygodności
![zaznaczenie_1027](https://user-images.githubusercontent.com/3618479/30726463-49ccc99c-9f4b-11e7-8b74-db3108ac4e45.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: `feder/tasks/views.py`
Content:
```
1 from atom.views import (ActionMessageMixin, ActionView, CreateMessageMixin,
2                         DeleteMessageMixin, UpdateMessageMixin)
3 from braces.views import (FormValidMessageMixin, PrefetchRelatedMixin,
4                           SelectRelatedMixin, UserFormKwargsMixin)
5 from cached_property import cached_property
6 from django.contrib import messages
7 from django.contrib.auth.mixins import LoginRequiredMixin
8 from django.core.urlresolvers import reverse, reverse_lazy
9 from django.shortcuts import get_object_or_404, redirect
10 from django.utils.translation import ugettext_lazy as _
11 from django.views.generic import (CreateView, DeleteView, DetailView, FormView,
12                                   UpdateView)
13 from django_filters.views import FilterView
14 
15 from feder.cases.models import Case
16 from feder.main.mixins import (AttrPermissionRequiredMixin,
17                                RaisePermissionRequiredMixin)
18 from .filters import TaskFilter
19 from .forms import AnswerFormSet, SurveyForm, TaskForm
20 from .models import Survey, Task
21 
22 DONE_MESSAGE_TEXT = _("Already done the job. If you want to change the answer - delete answers.")
23 
24 THANK_TEXT = _("Thank you for your submission. It is approaching us to know the " +
25                "truth, by obtaining reliable data.")
26 
27 EXHAUSTED_TEXT = _("Thank you for your help. Unfortunately, all the tasks " +
28                    "for you have been exhausted.")
29 
30 
31 class TaskListView(SelectRelatedMixin, FilterView):
32     filterset_class = TaskFilter
33     model = Task
34     select_related = ['case', 'questionary']
35     paginate_by = 25
36 
37     def get_context_data(self, **kwargs):
38         context = super(TaskListView, self).get_context_data(**kwargs)
39         context['stats'] = self.object_list.survey_stats()
40         return context
41 
42 
43 class TaskDetailView(SelectRelatedMixin, PrefetchRelatedMixin, DetailView):
44     model = Task
45     select_related = ['case__monitoring', 'case__institution', 'questionary']
46     prefetch_related = ['survey_set', 'questionary__question_set']
47 
48     def get_user_survey(self):
49         try:
50             return (self.object.survey_set.with_full_answer().
51                     of_user(self.request.user, self.request.light_user).get())
52         except Survey.DoesNotExist:
53             return None
54 
55     def get_context_data(self, **kwargs):
56         context = super(TaskDetailView, self).get_context_data(**kwargs)
57         context['formset'] = AnswerFormSet(questionary=self.object.questionary)
58         context['user_survey'] = self.get_user_survey()
59         return context
60 
61 
62 class TaskSurveyView(SelectRelatedMixin, PrefetchRelatedMixin, DetailView):
63     model = Task
64     select_related = ['case__monitoring', 'case__institution', 'questionary', ]
65     prefetch_related = ['questionary__question_set']
66     template_name_suffix = '_survey'
67 
68     def get_context_data(self, **kwargs):
69         context = super(TaskSurveyView, self).get_context_data(**kwargs)
70         survey_list = (Survey.objects.for_task(self.object).with_user().with_full_answer().all())
71         context['survey_list'] = survey_list
72         user_survey_list = [x for x in survey_list if x.user == self.request.user]  # TODO: Lazy
73         context['user_survey'] = user_survey_list[0] if user_survey_list else None
74         return context
75 
76 
77 class TaskCreateView(RaisePermissionRequiredMixin, UserFormKwargsMixin,
78                      CreateMessageMixin, CreateView):
79     model = Task
80     form_class = TaskForm
81     permission_required = 'monitorings.add_task'
82 
83     @cached_property
84     def case(self):
85         return get_object_or_404(Case.objects.select_related('monitoring'),
86                                  pk=self.kwargs['case'])
87 
88     def get_permission_object(self):
89         return self.case.monitoring
90 
91     def get_form_kwargs(self):
92         kw = super(TaskCreateView, self).get_form_kwargs()
93         kw['case'] = self.case
94         return kw
95 
96     def get_context_data(self, **kwargs):
97         context = super(TaskCreateView, self).get_context_data(**kwargs)
98         context['case'] = self.case
99         return context
100 
101 
102 class TaskUpdateView(AttrPermissionRequiredMixin, UserFormKwargsMixin,
103                      UpdateMessageMixin, FormValidMessageMixin, UpdateView):
104     model = Task
105     form_class = TaskForm
106     permission_required = 'change_task'
107     permission_attribute = 'case__monitoring'
108 
109 
110 class TaskDeleteView(AttrPermissionRequiredMixin, DeleteMessageMixin, DeleteView):
111     model = Task
112     success_url = reverse_lazy('tasks:list')
113     permission_required = 'delete_task'
114     permission_attribute = 'case__monitoring'
115 
116 
117 class SurveyDeleteView(LoginRequiredMixin, DeleteMessageMixin, DeleteView):
118     model = Survey
119     slug_url_kwarg = 'task_id'
120     slug_field = 'task_id'
121 
122     def get_queryset(self, *args, **kwargs):
123         qs = super(SurveyDeleteView, self).get_queryset()
124         return qs.of_user(self.request.user, self.request.light_user).with_full_answer()
125 
126     def get_success_url(self):
127         return self.object.task.get_absolute_url()
128 
129 
130 class SurveySelectView(AttrPermissionRequiredMixin, ActionMessageMixin,
131                        SelectRelatedMixin, ActionView):  # TODO: Write test
132     model = Survey
133     template_name_suffix = '_select'
134     select_related = ['task__case__monitoring', ]
135     permission_required = 'monitorings.select_survey'
136     permission_attribute = 'task__case__monitoring'
137     direction = None
138     change = {'up': 1, 'down': -1}
139 
140     def action(self, *args, **kwargs):
141         self.object.credibility_update(self.change[self.direction])
142         self.object.save()
143 
144     def get_success_message(self):
145         return _("Survey {object} selected!").format(object=self.object)
146 
147     def get_success_url(self):
148         return reverse('tasks:survey', kwargs={'pk': self.object.task_id})
149 
150 
151 class SurveyFillView(FormView):
152     template_name = 'tasks/survey_fill.html'
153     form_class = SurveyForm
154     formset_class = AnswerFormSet
155 
156     @cached_property
157     def task(self):
158         return get_object_or_404(Task, pk=self.kwargs['pk'])
159 
160     @cached_property
161     def object(self):
162         try:
163             return Survey.objects.filter(task=self.task).of_user(user=self.request.user,
164                                                                  light_user=self.request.light_user).all()[0]
165         except IndexError:
166             return None
167 
168     def get_form_kwargs(self):
169         kwargs = super(SurveyFillView, self).get_form_kwargs()
170         kwargs['task'] = self.task
171         kwargs['instance'] = self.object
172         return kwargs
173 
174     def get_success_url(self):
175         if 'save' in self.request.POST:  # only save
176             return self.object.task.get_absolute_url()
177 
178         # find next task
179         try:
180             next_task = self.task.get_next_for_user(self.request.user)
181             return next_task.get_absolute_url()
182         except Task.DoesNotExist:
183             messages.success(self.request, EXHAUSTED_TEXT)
184             return self.task.case.monitoring.get_absolute_url()
185 
186     @cached_property
187     def formset(self):
188         return self.formset_class(data=self.request.POST or None,
189                                   survey=self.object,
190                                   questionary=self.task.questionary)
191 
192     def form_valid(self, form):
193         self.object = form.save(commit=False)
194         if self.formset.is_valid():
195             if self.request.user.is_authenticated():
196                 self.object.user = self.request.user
197             else:
198                 self.object.light_user = self.request.light_user_new
199             self.object.save()
200             self.formset.save()
201             return self.formset_valid(form, self.object, self.formset)
202         return self.render_to_response(self.get_context_data())
203 
204     def formset_valid(self, form, obj, formset):
205         messages.success(self.request, THANK_TEXT)
206         obj.save()
207         formset.save()
208         return redirect(self.get_success_url())
209 
210     def get_context_data(self, **kwargs):
211         context = super(SurveyFillView, self).get_context_data(**kwargs)
212         context['formset'] = self.formset
213         context['object'] = self.object
214         context['task'] = self.task
215         return context
216
```
--- 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/feder/tasks/views.py b/feder/tasks/views.py
--- a/feder/tasks/views.py
+++ b/feder/tasks/views.py
@@ -142,7 +142,10 @@
         self.object.save()
 
     def get_success_message(self):
-        return _("Survey {object} selected!").format(object=self.object)
+        if self.direction == 'up':
+            return _("Survey credibility increased!")
+        else:
+            return _("Survey credibility decreased!")
 
     def get_success_url(self):
         return reverse('tasks:survey', kwargs={'pk': self.object.task_id})

{"golden_diff": "diff --git a/feder/tasks/views.py b/feder/tasks/views.py\n--- a/feder/tasks/views.py\n+++ b/feder/tasks/views.py\n@@ -142,7 +142,10 @@\n         self.object.save()\n \n     def get_success_message(self):\n-        return _(\"Survey {object} selected!\").format(object=self.object)\n+        if self.direction == 'up':\n+            return _(\"Survey credibility increased!\")\n+        else:\n+            return _(\"Survey credibility decreased!\")\n \n     def get_success_url(self):\n         return reverse('tasks:survey', kwargs={'pk': self.object.task_id})\n", "issue": "Przyjazny komunikat o aktualizacji wiarygodno\u015bci\n![zaznaczenie_1027](https://user-images.githubusercontent.com/3618479/30726463-49ccc99c-9f4b-11e7-8b74-db3108ac4e45.png)\r\n\n", "before_files": [{"content": "from atom.views import (ActionMessageMixin, ActionView, CreateMessageMixin,\n                        DeleteMessageMixin, UpdateMessageMixin)\nfrom braces.views import (FormValidMessageMixin, PrefetchRelatedMixin,\n                          SelectRelatedMixin, UserFormKwargsMixin)\nfrom cached_property import cached_property\nfrom django.contrib import messages\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.core.urlresolvers import reverse, reverse_lazy\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic import (CreateView, DeleteView, DetailView, FormView,\n                                  UpdateView)\nfrom django_filters.views import FilterView\n\nfrom feder.cases.models import Case\nfrom feder.main.mixins import (AttrPermissionRequiredMixin,\n                               RaisePermissionRequiredMixin)\nfrom .filters import TaskFilter\nfrom .forms import AnswerFormSet, SurveyForm, TaskForm\nfrom .models import Survey, Task\n\nDONE_MESSAGE_TEXT = _(\"Already done the job. If you want to change the answer - delete answers.\")\n\nTHANK_TEXT = _(\"Thank you for your submission. It is approaching us to know the \" +\n               \"truth, by obtaining reliable data.\")\n\nEXHAUSTED_TEXT = _(\"Thank you for your help. Unfortunately, all the tasks \" +\n                   \"for you have been exhausted.\")\n\n\nclass TaskListView(SelectRelatedMixin, FilterView):\n    filterset_class = TaskFilter\n    model = Task\n    select_related = ['case', 'questionary']\n    paginate_by = 25\n\n    def get_context_data(self, **kwargs):\n        context = super(TaskListView, self).get_context_data(**kwargs)\n        context['stats'] = self.object_list.survey_stats()\n        return context\n\n\nclass TaskDetailView(SelectRelatedMixin, PrefetchRelatedMixin, DetailView):\n    model = Task\n    select_related = ['case__monitoring', 'case__institution', 'questionary']\n    prefetch_related = ['survey_set', 'questionary__question_set']\n\n    def get_user_survey(self):\n        try:\n            return (self.object.survey_set.with_full_answer().\n                    of_user(self.request.user, self.request.light_user).get())\n        except Survey.DoesNotExist:\n            return None\n\n    def get_context_data(self, **kwargs):\n        context = super(TaskDetailView, self).get_context_data(**kwargs)\n        context['formset'] = AnswerFormSet(questionary=self.object.questionary)\n        context['user_survey'] = self.get_user_survey()\n        return context\n\n\nclass TaskSurveyView(SelectRelatedMixin, PrefetchRelatedMixin, DetailView):\n    model = Task\n    select_related = ['case__monitoring', 'case__institution', 'questionary', ]\n    prefetch_related = ['questionary__question_set']\n    template_name_suffix = '_survey'\n\n    def get_context_data(self, **kwargs):\n        context = super(TaskSurveyView, self).get_context_data(**kwargs)\n        survey_list = (Survey.objects.for_task(self.object).with_user().with_full_answer().all())\n        context['survey_list'] = survey_list\n        user_survey_list = [x for x in survey_list if x.user == self.request.user]  # TODO: Lazy\n        context['user_survey'] = user_survey_list[0] if user_survey_list else None\n        return context\n\n\nclass TaskCreateView(RaisePermissionRequiredMixin, UserFormKwargsMixin,\n                     CreateMessageMixin, CreateView):\n    model = Task\n    form_class = TaskForm\n    permission_required = 'monitorings.add_task'\n\n    @cached_property\n    def case(self):\n        return get_object_or_404(Case.objects.select_related('monitoring'),\n                                 pk=self.kwargs['case'])\n\n    def get_permission_object(self):\n        return self.case.monitoring\n\n    def get_form_kwargs(self):\n        kw = super(TaskCreateView, self).get_form_kwargs()\n        kw['case'] = self.case\n        return kw\n\n    def get_context_data(self, **kwargs):\n        context = super(TaskCreateView, self).get_context_data(**kwargs)\n        context['case'] = self.case\n        return context\n\n\nclass TaskUpdateView(AttrPermissionRequiredMixin, UserFormKwargsMixin,\n                     UpdateMessageMixin, FormValidMessageMixin, UpdateView):\n    model = Task\n    form_class = TaskForm\n    permission_required = 'change_task'\n    permission_attribute = 'case__monitoring'\n\n\nclass TaskDeleteView(AttrPermissionRequiredMixin, DeleteMessageMixin, DeleteView):\n    model = Task\n    success_url = reverse_lazy('tasks:list')\n    permission_required = 'delete_task'\n    permission_attribute = 'case__monitoring'\n\n\nclass SurveyDeleteView(LoginRequiredMixin, DeleteMessageMixin, DeleteView):\n    model = Survey\n    slug_url_kwarg = 'task_id'\n    slug_field = 'task_id'\n\n    def get_queryset(self, *args, **kwargs):\n        qs = super(SurveyDeleteView, self).get_queryset()\n        return qs.of_user(self.request.user, self.request.light_user).with_full_answer()\n\n    def get_success_url(self):\n        return self.object.task.get_absolute_url()\n\n\nclass SurveySelectView(AttrPermissionRequiredMixin, ActionMessageMixin,\n                       SelectRelatedMixin, ActionView):  # TODO: Write test\n    model = Survey\n    template_name_suffix = '_select'\n    select_related = ['task__case__monitoring', ]\n    permission_required = 'monitorings.select_survey'\n    permission_attribute = 'task__case__monitoring'\n    direction = None\n    change = {'up': 1, 'down': -1}\n\n    def action(self, *args, **kwargs):\n        self.object.credibility_update(self.change[self.direction])\n        self.object.save()\n\n    def get_success_message(self):\n        return _(\"Survey {object} selected!\").format(object=self.object)\n\n    def get_success_url(self):\n        return reverse('tasks:survey', kwargs={'pk': self.object.task_id})\n\n\nclass SurveyFillView(FormView):\n    template_name = 'tasks/survey_fill.html'\n    form_class = SurveyForm\n    formset_class = AnswerFormSet\n\n    @cached_property\n    def task(self):\n        return get_object_or_404(Task, pk=self.kwargs['pk'])\n\n    @cached_property\n    def object(self):\n        try:\n            return Survey.objects.filter(task=self.task).of_user(user=self.request.user,\n                                                                 light_user=self.request.light_user).all()[0]\n        except IndexError:\n            return None\n\n    def get_form_kwargs(self):\n        kwargs = super(SurveyFillView, self).get_form_kwargs()\n        kwargs['task'] = self.task\n        kwargs['instance'] = self.object\n        return kwargs\n\n    def get_success_url(self):\n        if 'save' in self.request.POST:  # only save\n            return self.object.task.get_absolute_url()\n\n        # find next task\n        try:\n            next_task = self.task.get_next_for_user(self.request.user)\n            return next_task.get_absolute_url()\n        except Task.DoesNotExist:\n            messages.success(self.request, EXHAUSTED_TEXT)\n            return self.task.case.monitoring.get_absolute_url()\n\n    @cached_property\n    def formset(self):\n        return self.formset_class(data=self.request.POST or None,\n                                  survey=self.object,\n                                  questionary=self.task.questionary)\n\n    def form_valid(self, form):\n        self.object = form.save(commit=False)\n        if self.formset.is_valid():\n            if self.request.user.is_authenticated():\n                self.object.user = self.request.user\n            else:\n                self.object.light_user = self.request.light_user_new\n            self.object.save()\n            self.formset.save()\n            return self.formset_valid(form, self.object, self.formset)\n        return self.render_to_response(self.get_context_data())\n\n    def formset_valid(self, form, obj, formset):\n        messages.success(self.request, THANK_TEXT)\n        obj.save()\n        formset.save()\n        return redirect(self.get_success_url())\n\n    def get_context_data(self, **kwargs):\n        context = super(SurveyFillView, self).get_context_data(**kwargs)\n        context['formset'] = self.formset\n        context['object'] = self.object\n        context['task'] = self.task\n        return context\n", "path": "feder/tasks/views.py"}], "after_files": [{"content": "from atom.views import (ActionMessageMixin, ActionView, CreateMessageMixin,\n                        DeleteMessageMixin, UpdateMessageMixin)\nfrom braces.views import (FormValidMessageMixin, PrefetchRelatedMixin,\n                          SelectRelatedMixin, UserFormKwargsMixin)\nfrom cached_property import cached_property\nfrom django.contrib import messages\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.core.urlresolvers import reverse, reverse_lazy\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic import (CreateView, DeleteView, DetailView, FormView,\n                                  UpdateView)\nfrom django_filters.views import FilterView\n\nfrom feder.cases.models import Case\nfrom feder.main.mixins import (AttrPermissionRequiredMixin,\n                               RaisePermissionRequiredMixin)\nfrom .filters import TaskFilter\nfrom .forms import AnswerFormSet, SurveyForm, TaskForm\nfrom .models import Survey, Task\n\nDONE_MESSAGE_TEXT = _(\"Already done the job. If you want to change the answer - delete answers.\")\n\nTHANK_TEXT = _(\"Thank you for your submission. It is approaching us to know the \" +\n               \"truth, by obtaining reliable data.\")\n\nEXHAUSTED_TEXT = _(\"Thank you for your help. Unfortunately, all the tasks \" +\n                   \"for you have been exhausted.\")\n\n\nclass TaskListView(SelectRelatedMixin, FilterView):\n    filterset_class = TaskFilter\n    model = Task\n    select_related = ['case', 'questionary']\n    paginate_by = 25\n\n    def get_context_data(self, **kwargs):\n        context = super(TaskListView, self).get_context_data(**kwargs)\n        context['stats'] = self.object_list.survey_stats()\n        return context\n\n\nclass TaskDetailView(SelectRelatedMixin, PrefetchRelatedMixin, DetailView):\n    model = Task\n    select_related = ['case__monitoring', 'case__institution', 'questionary']\n    prefetch_related = ['survey_set', 'questionary__question_set']\n\n    def get_user_survey(self):\n        try:\n            return (self.object.survey_set.with_full_answer().\n                    of_user(self.request.user, self.request.light_user).get())\n        except Survey.DoesNotExist:\n            return None\n\n    def get_context_data(self, **kwargs):\n        context = super(TaskDetailView, self).get_context_data(**kwargs)\n        context['formset'] = AnswerFormSet(questionary=self.object.questionary)\n        context['user_survey'] = self.get_user_survey()\n        return context\n\n\nclass TaskSurveyView(SelectRelatedMixin, PrefetchRelatedMixin, DetailView):\n    model = Task\n    select_related = ['case__monitoring', 'case__institution', 'questionary', ]\n    prefetch_related = ['questionary__question_set']\n    template_name_suffix = '_survey'\n\n    def get_context_data(self, **kwargs):\n        context = super(TaskSurveyView, self).get_context_data(**kwargs)\n        survey_list = (Survey.objects.for_task(self.object).with_user().with_full_answer().all())\n        context['survey_list'] = survey_list\n        user_survey_list = [x for x in survey_list if x.user == self.request.user]  # TODO: Lazy\n        context['user_survey'] = user_survey_list[0] if user_survey_list else None\n        return context\n\n\nclass TaskCreateView(RaisePermissionRequiredMixin, UserFormKwargsMixin,\n                     CreateMessageMixin, CreateView):\n    model = Task\n    form_class = TaskForm\n    permission_required = 'monitorings.add_task'\n\n    @cached_property\n    def case(self):\n        return get_object_or_404(Case.objects.select_related('monitoring'),\n                                 pk=self.kwargs['case'])\n\n    def get_permission_object(self):\n        return self.case.monitoring\n\n    def get_form_kwargs(self):\n        kw = super(TaskCreateView, self).get_form_kwargs()\n        kw['case'] = self.case\n        return kw\n\n    def get_context_data(self, **kwargs):\n        context = super(TaskCreateView, self).get_context_data(**kwargs)\n        context['case'] = self.case\n        return context\n\n\nclass TaskUpdateView(AttrPermissionRequiredMixin, UserFormKwargsMixin,\n                     UpdateMessageMixin, FormValidMessageMixin, UpdateView):\n    model = Task\n    form_class = TaskForm\n    permission_required = 'change_task'\n    permission_attribute = 'case__monitoring'\n\n\nclass TaskDeleteView(AttrPermissionRequiredMixin, DeleteMessageMixin, DeleteView):\n    model = Task\n    success_url = reverse_lazy('tasks:list')\n    permission_required = 'delete_task'\n    permission_attribute = 'case__monitoring'\n\n\nclass SurveyDeleteView(LoginRequiredMixin, DeleteMessageMixin, DeleteView):\n    model = Survey\n    slug_url_kwarg = 'task_id'\n    slug_field = 'task_id'\n\n    def get_queryset(self, *args, **kwargs):\n        qs = super(SurveyDeleteView, self).get_queryset()\n        return qs.of_user(self.request.user, self.request.light_user).with_full_answer()\n\n    def get_success_url(self):\n        return self.object.task.get_absolute_url()\n\n\nclass SurveySelectView(AttrPermissionRequiredMixin, ActionMessageMixin,\n                       SelectRelatedMixin, ActionView):  # TODO: Write test\n    model = Survey\n    template_name_suffix = '_select'\n    select_related = ['task__case__monitoring', ]\n    permission_required = 'monitorings.select_survey'\n    permission_attribute = 'task__case__monitoring'\n    direction = None\n    change = {'up': 1, 'down': -1}\n\n    def action(self, *args, **kwargs):\n        self.object.credibility_update(self.change[self.direction])\n        self.object.save()\n\n    def get_success_message(self):\n        if self.direction == 'up':\n            return _(\"Survey credibility increased!\")\n        else:\n            return _(\"Survey credibility decreased!\")\n\n    def get_success_url(self):\n        return reverse('tasks:survey', kwargs={'pk': self.object.task_id})\n\n\nclass SurveyFillView(FormView):\n    template_name = 'tasks/survey_fill.html'\n    form_class = SurveyForm\n    formset_class = AnswerFormSet\n\n    @cached_property\n    def task(self):\n        return get_object_or_404(Task, pk=self.kwargs['pk'])\n\n    @cached_property\n    def object(self):\n        try:\n            return Survey.objects.filter(task=self.task).of_user(user=self.request.user,\n                                                                 light_user=self.request.light_user).all()[0]\n        except IndexError:\n            return None\n\n    def get_form_kwargs(self):\n        kwargs = super(SurveyFillView, self).get_form_kwargs()\n        kwargs['task'] = self.task\n        kwargs['instance'] = self.object\n        return kwargs\n\n    def get_success_url(self):\n        if 'save' in self.request.POST:  # only save\n            return self.object.task.get_absolute_url()\n\n        # find next task\n        try:\n            next_task = self.task.get_next_for_user(self.request.user)\n            return next_task.get_absolute_url()\n        except Task.DoesNotExist:\n            messages.success(self.request, EXHAUSTED_TEXT)\n            return self.task.case.monitoring.get_absolute_url()\n\n    @cached_property\n    def formset(self):\n        return self.formset_class(data=self.request.POST or None,\n                                  survey=self.object,\n                                  questionary=self.task.questionary)\n\n    def form_valid(self, form):\n        self.object = form.save(commit=False)\n        if self.formset.is_valid():\n            if self.request.user.is_authenticated():\n                self.object.user = self.request.user\n            else:\n                self.object.light_user = self.request.light_user_new\n            self.object.save()\n            self.formset.save()\n            return self.formset_valid(form, self.object, self.formset)\n        return self.render_to_response(self.get_context_data())\n\n    def formset_valid(self, form, obj, formset):\n        messages.success(self.request, THANK_TEXT)\n        obj.save()\n        formset.save()\n        return redirect(self.get_success_url())\n\n    def get_context_data(self, **kwargs):\n        context = super(SurveyFillView, self).get_context_data(**kwargs)\n        context['formset'] = self.formset\n        context['object'] = self.object\n        context['task'] = self.task\n        return context\n", "path": "feder/tasks/views.py"}]}