1
0

forms.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from django import forms
  2. from django.forms import ModelForm, CharField, SlugField
  3. from django.core.validators import validate_unicode_slug
  4. from .models import Network, Host, Channel, Owner, CurseWord, Adjective
  5. class NetworkForm(ModelForm):
  6. class Meta:
  7. model=Network
  8. #fields = ['name', 'slug', 'nickname', 'password', 'username', 'home_channel', 'command_character', 'help_character']
  9. fields='__all__'
  10. #exclude = ['slug'] #Does not need "fields = '__all__'".
  11. labels={
  12. 'name': '<i class="sitemap icon"></i>Name',
  13. 'slug': '<i class="linkify icon"></i>Slug',
  14. 'nickname': '<i class="id badge icon"></i>Nickname',
  15. 'username': '<i class="id card icon"></i>Username',
  16. 'password': '<i class="privacy icon"></i>Password',
  17. 'mail': '<i class="envelope icon"></i>NickServ registration E-mail',
  18. 'home_channel': '<i class="hashtag icon"></i>Home channel',
  19. 'command_character': '<i class="terminal icon"></i>Command character',
  20. 'help_character': '<i class="help icon"></i>Help character',
  21. 'network_services': '<i class="lightbulb outline icon"></i>Network services',
  22. 'enabled': '<i class="power off icon"></i>Enabled',
  23. # 'mute': '<i class="comment slash icon"></i>Mute',
  24. }
  25. widgets={
  26. 'enabled': forms.CheckboxInput(attrs={'_style': 'inverted toggle',}),
  27. }
  28. class HostForm(ModelForm):
  29. class Meta:
  30. model=Host
  31. exclude=['network', 'connection_attempts', 'connection_succeeds']
  32. labels={
  33. 'address': '<i class="server icon"></i>Address',
  34. 'port': '<i class="dungeon icon"></i>Port',
  35. 'ssl': '<i class="lock icon"></i>Use SSL',
  36. }
  37. widgets={
  38. 'ssl': forms.CheckboxInput(attrs={'_style': 'inverted toggle',}),
  39. }
  40. layout = [
  41. ('Four Fields',
  42. ('Field', 'address'),
  43. ('Field', 'port'),
  44. ('Field', 'ssl'),
  45. ('Field', 'DELETE'),
  46. )
  47. ]
  48. class OwnerForm(ModelForm):
  49. class Meta:
  50. model=Owner
  51. exclude=['network',]
  52. labels={
  53. 'hostmask': '<i class="fingerprint icon"></i>Owner hostmask',
  54. }
  55. layout = [
  56. ('Two Fields',
  57. ('Field', 'hostmask'),
  58. ('Field', 'DELETE'),
  59. )
  60. ]
  61. class ChannelForm(ModelForm):
  62. class Meta:
  63. model=Channel
  64. fields=['autojoin', 'statistic_commands', 'games', 'chat']
  65. labels={
  66. 'autojoin': '<i class="power icon"></i>Auto join',
  67. 'statistic_commands': '<i class="chart pie icon"></i>Statistic commands',
  68. 'chat': '<i class="comment dots icon"></i>Chat',
  69. 'games': '<i class="gamepad icon"></i>Games',
  70. }
  71. widgets={
  72. 'autojoin': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
  73. 'statistic_commands': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
  74. 'chat': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
  75. 'games': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
  76. }
  77. class CurseWordForm(ModelForm):
  78. class Meta:
  79. model=CurseWord
  80. fields={'content'}
  81. labels={
  82. 'content': '<i class="book dead icon"></i>Curse word'
  83. }
  84. widgets={
  85. 'content': forms.TextInput(attrs={'_no_required': 'True'}),
  86. }
  87. class AdjectiveForm(ModelForm):
  88. class Meta:
  89. model=Adjective
  90. fields={'content'}
  91. labels={
  92. 'content': '<i class="book dead icon"></i>Adjective'
  93. }
  94. widgets={
  95. 'content': forms.TextInput(attrs={'_no_required': 'True'}),
  96. }