# Path: core/forms/fields.py
# class CronFormField(forms.CharField):
#     def __init__(self, *args, **kwargs):
#         defaults = {'widget': forms.TextInput}
#         kwargs.update(defaults)
#         super(CronFormField, self).__init__(*args, **kwargs)
# 
#     def validate(self, value):
#         super(CronFormField, self).validate(value)
#         models.validate_cron(value)
# 
# Path: core/models.py
# def create_auth_token(sender, instance=None, created=False, **kwargs):
# def validate_cron(value):
#     def __init__(self, *args, **kwargs):
#     def formfield(self, **kwargs):
#     def validate(self, value, model_instance):
#     def get_actual_hosts(self) -> models.QuerySet:
#     def get_playbook_name(self) -> str:
#     def get_hosts_without_groups(self) -> models.QuerySet:
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def get_vars(self):
#     def __str__(self):
#     def __str__(self):
#     def create_task(self, user, is_automatically_created=False, repeat_number=0):
#     def have_uncompleted_task(self):
#     def __str__(self):
#     def get_ansible_command(self):
#     def get_duration(self) -> datetime.timedelta:
#     def stop(self):
#     def __str__(self):
# class CronField(models.CharField):
# class TaskOperationsMixin:
# class Variable(models.Model):
#     class Meta:
# class HostGroup(models.Model):
#     class Meta:
# class Host(models.Model):
#     class Meta:
# class AnsibleUser(models.Model):
#     class Meta:
# class TaskTemplate(TaskOperationsMixin, models.Model):
#     class Meta:
# class RepeatSetting(models.Model):
# class Task(TaskOperationsMixin, models.Model):
#     class Meta:
# class TaskLog(models.Model):
#     class Meta:


from django import forms
from django.conf import settings
from django.db.models.functions import Lower
from django.utils import timezone
from core.forms.fields import CronFormField
from core import models



class Search(forms.Form):
    name = forms.CharField(required=False)
    hosts = forms.ModelMultipleChoiceField(required=False, queryset=models.Host.objects.order_by(Lower('name')),
                                           widget=forms.SelectMultiple(attrs={'class': 'need-select2'}))
    host_groups = forms.ModelMultipleChoiceField(label='Groups', required=False,
                                                 queryset=models.HostGroup.objects.order_by(Lower('name')),
                                                 widget=forms.SelectMultiple(attrs={'class': 'need-select2'}))


class Edit(forms.ModelForm):
    inventory = forms.FileField(required=False)
    hosts = forms.ModelMultipleChoiceField(queryset=models.Host.objects.order_by(Lower('name')), required=False,
                                           widget=forms.SelectMultiple(attrs={'class': 'need-select2'}))
    host_groups = forms.ModelMultipleChoiceField(queryset=models.HostGroup.objects.order_by(Lower('name')),
                                                 required=False,
                                                 widget=forms.SelectMultiple(attrs={'class': 'need-select2'}))
    playbook = forms.FilePathField(path=settings.ANSIBLE_PLAYBOOKS_PATH, match='.*\.yml$',
                                   widget=forms.Select(attrs={'class': 'need-select2'}))
    ansible_user = forms.ModelChoiceField(queryset=models.AnsibleUser.objects.all(),
                                          widget=forms.Select(attrs={'class': 'need-select2'}))

    cron = CronFormField(widget=forms.TextInput, required=False)

    class Meta:

# Path: core/forms/fields.py
# class CronFormField(forms.CharField):
#     def __init__(self, *args, **kwargs):
#         defaults = {'widget': forms.TextInput}
#         kwargs.update(defaults)
#         super(CronFormField, self).__init__(*args, **kwargs)
# 
#     def validate(self, value):
#         super(CronFormField, self).validate(value)
#         models.validate_cron(value)
# 
# Path: core/models.py
# def create_auth_token(sender, instance=None, created=False, **kwargs):
# def validate_cron(value):
#     def __init__(self, *args, **kwargs):
#     def formfield(self, **kwargs):
#     def validate(self, value, model_instance):
#     def get_actual_hosts(self) -> models.QuerySet:
#     def get_playbook_name(self) -> str:
#     def get_hosts_without_groups(self) -> models.QuerySet:
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def get_vars(self):
#     def __str__(self):
#     def __str__(self):
#     def create_task(self, user, is_automatically_created=False, repeat_number=0):
#     def have_uncompleted_task(self):
#     def __str__(self):
#     def get_ansible_command(self):
#     def get_duration(self) -> datetime.timedelta:
#     def stop(self):
#     def __str__(self):
# class CronField(models.CharField):
# class TaskOperationsMixin:
# class Variable(models.Model):
#     class Meta:
# class HostGroup(models.Model):
#     class Meta:
# class Host(models.Model):
#     class Meta:
# class AnsibleUser(models.Model):
#     class Meta:
# class TaskTemplate(TaskOperationsMixin, models.Model):
#     class Meta:
# class RepeatSetting(models.Model):
# class Task(TaskOperationsMixin, models.Model):
#     class Meta:
# class TaskLog(models.Model):
#     class Meta:


# Path: core/forms/task_template.py
from django import forms
from django.conf import settings
from django.db.models.functions import Lower
from django.utils import timezone
from core.forms.fields import CronFormField
from core import models




class Search(forms.Form):
    name = forms.CharField(required=False)
    hosts = forms.ModelMultipleChoiceField(required=False, queryset=models.Host.objects.order_by(Lower('name')),
                                           widget=forms.SelectMultiple(attrs={'class': 'need-select2'}))
    host_groups = forms.ModelMultipleChoiceField(label='Groups', required=False,
                                                 queryset=models.HostGroup.objects.order_by(Lower('name')),
                                                 widget=forms.SelectMultiple(attrs={'class': 'need-select2'}))


class Edit(forms.ModelForm):
    inventory = forms.FileField(required=False)
    hosts = forms.ModelMultipleChoiceField(queryset=models.Host.objects.order_by(Lower('name')), required=False,
                                           widget=forms.SelectMultiple(attrs={'class': 'need-select2'}))
    host_groups = forms.ModelMultipleChoiceField(queryset=models.HostGroup.objects.order_by(Lower('name')),
                                                 required=False,
                                                 widget=forms.SelectMultiple(attrs={'class': 'need-select2'}))
    playbook = forms.FilePathField(path=settings.ANSIBLE_PLAYBOOKS_PATH, match='.*\.yml$',
                                   widget=forms.Select(attrs={'class': 'need-select2'}))
    ansible_user = forms.ModelChoiceField(queryset=models.AnsibleUser.objects.all(),
                                          widget=forms.Select(attrs={'class': 'need-select2'}))

    cron = CronFormField(widget=forms.TextInput, required=False)

    class Meta:

        model = models.TaskTemplate