forms.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import re
  2. from django import forms
  3. class LogoForm(forms.Form):
  4. namesystem = forms.CharField(
  5. max_length=30,
  6. label="Название системы", required=False)
  7. logo = forms.FileField(
  8. label="Логотип", required=False)
  9. logo.widget.attrs.update({'accept': '.png, .svg, .ico'})
  10. class ColorsForm(forms.Form):
  11. def __init__(self, *args, **kwargs):
  12. # Read the color codes from the CSS file and append additional colors
  13. f = str((open('design_template/static/design_template/colors.css', encoding='utf-8')).read())
  14. color_codes_list = re.findall(r'#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3}', f)
  15. colors = color_codes_list
  16. super(ColorsForm, self).__init__(*args, **kwargs)
  17. # Create form fields with initial color values
  18. self.fields['btnBg'] = forms.CharField(
  19. label='Цвет кнопок',
  20. initial=colors[0],
  21. max_length=7,
  22. widget=forms.TextInput(attrs={
  23. 'type': 'color'
  24. })
  25. )
  26. self.fields['btnTxt'] = forms.CharField(
  27. label='Цвет текста кнопок',
  28. initial=colors[1],
  29. max_length=7,
  30. widget=forms.TextInput(attrs={
  31. 'type': 'color'
  32. })
  33. )
  34. self.fields['btnHover'] = forms.CharField(
  35. label='Цвет наведения у кнопок',
  36. initial=colors[2],
  37. max_length=7,
  38. widget=forms.TextInput(attrs={
  39. 'type': 'color'
  40. })
  41. )
  42. self.fields['pillsBg'] = forms.CharField(
  43. label='Цвет плашек в меню',
  44. initial=colors[3],
  45. max_length=7,
  46. widget=forms.TextInput(attrs={
  47. 'type': 'color'
  48. })
  49. )
  50. self.fields['pillsTxt'] = forms.CharField(
  51. label='Цвет текста плашек в меню',
  52. initial=colors[4],
  53. max_length=7,
  54. widget=forms.TextInput(attrs={
  55. 'type': 'color'
  56. })
  57. )
  58. self.fields['linksTxt'] = forms.CharField(
  59. label='Цвет текста ссылок',
  60. initial=colors[5],
  61. max_length=7,
  62. widget=forms.TextInput(attrs={
  63. 'type': 'color'
  64. })
  65. )
  66. self.fields['linksHover'] = forms.CharField(
  67. label='Цвет наведения у ссылок',
  68. initial=colors[6],
  69. max_length=7,
  70. widget=forms.TextInput(attrs={
  71. 'type': 'color'
  72. })
  73. )
  74. self.fields['btnSuccessBg'] = forms.CharField(
  75. label='Цвет кнопок успеха',
  76. initial=colors[7],
  77. max_length=7,
  78. widget=forms.TextInput(attrs={
  79. 'type': 'color'
  80. })
  81. )
  82. self.fields['btnSuccessTxt'] = forms.CharField(
  83. label='Цвет текста кнопок успеха',
  84. initial=colors[8],
  85. max_length=7, widget=forms.TextInput(attrs={
  86. 'type': 'color'
  87. })
  88. )
  89. self.fields['btnSuccessHover'] = forms.CharField(
  90. label='Цвет наведения у кнопок успеха',
  91. initial=colors[9],
  92. max_length=7, widget=forms.TextInput(attrs={
  93. 'type': 'color'
  94. })
  95. )
  96. self.fields['btnDangerBg'] = forms.CharField(
  97. label='Цвет текста кнопок предупреждения',
  98. initial=colors[10],
  99. max_length=7, widget=forms.TextInput(attrs={
  100. 'type': 'color'
  101. })
  102. )
  103. self.fields['btnDangerTxt'] = forms.CharField(
  104. label='Цвет текста кнопок предупреждения',
  105. initial=colors[11],
  106. max_length=7, widget=forms.TextInput(attrs={
  107. 'type': 'color'
  108. })
  109. )
  110. self.fields['btnDangerHover'] = forms.CharField(
  111. label='Цвет наведения у кнопок предупреждения',
  112. initial=colors[12],
  113. max_length=7,
  114. widget=forms.TextInput(attrs={
  115. 'type': 'color'
  116. })
  117. )