prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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".
  
  </issue>
  <code>
  [start of adhocracy4/images/widgets.py]
  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 of adhocracy4/images/widgets.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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
  
verification_info: {"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"}]}