41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
from django import forms
|
|
|
|
from .models import ProblemCase
|
|
|
|
|
|
class ProblemCaseForm(forms.ModelForm):
|
|
class Meta:
|
|
model = ProblemCase
|
|
fields = ["description", "urgency"]
|
|
labels = {
|
|
"description": "Masukkan masalah, target, atau hambatan Anda:",
|
|
"urgency": "Tingkat Urgensi",
|
|
}
|
|
widgets = {
|
|
"description": forms.Textarea(attrs={
|
|
"class": "form-control problem-textarea",
|
|
"rows": 9,
|
|
"placeholder": "Contoh: Kuliah di Singapura atau Jepang, dana 200 juta, ingin 3 tahun selesai.",
|
|
}),
|
|
"urgency": forms.TextInput(attrs={
|
|
"type": "range",
|
|
"class": "form-range urgency-slider",
|
|
"min": 1,
|
|
"max": 5,
|
|
"step": 1,
|
|
"oninput": "document.getElementById('urgency-output').value=this.value",
|
|
}),
|
|
}
|
|
|
|
def clean_description(self):
|
|
description = self.cleaned_data["description"].strip()
|
|
if len(description) < 20:
|
|
raise forms.ValidationError("Tuliskan minimal 20 karakter agar analisis lebih bermakna.")
|
|
return description
|
|
|
|
def clean_urgency(self):
|
|
urgency = self.cleaned_data["urgency"]
|
|
if urgency < 1 or urgency > 5:
|
|
raise forms.ValidationError("Urgensi harus berada pada skala 1 sampai 5.")
|
|
return urgency
|