prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Community debate module error messages
  **expected behaviour:** Error message only shown for document upload if file is incorrect
  **behaviour:** Error message is also shown when title is not added
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `euth/communitydebate/views.py`
  Content:
  ```
  1 from django.contrib import messages
  2 from django.shortcuts import render
  3 from django.urls import reverse
  4 from django.utils.translation import gettext as _
  5 from django.views import generic
  6 from rules.contrib.views import PermissionRequiredMixin
  7 
  8 from adhocracy4.filters import views as filter_views
  9 from adhocracy4.modules.models import Module
  10 from euth.projects import mixins as prj_mixins
  11 
  12 from . import forms
  13 from . import models as communitydebate_models
  14 from .filters import TopicFilterSet
  15 
  16 
  17 class TopicListView(prj_mixins.ProjectPhaseMixin,
  18                     filter_views.FilteredListView):
  19     model = communitydebate_models.Topic
  20     paginate_by = 15
  21     filter_set = TopicFilterSet
  22 
  23     def get_queryset(self):
  24         return super().get_queryset().filter(module=self.module)
  25 
  26 
  27 class TopicDetailView(PermissionRequiredMixin, generic.DetailView):
  28     model = communitydebate_models.Topic
  29     queryset = \
  30         communitydebate_models.Topic.objects\
  31         .annotate_positive_rating_count() \
  32         .annotate_negative_rating_count()
  33     permission_required = 'euth_communitydebate.view_topic'
  34 
  35     def get_context_data(self, **kwargs):
  36         context = super().get_context_data()
  37         upload_files = communitydebate_models.TopicFileUpload.objects\
  38             .filter(topic=self.object)
  39         context['upload_files'] = upload_files
  40         return context
  41 
  42 
  43 class TopicCreateView(PermissionRequiredMixin, generic.CreateView):
  44     model = communitydebate_models.Topic
  45     form_class = forms.TopicForm
  46     permission_required = 'euth_communitydebate.propose_topic'
  47     template_name = 'euth_communitydebate/topic_form.html'
  48 
  49     @property
  50     def raise_exception(self):
  51         return self.request.user.is_authenticated
  52 
  53     def dispatch(self, *args, **kwargs):
  54         mod_slug = self.kwargs[self.slug_url_kwarg]
  55         self.module = Module.objects.get(slug=mod_slug)
  56         self.project = self.module.project
  57         return super().dispatch(*args, **kwargs)
  58 
  59     def get_permission_object(self, *args, **kwargs):
  60         return self.module
  61 
  62     def get_context_data(self, upload_forms=None, **kwargs):
  63         context = super().get_context_data(**kwargs)
  64         context['project'] = self.project
  65         context['mode'] = 'create'
  66         if not upload_forms:
  67             upload_forms = forms.TopicFileUploadFormset()
  68         context['upload_forms'] = upload_forms
  69         return context
  70 
  71     def form_valid(self, form):
  72         form.instance.creator = self.request.user
  73         form.instance.module = self.module
  74         return super().form_valid(form)
  75 
  76     def get_form_kwargs(self):
  77         kwargs = super().get_form_kwargs()
  78         kwargs['module'] = self.module
  79         return kwargs
  80 
  81     def post(self, request, *args, **kwargs):
  82         self.object = None
  83         form = self.get_form()
  84         if form.is_valid():
  85             topic = form.save(commit=False)
  86             upload_forms = forms.TopicFileUploadFormset(request.POST,
  87                                                         request.FILES,
  88                                                         instance=topic)
  89             if upload_forms.is_valid():
  90                 response = self.form_valid(form)
  91                 upload_forms.save()
  92                 messages.add_message(request,
  93                                      messages.SUCCESS,
  94                                      _('Topic '
  95                                        'successfully created'))
  96                 return response
  97 
  98         upload_forms = forms.TopicFileUploadFormset(request.POST,
  99                                                     request.FILES)
  100         return render(request, self.template_name,
  101                       self.get_context_data(upload_forms=upload_forms))
  102 
  103 
  104 class TopicUpdateView(PermissionRequiredMixin, generic.UpdateView):
  105     model = communitydebate_models.Topic
  106     form_class = forms.TopicForm
  107     permission_required = 'euth_communitydebate.modify_topic'
  108     template_name = 'euth_communitydebate/topic_form.html'
  109 
  110     @property
  111     def raise_exception(self):
  112         return self.request.user.is_authenticated
  113 
  114     def dispatch(self, *args, **kwargs):
  115         self.object = self.get_object()
  116         return super().dispatch(*args, **kwargs)
  117 
  118     def get_context_data(self, upload_forms=None, **kwargs):
  119         context = super().get_context_data(**kwargs)
  120         context['project'] = self.object.project
  121         context['mode'] = 'update'
  122         if not upload_forms:
  123             upload_forms = forms.TopicFileUploadFormset(
  124                 instance=self.get_object())
  125         context['upload_forms'] = upload_forms
  126         return context
  127 
  128     def get_form_kwargs(self):
  129         kwargs = super().get_form_kwargs()
  130         kwargs['module'] = kwargs.get('instance').module
  131         return kwargs
  132 
  133     def post(self, request, *args, **kwargs):
  134         form = self.get_form()
  135         upload_forms = forms.TopicFileUploadFormset(request.POST,
  136                                                     request.FILES,
  137                                                     instance=self.object)
  138         if upload_forms.is_valid() and form.is_valid():
  139             response = self.form_valid(form)
  140             upload_forms.save()
  141             messages.add_message(request,
  142                                  messages.SUCCESS,
  143                                  _('Topic successfully '
  144                                    'updated'))
  145         else:
  146             response = render(request,
  147                               self.template_name,
  148                               self.get_context_data(upload_forms=upload_forms))
  149         return response
  150 
  151 
  152 class TopicDeleteView(PermissionRequiredMixin, generic.DeleteView):
  153     model = communitydebate_models.Topic
  154     success_message = _("Your topic has been deleted")
  155     permission_required = 'euth_communitydebate.modify_topic'
  156 
  157     @property
  158     def raise_exception(self):
  159         return self.request.user.is_authenticated
  160 
  161     def delete(self, request, *args, **kwargs):
  162         messages.success(self.request, self.success_message)
  163         return super(TopicDeleteView, self).delete(request, *args, **kwargs)
  164 
  165     def get_success_url(self):
  166         return reverse('project-detail',
  167                        kwargs={'slug': self.object.project.slug})
  168
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/euth/communitydebate/views.py b/euth/communitydebate/views.py
  --- a/euth/communitydebate/views.py
  +++ b/euth/communitydebate/views.py
  @@ -95,8 +95,9 @@
                                          'successfully created'))
                   return response
   
  -        upload_forms = forms.TopicFileUploadFormset(request.POST,
  -                                                    request.FILES)
  +        else:
  +            upload_forms = forms.TopicFileUploadFormset(request.POST,
  +                                                        request.FILES)
           return render(request, self.template_name,
                         self.get_context_data(upload_forms=upload_forms))
  
verification_info: {"golden_diff": "diff --git a/euth/communitydebate/views.py b/euth/communitydebate/views.py\n--- a/euth/communitydebate/views.py\n+++ b/euth/communitydebate/views.py\n@@ -95,8 +95,9 @@\n                                        'successfully created'))\n                 return response\n \n-        upload_forms = forms.TopicFileUploadFormset(request.POST,\n-                                                    request.FILES)\n+        else:\n+            upload_forms = forms.TopicFileUploadFormset(request.POST,\n+                                                        request.FILES)\n         return render(request, self.template_name,\n                       self.get_context_data(upload_forms=upload_forms))\n", "issue": "Community debate module error messages\n**expected behaviour:** Error message only shown for document upload if file is incorrect\r\n**behaviour:** Error message is also shown when title is not added\r\n\r\n\n", "before_files": [{"content": "from django.contrib import messages\nfrom django.shortcuts import render\nfrom django.urls import reverse\nfrom django.utils.translation import gettext as _\nfrom django.views import generic\nfrom rules.contrib.views import PermissionRequiredMixin\n\nfrom adhocracy4.filters import views as filter_views\nfrom adhocracy4.modules.models import Module\nfrom euth.projects import mixins as prj_mixins\n\nfrom . import forms\nfrom . import models as communitydebate_models\nfrom .filters import TopicFilterSet\n\n\nclass TopicListView(prj_mixins.ProjectPhaseMixin,\n                    filter_views.FilteredListView):\n    model = communitydebate_models.Topic\n    paginate_by = 15\n    filter_set = TopicFilterSet\n\n    def get_queryset(self):\n        return super().get_queryset().filter(module=self.module)\n\n\nclass TopicDetailView(PermissionRequiredMixin, generic.DetailView):\n    model = communitydebate_models.Topic\n    queryset = \\\n        communitydebate_models.Topic.objects\\\n        .annotate_positive_rating_count() \\\n        .annotate_negative_rating_count()\n    permission_required = 'euth_communitydebate.view_topic'\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data()\n        upload_files = communitydebate_models.TopicFileUpload.objects\\\n            .filter(topic=self.object)\n        context['upload_files'] = upload_files\n        return context\n\n\nclass TopicCreateView(PermissionRequiredMixin, generic.CreateView):\n    model = communitydebate_models.Topic\n    form_class = forms.TopicForm\n    permission_required = 'euth_communitydebate.propose_topic'\n    template_name = 'euth_communitydebate/topic_form.html'\n\n    @property\n    def raise_exception(self):\n        return self.request.user.is_authenticated\n\n    def dispatch(self, *args, **kwargs):\n        mod_slug = self.kwargs[self.slug_url_kwarg]\n        self.module = Module.objects.get(slug=mod_slug)\n        self.project = self.module.project\n        return super().dispatch(*args, **kwargs)\n\n    def get_permission_object(self, *args, **kwargs):\n        return self.module\n\n    def get_context_data(self, upload_forms=None, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context['project'] = self.project\n        context['mode'] = 'create'\n        if not upload_forms:\n            upload_forms = forms.TopicFileUploadFormset()\n        context['upload_forms'] = upload_forms\n        return context\n\n    def form_valid(self, form):\n        form.instance.creator = self.request.user\n        form.instance.module = self.module\n        return super().form_valid(form)\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs['module'] = self.module\n        return kwargs\n\n    def post(self, request, *args, **kwargs):\n        self.object = None\n        form = self.get_form()\n        if form.is_valid():\n            topic = form.save(commit=False)\n            upload_forms = forms.TopicFileUploadFormset(request.POST,\n                                                        request.FILES,\n                                                        instance=topic)\n            if upload_forms.is_valid():\n                response = self.form_valid(form)\n                upload_forms.save()\n                messages.add_message(request,\n                                     messages.SUCCESS,\n                                     _('Topic '\n                                       'successfully created'))\n                return response\n\n        upload_forms = forms.TopicFileUploadFormset(request.POST,\n                                                    request.FILES)\n        return render(request, self.template_name,\n                      self.get_context_data(upload_forms=upload_forms))\n\n\nclass TopicUpdateView(PermissionRequiredMixin, generic.UpdateView):\n    model = communitydebate_models.Topic\n    form_class = forms.TopicForm\n    permission_required = 'euth_communitydebate.modify_topic'\n    template_name = 'euth_communitydebate/topic_form.html'\n\n    @property\n    def raise_exception(self):\n        return self.request.user.is_authenticated\n\n    def dispatch(self, *args, **kwargs):\n        self.object = self.get_object()\n        return super().dispatch(*args, **kwargs)\n\n    def get_context_data(self, upload_forms=None, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context['project'] = self.object.project\n        context['mode'] = 'update'\n        if not upload_forms:\n            upload_forms = forms.TopicFileUploadFormset(\n                instance=self.get_object())\n        context['upload_forms'] = upload_forms\n        return context\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs['module'] = kwargs.get('instance').module\n        return kwargs\n\n    def post(self, request, *args, **kwargs):\n        form = self.get_form()\n        upload_forms = forms.TopicFileUploadFormset(request.POST,\n                                                    request.FILES,\n                                                    instance=self.object)\n        if upload_forms.is_valid() and form.is_valid():\n            response = self.form_valid(form)\n            upload_forms.save()\n            messages.add_message(request,\n                                 messages.SUCCESS,\n                                 _('Topic successfully '\n                                   'updated'))\n        else:\n            response = render(request,\n                              self.template_name,\n                              self.get_context_data(upload_forms=upload_forms))\n        return response\n\n\nclass TopicDeleteView(PermissionRequiredMixin, generic.DeleteView):\n    model = communitydebate_models.Topic\n    success_message = _(\"Your topic has been deleted\")\n    permission_required = 'euth_communitydebate.modify_topic'\n\n    @property\n    def raise_exception(self):\n        return self.request.user.is_authenticated\n\n    def delete(self, request, *args, **kwargs):\n        messages.success(self.request, self.success_message)\n        return super(TopicDeleteView, self).delete(request, *args, **kwargs)\n\n    def get_success_url(self):\n        return reverse('project-detail',\n                       kwargs={'slug': self.object.project.slug})\n", "path": "euth/communitydebate/views.py"}], "after_files": [{"content": "from django.contrib import messages\nfrom django.shortcuts import render\nfrom django.urls import reverse\nfrom django.utils.translation import gettext as _\nfrom django.views import generic\nfrom rules.contrib.views import PermissionRequiredMixin\n\nfrom adhocracy4.filters import views as filter_views\nfrom adhocracy4.modules.models import Module\nfrom euth.projects import mixins as prj_mixins\n\nfrom . import forms\nfrom . import models as communitydebate_models\nfrom .filters import TopicFilterSet\n\n\nclass TopicListView(prj_mixins.ProjectPhaseMixin,\n                    filter_views.FilteredListView):\n    model = communitydebate_models.Topic\n    paginate_by = 15\n    filter_set = TopicFilterSet\n\n    def get_queryset(self):\n        return super().get_queryset().filter(module=self.module)\n\n\nclass TopicDetailView(PermissionRequiredMixin, generic.DetailView):\n    model = communitydebate_models.Topic\n    queryset = \\\n        communitydebate_models.Topic.objects\\\n        .annotate_positive_rating_count() \\\n        .annotate_negative_rating_count()\n    permission_required = 'euth_communitydebate.view_topic'\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data()\n        upload_files = communitydebate_models.TopicFileUpload.objects\\\n            .filter(topic=self.object)\n        context['upload_files'] = upload_files\n        return context\n\n\nclass TopicCreateView(PermissionRequiredMixin, generic.CreateView):\n    model = communitydebate_models.Topic\n    form_class = forms.TopicForm\n    permission_required = 'euth_communitydebate.propose_topic'\n    template_name = 'euth_communitydebate/topic_form.html'\n\n    @property\n    def raise_exception(self):\n        return self.request.user.is_authenticated\n\n    def dispatch(self, *args, **kwargs):\n        mod_slug = self.kwargs[self.slug_url_kwarg]\n        self.module = Module.objects.get(slug=mod_slug)\n        self.project = self.module.project\n        return super().dispatch(*args, **kwargs)\n\n    def get_permission_object(self, *args, **kwargs):\n        return self.module\n\n    def get_context_data(self, upload_forms=None, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context['project'] = self.project\n        context['mode'] = 'create'\n        if not upload_forms:\n            upload_forms = forms.TopicFileUploadFormset()\n        context['upload_forms'] = upload_forms\n        return context\n\n    def form_valid(self, form):\n        form.instance.creator = self.request.user\n        form.instance.module = self.module\n        return super().form_valid(form)\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs['module'] = self.module\n        return kwargs\n\n    def post(self, request, *args, **kwargs):\n        self.object = None\n        form = self.get_form()\n        if form.is_valid():\n            topic = form.save(commit=False)\n            upload_forms = forms.TopicFileUploadFormset(request.POST,\n                                                        request.FILES,\n                                                        instance=topic)\n            if upload_forms.is_valid():\n                response = self.form_valid(form)\n                upload_forms.save()\n                messages.add_message(request,\n                                     messages.SUCCESS,\n                                     _('Topic '\n                                       'successfully created'))\n                return response\n\n        else:\n            upload_forms = forms.TopicFileUploadFormset(request.POST,\n                                                        request.FILES)\n        return render(request, self.template_name,\n                      self.get_context_data(upload_forms=upload_forms))\n\n\nclass TopicUpdateView(PermissionRequiredMixin, generic.UpdateView):\n    model = communitydebate_models.Topic\n    form_class = forms.TopicForm\n    permission_required = 'euth_communitydebate.modify_topic'\n    template_name = 'euth_communitydebate/topic_form.html'\n\n    @property\n    def raise_exception(self):\n        return self.request.user.is_authenticated\n\n    def dispatch(self, *args, **kwargs):\n        self.object = self.get_object()\n        return super().dispatch(*args, **kwargs)\n\n    def get_context_data(self, upload_forms=None, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context['project'] = self.object.project\n        context['mode'] = 'update'\n        if not upload_forms:\n            upload_forms = forms.TopicFileUploadFormset(\n                instance=self.get_object())\n        context['upload_forms'] = upload_forms\n        return context\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs['module'] = kwargs.get('instance').module\n        return kwargs\n\n    def post(self, request, *args, **kwargs):\n        form = self.get_form()\n        upload_forms = forms.TopicFileUploadFormset(request.POST,\n                                                    request.FILES,\n                                                    instance=self.object)\n        if upload_forms.is_valid() and form.is_valid():\n            response = self.form_valid(form)\n            upload_forms.save()\n            messages.add_message(request,\n                                 messages.SUCCESS,\n                                 _('Topic successfully '\n                                   'updated'))\n        else:\n            response = render(request,\n                              self.template_name,\n                              self.get_context_data(upload_forms=upload_forms))\n        return response\n\n\nclass TopicDeleteView(PermissionRequiredMixin, generic.DeleteView):\n    model = communitydebate_models.Topic\n    success_message = _(\"Your topic has been deleted\")\n    permission_required = 'euth_communitydebate.modify_topic'\n\n    @property\n    def raise_exception(self):\n        return self.request.user.is_authenticated\n\n    def delete(self, request, *args, **kwargs):\n        messages.success(self.request, self.success_message)\n        return super(TopicDeleteView, self).delete(request, *args, **kwargs)\n\n    def get_success_url(self):\n        return reverse('project-detail',\n                       kwargs={'slug': self.object.project.slug})\n", "path": "euth/communitydebate/views.py"}]}