diff --git a/port/forms.py b/port/forms.py
index a38680d..1b9c855 100644
--- a/port/forms.py
+++ b/port/forms.py
@@ -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):
diff --git a/port/templates/index.html b/port/templates/index.html
index b4b7b92..2f38824 100644
--- a/port/templates/index.html
+++ b/port/templates/index.html
@@ -7,4 +7,6 @@
New Stay
{% endblock %}
+ {% block formnew %}
+ {% endblock %}
{% endblock %}
diff --git a/port/templates/new_stay/new_stay-0.html b/port/templates/new_stay/new_stay-0.html
index 7920a11..44fb491 100644
--- a/port/templates/new_stay/new_stay-0.html
+++ b/port/templates/new_stay/new_stay-0.html
@@ -1,10 +1,15 @@
{% extends "index.html" %}
{% block form %}
-
+
{{ boat_search_form }}
-
-
-
-
-
+
+
+{% endblock %}
+{% block formnew %}
+
{% endblock %}
diff --git a/port/templates/new_stay/new_stay-1.html b/port/templates/new_stay/new_stay-1.html
new file mode 100644
index 0000000..7dcc8a0
--- /dev/null
+++ b/port/templates/new_stay/new_stay-1.html
@@ -0,0 +1,12 @@
+{% extends "index.html" %}
+{% block form %}
+ {{ new_stay_insurance }}
+{% endblock %}
+{% block formnew %}
+
+{% endblock %}
diff --git a/port/views/index.py b/port/views/index.py
index 9749175..18f0571 100644
--- a/port/views/index.py
+++ b/port/views/index.py
@@ -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')