We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
improve accessibility of image upload
* add alt attribute with the filename
* if there is no image uploaded the image tag should not be there
* the label's `for` attribute doesn't reference the file input's id.

The first part causes the HTML to be invalid, which is part of the BITV Test "4.1.1a Valides HTML".
The third part is part of the BITV Test "3.3.2a Formularfelder richtig beschriftet".

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `adhocracy4/images/widgets.py`
Content:
```
1 from os.path import basename
2 
3 from django.contrib.staticfiles.storage import staticfiles_storage
4 from django.forms import widgets
5 from django.template import loader
6 from django.utils.html import conditional_escape
7 from django.utils.translation import ugettext
8 
9 
10 class ImageInputWidget(widgets.ClearableFileInput):
11 
12     """
13     A project-specific improved version of the clearable file upload.
14 
15     Allows to upload and delete uploaded files. It doesn't passing attributes
16     using the positional `attrs` argument and hard codes css files.
17     """
18     class Media:
19         js = (staticfiles_storage.url('a4images/imageUploader.js'),)
20 
21     def render(self, name, value, attrs=None):
22 
23         has_image_set = self.is_initial(value)
24         is_required = self.is_required
25 
26         file_placeholder = ugettext('Select a picture from your local folder.')
27         file_input = super().render(name, None, {
28             'id': name,
29             'class': 'form-control form-control-file'
30         })
31 
32         if has_image_set:
33             file_name = basename(value.name)
34             file_url = conditional_escape(value.url)
35         else:
36             file_name = ""
37             file_url = ""
38 
39         text_input = widgets.TextInput().render('__noname__', file_name, {
40             'class': 'form-control form-control-file-dummy',
41             'placeholder': file_placeholder,
42             'tabindex': '-1'
43         })
44 
45         checkbox_id = self.clear_checkbox_id(name)
46         checkbox_name = self.clear_checkbox_name(name)
47         checkbox_input = widgets.CheckboxInput().render(checkbox_name, False, {
48             'id': checkbox_id,
49             'class': 'clear-image',
50             'data-upload-clear': name,
51         })
52 
53         context = {
54             'name': name,
55             'has_image_set': has_image_set,
56             'is_required': is_required,
57             'file_url': file_url,
58             'file_input': file_input,
59             'file_id': name + '-file',
60             'text_input': text_input,
61             'checkbox_input': checkbox_input,
62             'checkbox_id': checkbox_id
63         }
64 
65         return loader.render_to_string(
66             'a4images/image_upload_widget.html',
67             context
68         )
69 
70     def value_from_datadict(self, data, files, name):
71         """
72         Modify value_from_datadict, so that delete takes precedence over
73         upload.
74         """
75         file_value = super(widgets.ClearableFileInput, self)\
76             .value_from_datadict(data, files, name)
77         checkbox_value = widgets.CheckboxInput()\
78             .value_from_datadict(data, files, self.clear_checkbox_name(name))
79         if not self.is_required and checkbox_value:
80             return False
81         return file_value
82
```
--- 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/adhocracy4/images/widgets.py b/adhocracy4/images/widgets.py
--- a/adhocracy4/images/widgets.py
+++ b/adhocracy4/images/widgets.py
@@ -19,13 +19,13 @@
         js = (staticfiles_storage.url('a4images/imageUploader.js'),)
 
     def render(self, name, value, attrs=None):
-
+        html_id = attrs and attrs.get('id', name) or name
         has_image_set = self.is_initial(value)
         is_required = self.is_required
 
         file_placeholder = ugettext('Select a picture from your local folder.')
         file_input = super().render(name, None, {
-            'id': name,
+            'id': html_id,
             'class': 'form-control form-control-file'
         })
 
@@ -39,7 +39,8 @@
         text_input = widgets.TextInput().render('__noname__', file_name, {
             'class': 'form-control form-control-file-dummy',
             'placeholder': file_placeholder,
-            'tabindex': '-1'
+            'tabindex': '-1',
+            'id': 'text-{}'.format(html_id)
         })
 
         checkbox_id = self.clear_checkbox_id(name)
