wip
This commit is contained in:
parent
e3e9c9ebc8
commit
edaabc5724
|
@ -17,8 +17,13 @@
|
|||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block formnew %}
|
||||
<form action="{% url 'insurance:add' %}" method="post">
|
||||
<form action="{% url 'index:new_insurance' %}" method="post">
|
||||
{% csrf_token %}
|
||||
{% if insurance is None %}
|
||||
<div class="new" id="new_insurance">
|
||||
{% else %}
|
||||
<div class="new hidden" id="new_insurance">
|
||||
{% endif %}
|
||||
{{ insurance_form }}
|
||||
<input type="submit" value="Add insurance" />
|
||||
</div>
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
{% endblock %}
|
||||
{% block formnew %}
|
||||
<form action="{% url 'person:add' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="new hidden" id="new_person">
|
||||
{{ person_form }}
|
||||
<input type="submit" value="Add person" />
|
||||
|
|
|
@ -7,5 +7,6 @@ urlpatterns = [
|
|||
path('', index, name='index'),
|
||||
path('new_stay/', new_stay, name='new_stay'),
|
||||
path('new_stay/boat', new_boat, name='new_boat'),
|
||||
path('new_stay/insurance', new_insurance, name='new_insurance'),
|
||||
path('reset_session/', reset_session, name='reset_session'),
|
||||
]
|
||||
|
|
|
@ -31,10 +31,10 @@ def new_stay(request):
|
|||
elif request.session['new_stay_step'] == 1:
|
||||
# Insurance form
|
||||
return new_stay_1(request)
|
||||
elif request.session['new_stay_step'] ==2:
|
||||
elif request.session['new_stay_step'] == 2:
|
||||
# Person form
|
||||
return new_stay_2(request)
|
||||
elif request.session['new_stay_step'] ==3:
|
||||
elif request.session['new_stay_step'] == 3:
|
||||
# Stay form
|
||||
return new_stay_3(request)
|
||||
elif request.session['new_stay_step'] == 4:
|
||||
|
@ -90,8 +90,8 @@ def new_stay_1(request):
|
|||
if request.POST.get('search_results'):
|
||||
print('Search results')
|
||||
print(request.POST.get('search_results'))
|
||||
else:
|
||||
# User has not select a search result
|
||||
elif request.method == 'POST':
|
||||
# User has not selected a search result
|
||||
# So this must be the good insurance
|
||||
print('No search')
|
||||
request.method = 'GET'
|
||||
|
@ -101,9 +101,8 @@ def new_stay_1(request):
|
|||
except IndexError:
|
||||
print('Missing search_results data')
|
||||
|
||||
print('No ')
|
||||
data = dict(request.session)
|
||||
data['insurance_form'] = InsuranceForm()
|
||||
data['insurance_form'] = InsuranceForm(prefix='ins')
|
||||
data['insurance_search_form'] = InsuranceSearchForm()
|
||||
data['insurance'] = None
|
||||
|
||||
|
@ -113,6 +112,8 @@ def new_stay_1(request):
|
|||
pk=id_ins)
|
||||
except KeyError:
|
||||
data['insurance'] = None
|
||||
except TypeError:
|
||||
data['insurance'] = None
|
||||
|
||||
return render(request, 'new_stay/new_stay-1.html', data)
|
||||
|
||||
|
@ -190,6 +191,20 @@ def new_stay_4(request):
|
|||
def new_boat(request):
|
||||
boat_form = BoatForm(request.POST, prefix='boa')
|
||||
boat = boat_form.save()
|
||||
request.method = 'GET'
|
||||
request.session['new_stay_step'] = 1
|
||||
request.session['new_stay_boat'] = boat.id
|
||||
return new_stay(request)
|
||||
|
||||
def new_insurance(request):
|
||||
ins_form = InsuranceForm(request.POST, prefix='ins')
|
||||
new_insurance = ins_form.save(commit=False)
|
||||
insurance = Insurance.objects.get(name=new_insurance.name)
|
||||
if insurance is None:
|
||||
insurance = ins_form.save()
|
||||
|
||||
request.method = 'GET'
|
||||
request.session['new_stay_step'] = 2
|
||||
request.session['new_stay_insurance'] = insurance.id
|
||||
return new_stay(request)
|
||||
|
||||
|
|
Loading…
Reference in New Issue