Files
2026-hypn0-site/hypn0/hypn0_site/forms.py
T
erjemin dc1897cc62
HYPN0 Build and Push Docker Image / build-and-push (push) Successful in 31s
mod: update Russian to English translations in templates and forms for improved accessibility
2026-09-27 21:12:57 +03:00

99 lines
2.5 KiB
Python

from django import forms
class HalftoneGenerateForm(forms.Form):
"""
Форма валидации входных параметров для генерации гипнотического SVG.
"""
SHAPE_CHOICES = [
("circle", "Circle"),
("ring", "Ring"),
("triangle", "Triangle"),
("square", "Square"),
("diamond", "Diamond"),
("hexagon", "Hexagon"),
("star", "Star"),
("cross", "Cross"),
("line", "Line"),
("snowflake", "Snowflake"),
("binary", "Binary (0/1)"),
("heart", "Heart"),
]
image = forms.ImageField(
required=True,
error_messages={
"required": "Feed the Hypnotoad with an image!",
"invalid_image": "Hypnotoad cannot digest this file. Image required (PNG, JPG, WEBP).",
},
)
shape = forms.ChoiceField(
choices=SHAPE_CHOICES,
initial="circle",
required=False,
)
cols = forms.IntegerField(
min_value=10,
max_value=80,
initial=35,
required=False,
)
max_radius = forms.IntegerField(
min_value=3,
max_value=65,
initial=8,
required=False,
)
blink = forms.IntegerField(
min_value=1,
max_value=10,
initial=6,
required=False,
)
rotation = forms.IntegerField(
min_value=-15,
max_value=15,
initial=0,
required=False,
)
scale = forms.IntegerField(
min_value=800,
max_value=1040,
initial=980,
required=False,
)
angle = forms.IntegerField(
min_value=-44,
max_value=45,
initial=0,
required=False,
)
def clean_shape(self):
shape = self.cleaned_data.get("shape")
if not shape:
return "circle"
return shape
def clean_cols(self):
return self.cleaned_data.get("cols") or 80
def clean_max_radius(self):
return self.cleaned_data.get("max_radius") or 8
def clean_blink(self):
val = self.cleaned_data.get("blink")
return 6 if val is None else val
def clean_rotation(self):
val = self.cleaned_data.get("rotation")
return 0 if val is None else val
def clean_scale(self):
val = self.cleaned_data.get("scale")
return 980 if val is None else val
def clean_angle(self):
val = self.cleaned_data.get("angle")
return 0 if val is None else val