@@ -47,16 +48,16 @@
         checkbox_input = widgets.CheckboxInput().render(checkbox_name, False, {
             'id': checkbox_id,
             'class': 'clear-image',
-            'data-upload-clear': name,
+            'data-upload-clear': html_id,
         })
 
         context = {
-            'name': name,
+            'id': html_id,
             'has_image_set': has_image_set,
             'is_required': is_required,
             'file_url': file_url,
             'file_input': file_input,
-            'file_id': name + '-file',
+            'file_id': html_id + '-file',
             'text_input': text_input,
             'checkbox_input': checkbox_input,
             'checkbox_id': checkbox_id

{"golden_diff": "diff --git a/adhocracy4/images/widgets.py b/adhocracy4/images/widgets.py\n--- a/adhocracy4/images/widgets.py\n+++ b/adhocracy4/images/widgets.py\n@@ -19,13 +19,13 @@\n         js = (staticfiles_storage.url('a4images/imageUploader.js'),)\n \n     def render(self, name, value, attrs=None):\n-\n+        html_id = attrs and attrs.get('id', name) or name\n         has_image_set = self.is_initial(value)\n         is_required = self.is_required\n \n         file_placeholder = ugettext('Select a picture from your local folder.')\n         file_input = super().render(name, None, {\n-            'id': name,\n+            'id': html_id,\n             'class': 'form-control form-control-file'\n         })\n \n@@ -39,7 +39,8 @@\n         text_input = widgets.TextInput().render('__noname__', file_name, {\n             'class': 'form-control form-control-file-dummy',\n             'placeholder': file_placeholder,\n-            'tabindex': '-1'\n+            'tabindex': '-1',\n+            'id': 'text-{}'.format(html_id)\n         })\n \n         checkbox_id = self.clear_checkbox_id(name)\n@@ -47,16 +48,16 @@\n         checkbox_input = widgets.CheckboxInput().render(checkbox_name, False, {\n             'id': checkbox_id,\n             'class': 'clear-image',\n-            'data-upload-clear': name,\n+            'data-upload-clear': html_id,\n         })\n \n         context = {\n-            'name': name,\n+            'id': html_id,\n             'has_image_set': has_image_set,\n             'is_required': is_required,\n             'file_url': file_url,\n             'file_input': file_input,\n-            'file_id': name + '-file',\n+            'file_id': html_id + '-file',\n             'text_input': text_input,\n             'checkbox_input': checkbox_input,\n             'checkbox_id': checkbox_id\n", "issue": "improve accessibility of image upload\n* add alt attribute with the filename\r\n* if there is no image uploaded the image tag should not be there\r\n* the label's `for` attribute doesn't reference the file input's id.\r\n\r\nThe first part causes the HTML to be invalid, which is part of the BITV Test \"4.1.1a Valides HTML\".\r\nThe third part is part of the BITV Test \"3.3.2a Formularfelder richtig beschriftet\".\n", "before_files": [{"content": "from os.path import basename\n\nfrom django.contrib.staticfiles.storage import staticfiles_storage\nfrom django.forms import widgets\nfrom django.template import loader\nfrom django.utils.html import conditional_escape\nfrom django.utils.translation import ugettext\n\n\nclass ImageInputWidget(widgets.ClearableFileInput):\n\n    \"\"\"\n    A project-specific improved version of the clearable file upload.\n\n    Allows to upload and delete uploaded files. It doesn't passing attributes\n    using the positional `attrs` argument and hard codes css files.\n    \"\"\"\n    class Media:\n        js = (staticfiles_storage.url('a4images/imageUploader.js'),)\n\n    def render(self, name, value, attrs=None):\n\n        has_image_set = self.is_initial(value)\n        is_required = self.is_required\n\n        file_placeholder = ugettext('Select a picture from your local folder.')\n        file_input = super().render(name, None, {\n            'id': name,\n            'class': 'form-control form-control-file'\n        })\n\n        if has_image_set:\n            file_name = basename(value.name)\n            file_url = conditional_escape(value.url)\n        else:\n            file_name = \"\"\n            file_url = \"\"\n\n        text_input = widgets.TextInput().render('__noname__', file_name, {\n            'class': 'form-control form-control-file-dummy',\n            'placeholder': file_placeholder,\n            'tabindex': '-1'\n        })\n\n        checkbox_id = self.clear_checkbox_id(name)\n        checkbox_name = self.clear_checkbox_name(name)\n        checkbox_input = widgets.CheckboxInput().render(checkbox_name, False, {\n            'id': checkbox_id,\n            'class': 'clear-image',\n            'data-upload-clear': name,\n        })\n\n        context = {\n            'name': name,\n            'has_image_set': has_image_set,\n            'is_required': is_required,\n            'file_url': file_url,\n            'file_input': file_input,\n            'file_id': name + '-file',\n            'text_input': text_input,\n            'checkbox_input': checkbox_input,\n            'checkbox_id': checkbox_id\n        }\n\n        return loader.render_to_string(\n            'a4images/image_upload_widget.html',\n            context\n        )\n\n    def value_from_datadict(self, data, files, name):\n        \"\"\"\n        Modify value_from_datadict, so that delete takes precedence over\n        upload.\n        \"\"\"\n        file_value = super(widgets.ClearableFileInput, self)\\\n            .value_from_datadict(data, files, name)\n        checkbox_value = widgets.CheckboxInput()\\\n            .value_from_datadict(data, files, self.clear_checkbox_name(name))\n        if not self.is_required and checkbox_value:\n            return False\n        return file_value\n", "path": "adhocracy4/images/widgets.py"}], "after_files": [{"content": "from os.path import basename\n\nfrom django.contrib.staticfiles.storage import staticfiles_storage\nfrom django.forms import widgets\nfrom django.template import loader\nfrom django.utils.html import conditional_escape\nfrom django.utils.translation import ugettext\n\n\nclass ImageInputWidget(widgets.ClearableFileInput):\n\n    \"\"\"\n    A project-specific improved version of the clearable file upload.\n\n    Allows to upload and delete uploaded files. It doesn't passing attributes\n    using the positional `attrs` argument and hard codes css files.\n    \"\"\"\n    class Media:\n        js = (staticfiles_storage.url('a4images/imageUploader.js'),)\n\n    def render(self, name, value, attrs=None):\n        html_id = attrs and attrs.get('id', name) or name\n        has_image_set = self.is_initial(value)\n        is_required = self.is_required\n\n        file_placeholder = ugettext('Select a picture from your local folder.')\n        file_input = super().render(name, None, {\n            'id': html_id,\n            'class': 'form-control form-control-file'\n        })\n\n        if has_image_set:\n            file_name = basename(value.name)\n            file_url = conditional_escape(value.url)\n        else:\n            file_name = \"\"\n            file_url = \"\"\n\n        text_input = widgets.TextInput().render('__noname__', file_name, {\n            'class': 'form-control form-control-file-dummy',\n            'placeholder': file_placeholder,\n            'tabindex': '-1',\n            'id': 'text-{}'.format(html_id)\n        })\n\n        checkbox_id = self.clear_checkbox_id(name)\n        checkbox_name = self.clear_checkbox_name(name)\n        checkbox_input = widgets.CheckboxInput().render(checkbox_name, False, {\n            'id': checkbox_id,\n            'class': 'clear-image',\n            'data-upload-clear': html_id,\n        })\n\n        context = {\n            'id': html_id,\n            'has_image_set': has_image_set,\n            'is_required': is_required,\n            'file_url': file_url,\n            'file_input': file_input,\n            'file_id': html_id + '-file',\n            'text_input': text_input,\n            'checkbox_input': checkbox_input,\n            'checkbox_id': checkbox_id\n        }\n\n        return loader.render_to_string(\n            'a4images/image_upload_widget.html',\n            context\n        )\n\n    def value_from_datadict(self, data, files, name):\n        \"\"\"\n        Modify value_from_datadict, so that delete takes precedence over\n        upload.\n        \"\"\"\n        file_value = super(widgets.ClearableFileInput, self)\\\n            .value_from_datadict(data, files, name)\n        checkbox_value = widgets.CheckboxInput()\\\n            .value_from_datadict(data, files, self.clear_checkbox_name(name))\n        if not self.is_required and checkbox_value:\n            return False\n        return file_value\n", "path": "adhocracy4/images/widgets.py"}]}