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['allegati'] = MultipleFileField(required=False)
    self.fields['descrizione'] = forms.CharField(required=False)
    self.fields['pertutti'] = forms.BooleanField(required=False)
    self.fields['comunicazione'] = 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)

class formMultipleCheckBox(forms.Form):
  choices = []
  def __init__(self,*args,**kwargs):
    forms.Form.__init__(self,*args,**kwargs)
    self.fields['select'] = forms.MultipleChoiceField(required=False,widget=forms.CheckboxSelectMultiple(),choices=self.choices)
  def c(self,lista):
    for u in lista:
      self.choices.append((u.id,u.id),)
    print('choices',self.choices)
