from django import forms

import re
from sicurezza.views import getSecurityLevelAll
from configurazione.views import *

from .models import *

class formSqlDatabase(forms.Form):
  def __init__(self,*args,**kwargs):
    forms.Form.__init__(self,*args,**kwargs)
    self.fields['server'] = forms.ChoiceField(required=False,choices=self.listsqlserver())
    self.fields['username'] = forms.CharField(required=True)
    self.fields['password'] = forms.CharField(required=True)
    self.fields['nome'] = forms.CharField(required=True)
    self.fields['enabled'] = forms.BooleanField(required=False,initial=True)
    self.fields['locked'] = forms.BooleanField(required=False,initial=False)
    self.fields['noneseguire'] = forms.BooleanField(required=False,initial=False)
    self.fields['tobedeleted'] = forms.BooleanField(required=False,initial=False)
    self.fields['timestamp'] = forms.DateTimeField(required=False)
    self.fields['nota'] = forms.CharField(required=False)
    self.fields['mail'] = forms.CharField(required=False)
    self.fields['mail_send'] = forms.BooleanField(required=False,initial=False)
    self.fields['password_last_update'] = forms.BooleanField(required=False)
  # lista dei mail server disponibili
  def listsqlserver(self):
    _sqlserver = []
    m = SqlServer.objects.all().filter(enabled=True).order_by('nome')
    for i in m:
      _sqlserver.append((i.id,i.nome))
    return _sqlserver

class formSqlServer(forms.Form):
  def __init__(self,*args,**kwargs):
    forms.Form.__init__(self,*args,**kwargs)
    self.fields['nome'] = forms.CharField(required=True)
    self.fields['server'] = forms.CharField(required=True)
    self.fields['enabled'] = forms.BooleanField(required=False)
    self.fields['adminuser'] = forms.CharField(required=False)
    self.fields['adminpass'] = forms.CharField(required=False,widget=forms.PasswordInput)
    self.fields['nota'] = forms.CharField(required=False)

