76 lines
2.5 KiB
Python
76 lines
2.5 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: BUMN rugi karena biaya tinggi, omzet turun 30%, atau kuliah Jepang/Singapura dengan dana 200 juta.",
|
|
}),
|
|
"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
|
|
|
|
|
|
class WebIntelligenceForm(forms.Form):
|
|
query = forms.CharField(
|
|
label="Topik atau masalah",
|
|
required=False,
|
|
max_length=180,
|
|
widget=forms.TextInput(attrs={
|
|
"class": "form-control",
|
|
"placeholder": "Contoh: kerugian BUMN Indonesia",
|
|
}),
|
|
)
|
|
url = forms.URLField(
|
|
label="URL sumber data",
|
|
max_length=500,
|
|
widget=forms.URLInput(attrs={
|
|
"class": "form-control",
|
|
"placeholder": "https://...",
|
|
}),
|
|
)
|
|
api_key = forms.CharField(
|
|
label="OpenAI API Key",
|
|
required=False,
|
|
widget=forms.PasswordInput(attrs={
|
|
"class": "form-control",
|
|
"placeholder": "Opsional — isi untuk analisis AI",
|
|
"autocomplete": "off",
|
|
}, render_value=False),
|
|
)
|
|
|
|
def clean_url(self):
|
|
source_url = self.cleaned_data["url"].strip()
|
|
if not source_url.lower().startswith(("http://", "https://")):
|
|
raise forms.ValidationError("URL harus diawali http:// atau https://.")
|
|
return source_url
|