from django import forms

from .models import *
from utenti.models import *

class ListAddAccountForm(forms.Form):

  def __init__(self,*args,**kwargs):
    super(forms.Form,self).__init__(*args,**kwargs)

  def getUser(self):
    u = User.objects.filter(domain_id=self.domain).filter(enabled=1).order_by('nome')
    user = [(0,'-')]
    for i in u:
      user.append((i.id,f'{i.mail}@{i.domain.nome}'))
    print("Numero di utenti potenziali presenti",len(user))
    return user

  def update(self,domain=0):
    self.domain=domain
    self.fields['mail_interne'] = forms.ChoiceField(label="Mail Interne",choices=self.getUser(),required=False)
    self.fields['mail_esterne'] = forms.CharField(label='Mail Esterne',initial='',required=False)

  def getLevel(self):
    securitylevel = []
    s = getSecurityLevelAll()
    #s = SecurityLevel.objects.filter(enabled=True).order_by('nome')
    for i in s:
      securitylevel.append((i.id,i.nome))
    return securitylevel

class ListAddListForm(forms.Form):

  def __init__(self,*args,**kwargs):
    super(forms.Form,self).__init__(*args,**kwargs)

    self.fields['nome'] = forms.CharField(initial='',required=True)
    self.fields['postmaster'] = forms.CharField(initial='',required=True)

    '''
  tobedeleted = models.BooleanField(db_column='tobedeleted',default=0)
  enabled = models.BooleanField(db_column='enabled',default=1)
  addinprogress = models.BooleanField(db_column='addinprogress',default=0)
  delinprogress = models.BooleanField(db_column='delinprogress',default=0)
  disinprogress = models.BooleanField(db_column='disinprogress',default=0)
  enainprogress = models.BooleanField(db_column='enainprogress',default=0)
  postmaster = models.CharField(db_column='postmaster',max_length=64)
  '''
