from django import forms
from django.forms import ModelForm, CharField, SlugField
from django.core.validators import validate_unicode_slug
from .models import Network, Host, Channel, Owner, CurseWord, CurseAdjective
class NetworkForm(ModelForm):
class Meta:
model=Network
#fields = ['name', 'slug', 'nickname', 'password', 'username', 'home_channel', 'command_character', 'help_character']
fields='__all__'
#exclude = ['slug'] #Does not need "fields = '__all__'".
labels={
'name': 'Name',
'slug': 'Slug',
'nickname': 'Nickname',
'username': 'Username',
'password': 'Password',
'mail': 'NickServ registration E-mail',
'home_channel': 'Home channel',
'command_character': 'Command character',
'help_character': 'Help character',
'network_services': 'Network services',
'enabled': 'Enabled',
# 'mute': 'Mute',
}
widgets={
'enabled': forms.CheckboxInput(attrs={'_style': 'inverted toggle',}),
}
class HostForm(ModelForm):
class Meta:
model=Host
exclude=['network', 'connection_attempts', 'connection_succeeds']
labels={
'address': 'Address',
'port': 'Port',
'ssl': 'Use SSL',
}
widgets={
'ssl': forms.CheckboxInput(attrs={'_style': 'inverted toggle',}),
}
layout = [
('Four Fields',
('Field', 'address'),
('Field', 'port'),
('Field', 'ssl'),
('Field', 'DELETE'),
)
]
class OwnerForm(ModelForm):
class Meta:
model=Owner
fields='__all__'
labels={
'hostmask': 'Owner hostmask',
}
layout = [
('Two Fields',
('Field', 'hostmask'),
('Field', 'DELETE'),
)
]
class ChannelForm(ModelForm):
class Meta:
model=Channel
fields=['autojoin', 'statistic_commands', 'games', 'chat']
labels={
'autojoin': 'Auto join',
'statistic_commands': 'Statistic commands',
'chat': 'Chat',
'games': 'Games',
}
widgets={
'autojoin': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
'statistic_commands': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
'chat': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
'games': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
}
class CurseWordForm(ModelForm):
class Meta:
model=CurseWord
fields={'word'}
labels={
'word': 'Curse word'
}
widgets={
'word': forms.TextInput(attrs={'_no_required': 'True'}),
}
class CurseAdjectiveForm(ModelForm):
class Meta:
model=CurseAdjective
fields={'word'}
labels={
'word': 'Adjective'
}
widgets={
'word': forms.TextInput(attrs={'_no_required': 'True'}),
}