added stay form

This commit is contained in:
maxime 2019-07-18 14:05:41 +02:00
parent a6f56cfcd3
commit 52626d16a8
2 changed files with 19 additions and 2 deletions

View File

@ -5,5 +5,4 @@
<br />
<input type="submit" value="Next" />
<br />
{% endif %}
{% endblock %}

View File

@ -47,6 +47,8 @@ def new_stay_0(request):
boat_id = int(request.POST.get('search_results'))
boat = Boat.objects.get(pk=boat_id)
if boat is not None:
request.method = 'GET'
request.session['new_stay_step'] = 1
request.session['new_stay_boat'] = boat_id
insurance = boat.getInsurance()
@ -89,6 +91,7 @@ def new_stay_1(request):
# User has not select a search result
# So this must be the good insurance
print('No search')
request.method = 'GET'
request.session['new_stay_step'] = 2
return new_stay(request)
@ -115,6 +118,7 @@ def new_stay_2(request):
if request.method == 'POST':
sailors_forms = SailorsFormSet(data=request.POST,
prefix='sai')
data = {'sailors_forms': sailors_forms}
for sailor_form in sailors_forms:
if not sailor_form.is_valid():
@ -123,6 +127,9 @@ def new_stay_2(request):
sailor = sailor_form.save(commit=False)
sailor.boat_id = request.session['new_stay_boat']
sailor.save()
request.method = 'GET'
request.session['new_stay_step'] = 3
return new_stay_3(request)
boat = Boat.objects.get(
@ -153,8 +160,19 @@ def new_stay_2(request):
def new_stay_3(request):
if request.method == 'POST':
pass
stay_form = StayForm(request.POST)
data = {'stay_form': stay_form}
stay = stay_form.save(commit=False)
stay.boat_id = request.session['new_stay_boat']
pprint(stay)
if (stay.departure < stay.arrival):
return render(request, 'new_stay/new_stay-3.html', data)
data = {}
data['stay_form'] = StayForm()
return render(request, 'new_stay/new_stay-3.html', data)
def new_stay_4(request):
pass