feat: connect flow components
This commit is contained in:
parent
6d55eba2c2
commit
bfcd8cd2e5
@ -17,6 +17,10 @@ class DateInput(forms.DateInput):
|
||||
|
||||
class AdoptionNoticeForm(forms.ModelForm):
|
||||
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)
|
||||
self.helper = FormHelper()
|
||||
|
||||
@ -24,6 +28,12 @@ class AdoptionNoticeForm(forms.ModelForm):
|
||||
self.helper.form_class = 'card'
|
||||
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(
|
||||
Fieldset(
|
||||
_('Vermittlungsdetails'),
|
||||
@ -33,8 +43,7 @@ class AdoptionNoticeForm(forms.ModelForm):
|
||||
'description',
|
||||
'further_information',
|
||||
),
|
||||
Submit('submit', _('Submit'))
|
||||
)
|
||||
submit)
|
||||
|
||||
class Meta:
|
||||
model = AdoptionNotice
|
||||
@ -43,8 +52,8 @@ class AdoptionNoticeForm(forms.ModelForm):
|
||||
|
||||
class AnimalForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'adding_to_adoption_notice' in kwargs:
|
||||
adding = kwargs.pop('adding_to_adoption_notice')
|
||||
if 'in_adoption_notice_creation_flow' in kwargs:
|
||||
adding = kwargs.pop('in_adoption_notice_creation_flow')
|
||||
else:
|
||||
adding = False
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -56,7 +65,6 @@ class AnimalForm(forms.ModelForm):
|
||||
else:
|
||||
self.helper.add_input(Submit('submit', _('Speichern')))
|
||||
|
||||
|
||||
class Meta:
|
||||
model = Animal
|
||||
fields = ["name", "date_of_birth", "species", "sex", "description"]
|
||||
|
@ -95,13 +95,13 @@ def search(request):
|
||||
@login_required
|
||||
def add_adoption(request):
|
||||
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():
|
||||
instance = form.save()
|
||||
return redirect(reverse("adoption-notice-edit", args=[instance.pk]))
|
||||
return redirect(reverse("adoption-notice-add-animal", args=[instance.pk]))
|
||||
else:
|
||||
form = AdoptionNoticeForm()
|
||||
form = AdoptionNoticeForm(in_adoption_notice_creation_flow=True)
|
||||
return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form})
|
||||
|
||||
@login_required
|
||||
@ -119,7 +119,7 @@ def adoption_notice_add_animal(request, adoption_notice_id):
|
||||
else:
|
||||
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html')
|
||||
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})
|
||||
|
||||
@login_required
|
||||
|
Loading…
Reference in New Issue
Block a user