diff --git a/src/fellchensammlung/forms.py b/src/fellchensammlung/forms.py index a092de2..4398fec 100644 --- a/src/fellchensammlung/forms.py +++ b/src/fellchensammlung/forms.py @@ -42,125 +42,6 @@ class AdoptionNoticeForm(forms.ModelForm): } -class AnimalForm(forms.Form): - - def __init__(self, animal_id, *args, **kwargs): - - photo_rows = [] - - super().__init__(*args, **kwargs) - - # Get the animal instance - animal = Animal.objects.get(pk=animal_id) - - # Define Django form fields for later use - self.fields["name"] = forms.CharField(initial=animal.name) - self.fields["species"] = forms.ChoiceField( - label=_("Tierart"), - choices=[(x.id, x.name) for x in Species.objects.all()], - initial=animal.species.pk - ) - - photos = animal.get_photos() - - for photo in photos: - alt_field_name = f"image_alt_{photo.pk}" - self.fields[alt_field_name] = forms.CharField() - self.fields[alt_field_name].initial = photo.alt_text - - title_field_name = f"image_title_{photo.pk}" - self.fields[title_field_name] = forms.CharField(max_length=200) - self.fields[title_field_name].initial = photo.title - - delete_btn = f"delete_photo_{photo.pk}" - save_btn = f"save_photo_{photo.pk}" - - current_row = Row( - Column(title_field_name, css_class="form-group col-md-2 mb-0"), - Column( - HTML(photo.as_html), - css_class="form-group col-md-4 mb-0"), - Column(alt_field_name, css_class="form-group col-md-2 mb-0"), - Column( - Submit(delete_btn, _("Löschen")), - css_class="form-group col-md-auto mb-0 needs_manual", - ), - Column( - Submit(save_btn, _("Bearbeiten")), - css_class="form-group col-md-auto mb-0 needs_manual", - ), - css_class="form-row", - ) - - photo_rows.append(current_row) - - self.helper = FormHelper() - self.helper.form_class = 'card' - - submit_form_btn = f"submit_form_{animal.pk}" - - self.helper.layout = Layout( - Fieldset( - animal.name, - Row( - Field("name", selected="", css_class="form-group col-md-6 mb-0"), - Field("species", css_class="form-group col-md-6 mb-0"), - Submit(submit_form_btn, _("Submit"), - css_class="form-group col-md-2 mb-0 needs_manual", - ), - css_class="form-row", - ) - ) - ) - - self.helper.layout.append(Fieldset(_("Fotos"), css_class="fieldsets")) - for photo_row in photo_rows: - self.helper.layout[-1].append(photo_row) - - current_row = Row( - HTML( - "