from django import  forms

class MultipleFileInput(forms.ClearableFileInput):
    allow_multiple_selected = True

class MultipleFileField(forms.FileField):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault("widget", MultipleFileInput())
        super().__init__(*args, **kwargs)

    def clean(self, data, initial=None):
        single_file_clean = super().clean
        if isinstance(data, (list, tuple)):
            result = [single_file_clean(d, initial) for d in data]
        else:
            result = [single_file_clean(data, initial)]
        return result

class AdminUpload(forms.Form):
  def __init__(self,*args,**kwargs):
    forms.Form.__init__(self,*args,**kwargs)
    self.fields['indice'] = forms.FileField(required=False)
    self.fields['allegati'] = MultipleFileField(required=False)
    self.fields['descrizione'] = forms.CharField(required=False)
    self.fields['pertutti'] = forms.BooleanField(required=False)

class DeleteOldDocuments(forms.Form):
  def __init(self,*args,**kwargs):
    forms.Form.__init__(self,*args,**kwargs)
    self.fields['limite'] = forms.CharField(required=True)
