can create boats for new_stay

This commit is contained in:
maxime 2019-08-03 22:44:57 +02:00
parent dfbed7248e
commit e3e9c9ebc8
5 changed files with 45 additions and 8 deletions

View File

@ -15,7 +15,8 @@
</div>
{% endblock %}
{% block formnew %}
<form action="{% url 'boat:add' %}" method="post">
<form action="{% url 'index:new_boat' %}" method="post" name="boat_add">
{% csrf_token %}
<div class="new hidden" id="new_boat">
<a
id="switch_boat_search"

View File

@ -6,5 +6,6 @@ app_name = 'index'
urlpatterns = [
path('', index, name='index'),
path('new_stay/', new_stay, name='new_stay'),
path('new_stay/boat', new_boat, name='new_boat'),
path('reset_session/', reset_session, name='reset_session'),
]

View File

@ -36,10 +36,31 @@ def form_boat(request):
'stay_form': stay_form,
'mooring_forms': mooring_forms})
def add_boat(request):
if request.method != 'POST':
def add_boat(request, cb=None):
"""
see if it's not possible to give
an url a "callback" in case of success
or error
"""
try:
new_boat_form = BoatForm(request.POST, prefix='boa')
new_boat = new_boat_form.save()
except ValidationError as err:
pprint(err)
return form(request.POST)
except ValueError as err:
pprint(err)
return form(request.POST)
if cb is not None:
return cb(request)
return list_boats(request)
def add_boat_(request):
if request.method != 'POST':
return form(request.POST)
try:
new_boat_form = BoatForm(request.POST, prefix='boa')
new_boat = new_boat_form.save(commit=False)
@ -71,10 +92,9 @@ def add_boat(request):
else:
new_company = None
new_person = PersonForm(request.POST, prefix='per').save(commit=False)
new_person = PersonForm(request.POST, prefix='per').save(commit=False)
new_address = AddressForm(request.POST, prefix='add').save(commit=False)
pprint(request.POST.get('sta-arrival'))
pprint(request.POST.get('sta-departure'))
new_stay = StayForm(request.POST, prefix='sta').save(commit=False)
if new_stay.no_mooring is not True:
new_moorings = MooringFormSet(request.POST, prefix='moo').save(commit=False)
@ -127,6 +147,9 @@ def add_boat(request):
new_boat_form.save_m2m()
except ValueError as err:
pprint(err)
return form_boat(request)
except ValidationError as err:
pprint(err)
return form_boat(request)

View File

@ -73,7 +73,7 @@ def new_stay_0(request):
name=name,
choices=boat_existing)
boat_form = BoatForm()
boat_form = BoatForm(request.POST, prefix='boa')
return render(request,
@ -125,7 +125,8 @@ def new_stay_2(request):
for sailor_form in sailors_forms:
if not sailor_form.has_changed():
return new_stay_3(request)
request.session['new_stay_step'] = 3
return new_stay(request)
if not sailor_form.is_valid():
return render(request, 'new_stay/new_stay-2.html')
else:
@ -137,7 +138,7 @@ def new_stay_2(request):
request.method = 'GET'
request.session['new_stay_step'] = 3
return new_stay_3(request)
return new_stay(request)
boat = Boat.objects.get(
pk=request.session.get('new_stay_boat'))
@ -185,3 +186,10 @@ def new_stay_3(request):
def new_stay_4(request):
pass
def new_boat(request):
boat_form = BoatForm(request.POST, prefix='boa')
boat = boat_form.save()
request.session['new_stay_step'] = 1
request.session['new_stay_boat'] = boat.id
return new_stay(request)

View File

@ -1,4 +1,8 @@
$(function () {
// todo
// change this with python normally
$('#id_boa-name').val($('#id_search_name').val());
// Events
$('[name=search_results]').on('change',
function (e) {