"""Forms for the appreciation module.""" from django import forms from apps.appreciation.models import Appreciation from apps.organizations.models import Department class AppreciationForm(forms.ModelForm): """Internal form for creating an appreciation (department-targeted).""" class Meta: model = Appreciation fields = ["hospital", "department", "message_en"] widgets = { "hospital": forms.Select( attrs={"class": "w-full px-4 py-3 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-navy/20 outline-none"} ), "message_en": forms.Textarea( attrs={ "rows": 5, "class": "w-full px-4 py-3 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-navy/20 outline-none", "placeholder": "Write your message of appreciation...", } ), "department": forms.Select( attrs={"class": "w-full px-4 py-3 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-navy/20 outline-none"} ), } def __init__(self, *args, hospital=None, **kwargs): super().__init__(*args, **kwargs) if hospital: self.fields["hospital"].initial = hospital dept_qs = Department.objects.filter(status="active").select_related("hospital").order_by( "hospital__name", "name" ) self.fields["department"].queryset = dept_qs self.fields["department"].label_from_instance = lambda obj: ( f"{obj.name} — {obj.hospital.name}" if obj.hospital else obj.name )