forked from uncloud/uncloud
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
from django import forms
|
|
from django.contrib.auth.models import User
|
|
from django.forms import ModelForm
|
|
from .validators import domain_name_validator
|
|
|
|
|
|
class DomainNameField(forms.CharField):
|
|
description = 'Domain name form field'
|
|
default_validators = [domain_name_validator, ]
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(DomainNameField, self).__init__(*args, **kwargs)
|
|
|
|
class UserDeleteForm(forms.ModelForm):
|
|
class Meta:
|
|
model = User
|
|
fields = []
|
|
|
|
class MainForm(forms.Form):
|
|
def __init__(self, *args, **kwargs):
|
|
super(MainForm, self).__init__(*args, **kwargs)
|
|
for visible in self.visible_fields():
|
|
if isinstance(visible.field.widget, forms.TextInput):
|
|
visible.field.widget.attrs['class'] = 'form-control'
|
|
elif isinstance(visible.field.widget, forms.Select):
|
|
visible.field.widget.attrs['class'] = 'form-select'
|
|
elif (isinstance(visible.field.widget, forms.CheckboxInput)):
|
|
visible.field.widget.attrs['class'] = 'custom-control-input'
|
|
|
|
class MainModelForm(ModelForm):
|
|
def __init__(self, *args, **kwargs):
|
|
super(MainModelForm, self).__init__(*args, **kwargs)
|
|
for visible in self.visible_fields():
|
|
visible.field.widget.attrs['class'] = 'form-control'
|
|
|