new_stay-1 initialized

This commit is contained in:
maxime 2019-06-24 18:10:45 +02:00
parent 2729011946
commit d600618522
5 changed files with 50 additions and 12 deletions

View File

@ -70,9 +70,12 @@ class BoatSearchForm(Form):
def __init__(self, name='', choices=[]):
super(Form, self).__init__()
print(name)
self.fields['search_name'].initial = name
self.fields['search_results'].choices = choices
if choices == [] and len(name) < 3:
self.fields.pop('search_results')
else:
self.fields['search_results'].choices = choices
class BoatForm(ModelForm):

View File

@ -7,4 +7,6 @@
<a href="{% url 'index:new_stay' %}">New Stay</a>
{% endblock %}
</form>
{% block formnew %}
{% endblock %}
{% endblock %}

View File

@ -1,10 +1,15 @@
{% extends "index.html" %}
{% block form %}
<div class="search" id="search_boat">
<div class="search" id="search_boat">
{{ boat_search_form }}
</div>
<div class="new hidden" id="new_boat">
<!-- {{ boat_form }} -->
</div>
<input type="submit" value="Submit" />
<input type="submit" value="Search boat" />
</div>
{% endblock %}
{% block formnew %}
<form action="{% url 'boat:add' %}" method="post">
<div class="new hidden" id="new_boat">
{{ boat_form }}
<input type="submit" value="Add boat" />
</div>
</form>
{% endblock %}

View File

@ -0,0 +1,12 @@
{% extends "index.html" %}
{% block form %}
{{ new_stay_insurance }}
{% endblock %}
{% block formnew %}
<form action="{% url 'insurance:add' %}" method="post">
<div class="new hidden" id="new_insurance">
{{ insurance_form }}
<input type="submit" value="Add insurance" />
</div>
</form>
{% endblock %}

View File

@ -19,6 +19,20 @@ def new_stay(request):
request.session['new_stay_step'] = 0
request.session['new_stay_done'] = False
try:
boat_id = int(request.POST.get('search_results'))
boat = Boat.objects.get(pk=boat_id)
if boat is not None:
request.session['new_stay_step'] = 1
request.session['new_stay_boat'] = boat_id
if boat.insurance is not None:
request.session['new_stay_insurance'] = boat.insurance.id
return new_stay(request)
except TypeError:
pass
except Exception as e:
pprint(e)
name = request.POST.get('search_name', '')
boat_existing = [ (b.id, b.name) for b in \
Boat.objects.filter(name__icontains=name) ] \
@ -39,14 +53,16 @@ def new_stay(request):
# Boat form
elif request.session['new_stay_step'] == 1:
# Insurance form
return render(request, 'new_stay-1.html')
data = dict(request.session)
data['insurance_form'] = InsuranceForm()
return render(request, 'new_stay/new_stay-1.html', data)
elif request.session['new_stay_step'] ==2:
# Person form
return render(request, 'new_stay-2.html')
return render(request, 'new_stay/new_stay-2.html')
elif request.session['new_stay_step'] ==3:
# Stay form
return render(request, 'new_stay-3.html')
return render(request, 'new_stay/new_stay-3.html')
elif request.session['new_stay_step'] == 4:
# Save form
request.session['new_stay_done'] = True
return render(request, 'new_stay-4.html')
return render(request, 'new_stay/new_stay-4.html')