feat: connect flow components

This commit is contained in:
moanos [he/him] 2024-05-31 09:58:55 +02:00
parent 6d55eba2c2
commit bfcd8cd2e5
2 changed files with 17 additions and 9 deletions

View File

@ -17,6 +17,10 @@ class DateInput(forms.DateInput):
class AdoptionNoticeForm(forms.ModelForm): class AdoptionNoticeForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if 'in_adoption_notice_creation_flow' in kwargs:
in_flow = kwargs.pop('in_adoption_notice_creation_flow')
else:
in_flow = False
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.helper = FormHelper() self.helper = FormHelper()
@ -24,6 +28,12 @@ class AdoptionNoticeForm(forms.ModelForm):
self.helper.form_class = 'card' self.helper.form_class = 'card'
self.helper.form_method = 'post' self.helper.form_method = 'post'
if in_flow:
submit = Submit('save-and-add-another-animal', _('Speichern und Tiere hinzufügen'))
else:
submit = Submit('submit', _('Submit'))
self.helper.layout = Layout( self.helper.layout = Layout(
Fieldset( Fieldset(
_('Vermittlungsdetails'), _('Vermittlungsdetails'),
@ -33,8 +43,7 @@ class AdoptionNoticeForm(forms.ModelForm):
'description', 'description',
'further_information', 'further_information',
), ),
Submit('submit', _('Submit')) submit)
)
class Meta: class Meta:
model = AdoptionNotice model = AdoptionNotice
@ -43,8 +52,8 @@ class AdoptionNoticeForm(forms.ModelForm):
class AnimalForm(forms.ModelForm): class AnimalForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if 'adding_to_adoption_notice' in kwargs: if 'in_adoption_notice_creation_flow' in kwargs:
adding = kwargs.pop('adding_to_adoption_notice') adding = kwargs.pop('in_adoption_notice_creation_flow')
else: else:
adding = False adding = False
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -56,7 +65,6 @@ class AnimalForm(forms.ModelForm):
else: else:
self.helper.add_input(Submit('submit', _('Speichern'))) self.helper.add_input(Submit('submit', _('Speichern')))
class Meta: class Meta:
model = Animal model = Animal
fields = ["name", "date_of_birth", "species", "sex", "description"] fields = ["name", "date_of_birth", "species", "sex", "description"]

View File

@ -95,13 +95,13 @@ def search(request):
@login_required @login_required
def add_adoption(request): def add_adoption(request):
if request.method == 'POST': if request.method == 'POST':
form = AdoptionNoticeForm(request.POST, request.FILES) form = AdoptionNoticeForm(request.POST, request.FILES, in_adoption_notice_creation_flow=True)
if form.is_valid(): if form.is_valid():
instance = form.save() instance = form.save()
return redirect(reverse("adoption-notice-edit", args=[instance.pk])) return redirect(reverse("adoption-notice-add-animal", args=[instance.pk]))
else: else:
form = AdoptionNoticeForm() form = AdoptionNoticeForm(in_adoption_notice_creation_flow=True)
return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form}) return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form})
@login_required @login_required
@ -119,7 +119,7 @@ def adoption_notice_add_animal(request, adoption_notice_id):
else: else:
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html') return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html')
else: else:
form = AnimalForm(adding_to_adoption_notice=True) form = AnimalForm(in_adoption_notice_creation_flow=True)
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html', {'form': form}) return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html', {'form': form})
@login_required @login_required