prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Required file question breaks validation on edit
  Editing an order with a product with a required file question breaks when the customer tries to edit the order. In that case even if the customer already provided a file earlier the validation for the question fails on edit.
  Required file question breaks validation on edit
  Editing an order with a product with a required file question breaks when the customer tries to edit the order. In that case even if the customer already provided a file earlier the validation for the question fails on edit.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/pretix/base/forms/widgets.py`
  Content:
  ```
  1 import os
  2 
  3 from django import forms
  4 from django.utils.formats import get_format
  5 from django.utils.functional import lazy
  6 from django.utils.timezone import now
  7 from django.utils.translation import ugettext_lazy as _
  8 
  9 from pretix.base.models import OrderPosition
  10 from pretix.multidomain.urlreverse import eventreverse
  11 
  12 
  13 class DatePickerWidget(forms.DateInput):
  14     def __init__(self, attrs=None, date_format=None):
  15         attrs = attrs or {}
  16         if 'placeholder' in attrs:
  17             del attrs['placeholder']
  18         date_attrs = dict(attrs)
  19         date_attrs.setdefault('class', 'form-control')
  20         date_attrs['class'] += ' datepickerfield'
  21 
  22         df = date_format or get_format('DATE_INPUT_FORMATS')[0]
  23         date_attrs['placeholder'] = now().replace(
  24             year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0
  25         ).strftime(df)
  26 
  27         forms.DateInput.__init__(self, date_attrs, date_format)
  28 
  29 
  30 class TimePickerWidget(forms.TimeInput):
  31     def __init__(self, attrs=None, time_format=None):
  32         attrs = attrs or {}
  33         if 'placeholder' in attrs:
  34             del attrs['placeholder']
  35         time_attrs = dict(attrs)
  36         time_attrs.setdefault('class', 'form-control')
  37         time_attrs['class'] += ' timepickerfield'
  38 
  39         tf = time_format or get_format('TIME_INPUT_FORMATS')[0]
  40         time_attrs['placeholder'] = now().replace(
  41             year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0
  42         ).strftime(tf)
  43 
  44         forms.TimeInput.__init__(self, time_attrs, time_format)
  45 
  46 
  47 class UploadedFileWidget(forms.ClearableFileInput):
  48     def __init__(self, *args, **kwargs):
  49         self.position = kwargs.pop('position')
  50         self.event = kwargs.pop('event')
  51         self.answer = kwargs.pop('answer')
  52         super().__init__(*args, **kwargs)
  53 
  54     class FakeFile:
  55         def __init__(self, file, position, event, answer):
  56             self.file = file
  57             self.position = position
  58             self.event = event
  59             self.answer = answer
  60 
  61         def __str__(self):
  62             return os.path.basename(self.file.name).split('.', 1)[-1]
  63 
  64         @property
  65         def url(self):
  66             if isinstance(self.position, OrderPosition):
  67                 return eventreverse(self.event, 'presale:event.order.download.answer', kwargs={
  68                     'order': self.position.order.code,
  69                     'secret': self.position.order.secret,
  70                     'answer': self.answer.pk,
  71                 })
  72             else:
  73                 return eventreverse(self.event, 'presale:event.cart.download.answer', kwargs={
  74                     'answer': self.answer.pk,
  75                 })
  76 
  77     def format_value(self, value):
  78         if self.is_initial(value):
  79             return self.FakeFile(value, self.position, self.event, self.answer)
  80 
  81 
  82 class SplitDateTimePickerWidget(forms.SplitDateTimeWidget):
  83     template_name = 'pretixbase/forms/widgets/splitdatetime.html'
  84 
  85     def __init__(self, attrs=None, date_format=None, time_format=None):
  86         attrs = attrs or {}
  87         if 'placeholder' in attrs:
  88             del attrs['placeholder']
  89         date_attrs = dict(attrs)
  90         time_attrs = dict(attrs)
  91         date_attrs.setdefault('class', 'form-control splitdatetimepart')
  92         time_attrs.setdefault('class', 'form-control splitdatetimepart')
  93         date_attrs.setdefault('autocomplete', 'off')
  94         time_attrs.setdefault('autocomplete', 'off')
  95         date_attrs['class'] += ' datepickerfield'
  96         time_attrs['class'] += ' timepickerfield'
  97 
  98         def date_placeholder():
  99             df = date_format or get_format('DATE_INPUT_FORMATS')[0]
  100             return now().replace(
  101                 year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0
  102             ).strftime(df)
  103 
  104         def time_placeholder():
  105             tf = time_format or get_format('TIME_INPUT_FORMATS')[0]
  106             return now().replace(
  107                 year=2000, month=1, day=1, hour=0, minute=0, second=0, microsecond=0
  108             ).strftime(tf)
  109 
  110         date_attrs['placeholder'] = lazy(date_placeholder, str)
  111         time_attrs['placeholder'] = lazy(time_placeholder, str)
  112 
  113         widgets = (
  114             forms.DateInput(attrs=date_attrs, format=date_format),
  115             forms.TimeInput(attrs=time_attrs, format=time_format),
  116         )
  117         # Skip one hierarchy level
  118         forms.MultiWidget.__init__(self, widgets, attrs)
  119 
  120 
  121 class BusinessBooleanRadio(forms.RadioSelect):
  122     def __init__(self, require_business=False, attrs=None):
  123         self.require_business = require_business
  124         if self.require_business:
  125             choices = (
  126                 ('business', _('Business customer')),
  127             )
  128         else:
  129             choices = (
  130                 ('individual', _('Individual customer')),
  131                 ('business', _('Business customer')),
  132             )
  133         super().__init__(attrs, choices)
  134 
  135     def format_value(self, value):
  136         if self.require_business:
  137             return 'business'
  138         try:
  139             return {True: 'business', False: 'individual'}[value]
  140         except KeyError:
  141             return 'individual'
  142 
  143     def value_from_datadict(self, data, files, name):
  144         value = data.get(name)
  145         if self.require_business:
  146             return True
  147         return {
  148             'business': True,
  149             True: True,
  150             'True': True,
  151             'individual': False,
  152             'False': False,
  153             False: False,
  154         }.get(value)
  155
  ```
  --- 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/src/pretix/base/forms/widgets.py b/src/pretix/base/forms/widgets.py
  --- a/src/pretix/base/forms/widgets.py
  +++ b/src/pretix/base/forms/widgets.py
  @@ -46,6 +46,14 @@
   
   class UploadedFileWidget(forms.ClearableFileInput):
       def __init__(self, *args, **kwargs):
  +        # Browsers can't recognize that the server already has a file uploaded
  +        # Don't mark this input as being required if we already have an answer
  +        # (this needs to be done via the attrs, otherwise we wouldn't get the "required" star on the field label)
  +        attrs = kwargs.get('attrs', {})
  +        if kwargs.get('required') and kwargs.get('initial'):
  +            attrs.update({'required': None})
  +        kwargs.update({'attrs': attrs})
  +
           self.position = kwargs.pop('position')
           self.event = kwargs.pop('event')
           self.answer = kwargs.pop('answer')
  
verification_info: {"golden_diff": "diff --git a/src/pretix/base/forms/widgets.py b/src/pretix/base/forms/widgets.py\n--- a/src/pretix/base/forms/widgets.py\n+++ b/src/pretix/base/forms/widgets.py\n@@ -46,6 +46,14 @@\n \n class UploadedFileWidget(forms.ClearableFileInput):\n     def __init__(self, *args, **kwargs):\n+        # Browsers can't recognize that the server already has a file uploaded\n+        # Don't mark this input as being required if we already have an answer\n+        # (this needs to be done via the attrs, otherwise we wouldn't get the \"required\" star on the field label)\n+        attrs = kwargs.get('attrs', {})\n+        if kwargs.get('required') and kwargs.get('initial'):\n+            attrs.update({'required': None})\n+        kwargs.update({'attrs': attrs})\n+\n         self.position = kwargs.pop('position')\n         self.event = kwargs.pop('event')\n         self.answer = kwargs.pop('answer')\n", "issue": "Required file question breaks validation on edit\nEditing an order with a product with a required file question breaks when the customer tries to edit the order. In that case even if the customer already provided a file earlier the validation for the question fails on edit.\nRequired file question breaks validation on edit\nEditing an order with a product with a required file question breaks when the customer tries to edit the order. In that case even if the customer already provided a file earlier the validation for the question fails on edit.\n", "before_files": [{"content": "import os\n\nfrom django import forms\nfrom django.utils.formats import get_format\nfrom django.utils.functional import lazy\nfrom django.utils.timezone import now\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom pretix.base.models import OrderPosition\nfrom pretix.multidomain.urlreverse import eventreverse\n\n\nclass DatePickerWidget(forms.DateInput):\n    def __init__(self, attrs=None, date_format=None):\n        attrs = attrs or {}\n        if 'placeholder' in attrs:\n            del attrs['placeholder']\n        date_attrs = dict(attrs)\n        date_attrs.setdefault('class', 'form-control')\n        date_attrs['class'] += ' datepickerfield'\n\n        df = date_format or get_format('DATE_INPUT_FORMATS')[0]\n        date_attrs['placeholder'] = now().replace(\n            year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0\n        ).strftime(df)\n\n        forms.DateInput.__init__(self, date_attrs, date_format)\n\n\nclass TimePickerWidget(forms.TimeInput):\n    def __init__(self, attrs=None, time_format=None):\n        attrs = attrs or {}\n        if 'placeholder' in attrs:\n            del attrs['placeholder']\n        time_attrs = dict(attrs)\n        time_attrs.setdefault('class', 'form-control')\n        time_attrs['class'] += ' timepickerfield'\n\n        tf = time_format or get_format('TIME_INPUT_FORMATS')[0]\n        time_attrs['placeholder'] = now().replace(\n            year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0\n        ).strftime(tf)\n\n        forms.TimeInput.__init__(self, time_attrs, time_format)\n\n\nclass UploadedFileWidget(forms.ClearableFileInput):\n    def __init__(self, *args, **kwargs):\n        self.position = kwargs.pop('position')\n        self.event = kwargs.pop('event')\n        self.answer = kwargs.pop('answer')\n        super().__init__(*args, **kwargs)\n\n    class FakeFile:\n        def __init__(self, file, position, event, answer):\n            self.file = file\n            self.position = position\n            self.event = event\n            self.answer = answer\n\n        def __str__(self):\n            return os.path.basename(self.file.name).split('.', 1)[-1]\n\n        @property\n        def url(self):\n            if isinstance(self.position, OrderPosition):\n                return eventreverse(self.event, 'presale:event.order.download.answer', kwargs={\n                    'order': self.position.order.code,\n                    'secret': self.position.order.secret,\n                    'answer': self.answer.pk,\n                })\n            else:\n                return eventreverse(self.event, 'presale:event.cart.download.answer', kwargs={\n                    'answer': self.answer.pk,\n                })\n\n    def format_value(self, value):\n        if self.is_initial(value):\n            return self.FakeFile(value, self.position, self.event, self.answer)\n\n\nclass SplitDateTimePickerWidget(forms.SplitDateTimeWidget):\n    template_name = 'pretixbase/forms/widgets/splitdatetime.html'\n\n    def __init__(self, attrs=None, date_format=None, time_format=None):\n        attrs = attrs or {}\n        if 'placeholder' in attrs:\n            del attrs['placeholder']\n        date_attrs = dict(attrs)\n        time_attrs = dict(attrs)\n        date_attrs.setdefault('class', 'form-control splitdatetimepart')\n        time_attrs.setdefault('class', 'form-control splitdatetimepart')\n        date_attrs.setdefault('autocomplete', 'off')\n        time_attrs.setdefault('autocomplete', 'off')\n        date_attrs['class'] += ' datepickerfield'\n        time_attrs['class'] += ' timepickerfield'\n\n        def date_placeholder():\n            df = date_format or get_format('DATE_INPUT_FORMATS')[0]\n            return now().replace(\n                year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0\n            ).strftime(df)\n\n        def time_placeholder():\n            tf = time_format or get_format('TIME_INPUT_FORMATS')[0]\n            return now().replace(\n                year=2000, month=1, day=1, hour=0, minute=0, second=0, microsecond=0\n            ).strftime(tf)\n\n        date_attrs['placeholder'] = lazy(date_placeholder, str)\n        time_attrs['placeholder'] = lazy(time_placeholder, str)\n\n        widgets = (\n            forms.DateInput(attrs=date_attrs, format=date_format),\n            forms.TimeInput(attrs=time_attrs, format=time_format),\n        )\n        # Skip one hierarchy level\n        forms.MultiWidget.__init__(self, widgets, attrs)\n\n\nclass BusinessBooleanRadio(forms.RadioSelect):\n    def __init__(self, require_business=False, attrs=None):\n        self.require_business = require_business\n        if self.require_business:\n            choices = (\n                ('business', _('Business customer')),\n            )\n        else:\n            choices = (\n                ('individual', _('Individual customer')),\n                ('business', _('Business customer')),\n            )\n        super().__init__(attrs, choices)\n\n    def format_value(self, value):\n        if self.require_business:\n            return 'business'\n        try:\n            return {True: 'business', False: 'individual'}[value]\n        except KeyError:\n            return 'individual'\n\n    def value_from_datadict(self, data, files, name):\n        value = data.get(name)\n        if self.require_business:\n            return True\n        return {\n            'business': True,\n            True: True,\n            'True': True,\n            'individual': False,\n            'False': False,\n            False: False,\n        }.get(value)\n", "path": "src/pretix/base/forms/widgets.py"}], "after_files": [{"content": "import os\n\nfrom django import forms\nfrom django.utils.formats import get_format\nfrom django.utils.functional import lazy\nfrom django.utils.timezone import now\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom pretix.base.models import OrderPosition\nfrom pretix.multidomain.urlreverse import eventreverse\n\n\nclass DatePickerWidget(forms.DateInput):\n    def __init__(self, attrs=None, date_format=None):\n        attrs = attrs or {}\n        if 'placeholder' in attrs:\n            del attrs['placeholder']\n        date_attrs = dict(attrs)\n        date_attrs.setdefault('class', 'form-control')\n        date_attrs['class'] += ' datepickerfield'\n\n        df = date_format or get_format('DATE_INPUT_FORMATS')[0]\n        date_attrs['placeholder'] = now().replace(\n            year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0\n        ).strftime(df)\n\n        forms.DateInput.__init__(self, date_attrs, date_format)\n\n\nclass TimePickerWidget(forms.TimeInput):\n    def __init__(self, attrs=None, time_format=None):\n        attrs = attrs or {}\n        if 'placeholder' in attrs:\n            del attrs['placeholder']\n        time_attrs = dict(attrs)\n        time_attrs.setdefault('class', 'form-control')\n        time_attrs['class'] += ' timepickerfield'\n\n        tf = time_format or get_format('TIME_INPUT_FORMATS')[0]\n        time_attrs['placeholder'] = now().replace(\n            year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0\n        ).strftime(tf)\n\n        forms.TimeInput.__init__(self, time_attrs, time_format)\n\n\nclass UploadedFileWidget(forms.ClearableFileInput):\n    def __init__(self, *args, **kwargs):\n        # Browsers can't recognize that the server already has a file uploaded\n        # Don't mark this input as being required if we already have an answer\n        # (this needs to be done via the attrs, otherwise we wouldn't get the \"required\" star on the field label)\n        attrs = kwargs.get('attrs', {})\n        if kwargs.get('required') and kwargs.get('initial'):\n            attrs.update({'required': None})\n        kwargs.update({'attrs': attrs})\n\n        self.position = kwargs.pop('position')\n        self.event = kwargs.pop('event')\n        self.answer = kwargs.pop('answer')\n        super().__init__(*args, **kwargs)\n\n    class FakeFile:\n        def __init__(self, file, position, event, answer):\n            self.file = file\n            self.position = position\n            self.event = event\n            self.answer = answer\n\n        def __str__(self):\n            return os.path.basename(self.file.name).split('.', 1)[-1]\n\n        @property\n        def url(self):\n            if isinstance(self.position, OrderPosition):\n                return eventreverse(self.event, 'presale:event.order.download.answer', kwargs={\n                    'order': self.position.order.code,\n                    'secret': self.position.order.secret,\n                    'answer': self.answer.pk,\n                })\n            else:\n                return eventreverse(self.event, 'presale:event.cart.download.answer', kwargs={\n                    'answer': self.answer.pk,\n                })\n\n    def format_value(self, value):\n        if self.is_initial(value):\n            return self.FakeFile(value, self.position, self.event, self.answer)\n\n\nclass SplitDateTimePickerWidget(forms.SplitDateTimeWidget):\n    template_name = 'pretixbase/forms/widgets/splitdatetime.html'\n\n    def __init__(self, attrs=None, date_format=None, time_format=None):\n        attrs = attrs or {}\n        if 'placeholder' in attrs:\n            del attrs['placeholder']\n        date_attrs = dict(attrs)\n        time_attrs = dict(attrs)\n        date_attrs.setdefault('class', 'form-control splitdatetimepart')\n        time_attrs.setdefault('class', 'form-control splitdatetimepart')\n        date_attrs.setdefault('autocomplete', 'off')\n        time_attrs.setdefault('autocomplete', 'off')\n        date_attrs['class'] += ' datepickerfield'\n        time_attrs['class'] += ' timepickerfield'\n\n        def date_placeholder():\n            df = date_format or get_format('DATE_INPUT_FORMATS')[0]\n            return now().replace(\n                year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0\n            ).strftime(df)\n\n        def time_placeholder():\n            tf = time_format or get_format('TIME_INPUT_FORMATS')[0]\n            return now().replace(\n                year=2000, month=1, day=1, hour=0, minute=0, second=0, microsecond=0\n            ).strftime(tf)\n\n        date_attrs['placeholder'] = lazy(date_placeholder, str)\n        time_attrs['placeholder'] = lazy(time_placeholder, str)\n\n        widgets = (\n            forms.DateInput(attrs=date_attrs, format=date_format),\n            forms.TimeInput(attrs=time_attrs, format=time_format),\n        )\n        # Skip one hierarchy level\n        forms.MultiWidget.__init__(self, widgets, attrs)\n\n\nclass BusinessBooleanRadio(forms.RadioSelect):\n    def __init__(self, require_business=False, attrs=None):\n        self.require_business = require_business\n        if self.require_business:\n            choices = (\n                ('business', _('Business customer')),\n            )\n        else:\n            choices = (\n                ('individual', _('Individual customer')),\n                ('business', _('Business customer')),\n            )\n        super().__init__(attrs, choices)\n\n    def format_value(self, value):\n        if self.require_business:\n            return 'business'\n        try:\n            return {True: 'business', False: 'individual'}[value]\n        except KeyError:\n            return 'individual'\n\n    def value_from_datadict(self, data, files, name):\n        value = data.get(name)\n        if self.require_business:\n            return True\n        return {\n            'business': True,\n            True: True,\n            'True': True,\n            'individual': False,\n            'False': False,\n            False: False,\n        }.get(value)\n", "path": "src/pretix/base/forms/widgets.py"}]}