added new_stay route and form 0 for boat search

This commit is contained in:
maxime 2019-06-23 14:42:06 +02:00
commit 951a325293
22 changed files with 407 additions and 121 deletions

View File

@ -5,3 +5,15 @@ TODO :
- how to determine which is the right person if choosing from a list and two - how to determine which is the right person if choosing from a list and two
have the same names (rare) : have the same names (rare) :
name surname - city (country) name surname - city (country)
Pour la partie NEW ARRIVAL:
- séparer chaque form:
séparer company_form, insurance_form, person_form, address_form, stay_form, mooring_form de boat_form
- une url pour:
-boat_form
-company_form, insurance_form, (address_form)
-person_form, (address_form)
-stay_form, mooring_form

View File

@ -1,49 +1,55 @@
HOME: HOME:
- NEW STAY - NEW STAY
- NEW PAYMENT - NEW PAYMENT
- FIND/EDIT STAY
- FIND/EDIT BOAT
NEW STAY - FIND/EDIT PERSON
- NEW PORT
- enter boat name: - FIND/EDIT PORT
- list of existing boats with same/similar name: choose one - SCHEDULE
or - ACCOUNTING: FIND PAYMENT
- add a new boat: boat form
NEXT NEW STAY
- same insurance?: - enter boat name:
- yes - list of existing boats with same/similar name: choose one
or or
- no: - add a new boat: boat form
- enter company(insurance) name: NEXT
- list of existing companies with same/similar name: choose one
or - same insurance?:
- add a new company: company form - yes
or
NEXT - no:
- enter company(insurance) name:
- persons: - list of existing companies with same/similar name: choose one
- list of persons on this boat in the past: or
- edit - add a new company: company form
- checkbox: is 'captain', 'crew', etc, during this stay
- add new person: person form NEXT
NEXT - persons:
- list of persons on this boat in the past:
- stay: stay form (add number of passengers) - edit
- checkbox: is 'captain', 'crew', etc, during this stay
SAVE - add new person: person form
NEW PAYMENT NEXT
- list of current stays: select one - stay: stay form (add number of passengers)
NEXT SAVE
- bill: bill form NEW PAYMENT
- number of nights:
- calculated if there is a departure date - list of current stays: select one
or
- enter a number if no departure date NEXT
- shower
- bill: bill form
- number of nights:
- calculated if there is a departure date
or
- enter a number if no departure date
- shower
- water: number of tons used for passenger boats - water: number of tons used for passenger boats

View File

@ -128,3 +128,5 @@ STATIC_URL = '/static/'
STATICFILES_DIRS = [ STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static") os.path.join(BASE_DIR, "static")
] ]
## CUSTOM CONF

View File

@ -17,7 +17,7 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = [
#path('', include('port.urls', namespace='index')), path('', include('port.urls.index', namespace='index')),
path('port/', include('port.urls.port', namespace='port')), path('port/', include('port.urls.port', namespace='port')),
path('person/', include('port.urls.person', namespace='person')), path('person/', include('port.urls.person', namespace='person')),
path('boat/', include('port.urls.boat', namespace='boat')), path('boat/', include('port.urls.boat', namespace='boat')),

View File

@ -1,6 +0,0 @@
TODO :
- see if we can add a person in a Mooring (problem if the boat fleets
changes between two moorings)
- how to determine which is the right person if choosing from a list and two
have the same names (rare)

View File

@ -1,11 +1,15 @@
from django.forms import Form, ModelForm, \ from django.forms import Form, ModelForm, \
CharField, IntegerField, DecimalField, \ CharField, IntegerField, DecimalField, ChoiceField,\
BooleanField, EmailField, DateTimeField, ImageField, \ BooleanField, EmailField, DateTimeField, ImageField, \
formset_factory, SelectDateWidget formset_factory, SelectDateWidget, TextInput, \
from django_countries.fields import CountryField RadioSelect
from phonenumber_field.formfields import PhoneNumberField
from django_countries.fields import CountryField
from phonenumber_field.formfields import PhoneNumberField
from .models import Address, Person, Company, Insurance, Boat, \
SailsOn, BoatInsurance, Port, Employee, Dock, Plug, Tap, \
Payment, Service, Bill, BillLine, BillPayment, Stay, Mooring
from .models import *
class AddressForm(ModelForm): class AddressForm(ModelForm):
class Meta: class Meta:
@ -55,6 +59,22 @@ class InsuranceForm(CompanyForm):
'name'] 'name']
class BoatSearchForm(Form):
search_name = CharField(
label='Name'
)
search_results = ChoiceField(
label='Boats',
widget=RadioSelect
)
def __init__(self, name='', choices=[]):
super(Form, self).__init__()
print(name)
self.fields['search_name'].initial = name
self.fields['search_results'].choices = choices
class BoatForm(ModelForm): class BoatForm(ModelForm):
class Meta: class Meta:
model = Boat model = Boat

View File

@ -1,6 +0,0 @@
TODO :
- see if we can add a person in a Mooring (problem if the boat fleets
changes between two moorings)
- how to determine which is the right person if choosing from a list and two
have the same names (rare)

View File

@ -0,0 +1,105 @@
# Generated by Django 2.2.1 on 2019-06-22 17:46
from django.db import migrations, models
import django.db.models.deletion
import port.models
class Migration(migrations.Migration):
dependencies = [
('port', '0003_auto_20190608_1839'),
]
operations = [
migrations.AddField(
model_name='sailson',
name='present',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='address',
name='address',
field=models.CharField(default='miss_add', max_length=200),
),
migrations.AlterField(
model_name='address',
name='city',
field=models.CharField(default='miss_city', max_length=200),
),
migrations.AlterField(
model_name='address',
name='zip_code',
field=models.CharField(default='miss_zip', max_length=10),
),
migrations.AlterField(
model_name='boat',
name='beam',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, validators=[port.models.validate_positive]),
),
migrations.AlterField(
model_name='boat',
name='boat_insurance',
field=models.ManyToManyField(blank=True, through='port.BoatInsurance', to='port.Insurance'),
),
migrations.AlterField(
model_name='boat',
name='length',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, validators=[port.models.validate_positive], verbose_name='Length'),
),
migrations.AlterField(
model_name='boat',
name='tonnage',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, validators=[port.models.validate_positive]),
),
migrations.AlterField(
model_name='boat',
name='water_draught',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, validators=[port.models.validate_positive]),
),
migrations.AlterField(
model_name='boat',
name='water_tank',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, validators=[port.models.validate_positive], verbose_name='Water tank capacity'),
),
migrations.AlterField(
model_name='company',
name='name',
field=models.CharField(blank=True, max_length=50),
),
migrations.AlterField(
model_name='dock',
name='depth_max',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, validators=[port.models.validate_positive]),
),
migrations.AlterField(
model_name='dock',
name='depth_min',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, validators=[port.models.validate_positive]),
),
migrations.AlterField(
model_name='dock',
name='length',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, validators=[port.models.validate_positive]),
),
migrations.AlterField(
model_name='dock',
name='width',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, validators=[port.models.validate_positive]),
),
migrations.AlterField(
model_name='employee',
name='port',
field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.PROTECT, to='port.Port'),
),
migrations.AlterField(
model_name='plug',
name='amperage',
field=models.DecimalField(decimal_places=2, max_digits=7, validators=[port.models.validate_positive]),
),
migrations.AlterField(
model_name='plug',
name='voltage',
field=models.DecimalField(decimal_places=2, max_digits=7, validators=[port.models.validate_positive]),
),
]

View File

@ -18,6 +18,7 @@
<link rel="stylesheet" href="{% static "css/normalize.css" %}"> <link rel="stylesheet" href="{% static "css/normalize.css" %}">
<link rel="stylesheet" href="{% static "css/skeleton.css" %}"> <link rel="stylesheet" href="{% static "css/skeleton.css" %}">
<link rel="stylesheet" href="{% static "css/gpp.css" %}">
<link rel="icon" type="image/png" href="{% static "images/favicon.png" %}"> <link rel="icon" type="image/png" href="{% static "images/favicon.png" %}">
<!-- <!--

10
port/templates/index.html Normal file
View File

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block content %}
<form action="{% url 'index:new_stay' %}"
method="post">
{% csrf_token %}
{% block form %}
<a href="{% url 'index:new_stay' %}">New Stay</a>
{% endblock %}
</form>
{% endblock %}

View File

@ -0,0 +1,10 @@
{% extends "index.html" %}
{% block form %}
<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" />
{% endblock %}

View File

@ -5,4 +5,5 @@ from .views.index import *
app_name = 'index' app_name = 'index'
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('/new_stay', new_stay, name='new_stay'),
] ]

9
port/urls/index.py Normal file
View File

@ -0,0 +1,9 @@
from django.urls import path
from ..views.index import *
app_name = 'index'
urlpatterns = [
path('', index, name='index'),
path('new_stay/', new_stay, name='new_stay'),
]

View File

@ -1,17 +1,51 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.conf import settings
from django.forms import TextInput, RadioSelect
from pprint import pprint from pprint import pprint
from ..models import * from ..models import *
from ..forms import * from ..forms import *
import ..views as Views #import ..views as Views
def index(request): def index(request):
return HttpResponse("Hello World") return render(request, 'index.html')
def index_port(request): def new_stay(request):
return Views.port.index(request) if not request.session.get('new_stay_step', False) \
or request.session.get('new_stay_done', False) :
# This is a new stay, we initialize the session
request.session['new_stay_step'] = 0
request.session['new_stay_done'] = False
def index_person(request): name = request.POST.get('search_name', '')
return Views.person.index(request) boat_existing = [ (b.id, b.name) for b in \
Boat.objects.filter(name__icontains=name) ]
pprint(boat_existing)
boat_search_form = BoatSearchForm(
name=name,
choices=boat_existing)
boat_form = BoatForm()
return render(request,
'new_stay/new_stay-0.html',
{
'boat_search_form': boat_search_form,
'boat_form': boat_form
})
# Boat form
elif request.session['new_stay_step'] == 1:
# Insurance form
return render(request, 'new_stay-1.html')
elif request.session['new_stay_step'] ==2:
# Person form
return render(request, 'new_stay-2.html')
elif request.session['new_stay_step'] ==3:
# Stay form
return render(request, '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')

View File

@ -0,0 +1,25 @@
"""gpp URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
#path('', include('port.urls', namespace='index')),
path('port/', include('port.urls.port', namespace='port')),
path('person/', include('port.urls.person', namespace='person')),
path('boat/', include('port.urls.boat', namespace='boat')),
path('admin/', admin.site.urls),
]

View File

@ -0,0 +1,49 @@
from django.shortcuts import render
from django.http import HttpResponse
from pprint import pprint
from .models import *
from .forms import *
def index(request):
return HttpResponse("Hello, world.")
def ports_status(request):
"""
res = ''
ports = Port.objects.all()
li = lambda x: '<li>' + str(x)
res = ''.join(map(li, ports))
res = '<html><body><ul>' + res + '</ul></body></html>'
return HttpResponse(res)
"""
return render(request, 'port/ports_status.html', {'ports': Port.objects})
def add_person(request):
"""
[GET] Renders the view to help people add persons
[POST] Adds person
"""
forms = {'person':None, 'address':None}
if (request.method == 'POST'):
forms.update({'person':PersonForm(request.POST)})
if (forms.get('person').is_valid()):
Person.objects.create(forms.get('person').cleaned_data)
return list_persons(request)
# Address handlinG
forms.update({'person':PersonForm(request.POST)})
if (forms.get('person').is_valid()):
Person.objects.create(forms.get('person').cleaned_data)
return list_persons(request)
else:
forms.update({'person':PersonForm()})
return render(request, 'person/add.html', {'form':forms})
def list_persons(request):
return render(request, 'person/list.html', {'persons': Person.objects})

View File

@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block content %}
<form action="{% url 'person:add' %}" method="post">
{% csrf_token %}
<fieldset>
<!-- TO IMPLEMENT -->
<legend>Person</legend>
{{ form.person }}
</fieldset>
<input type="submit" value="add"/>
</form>
{% endblock %}

View File

@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block content %}
<ul>
<!-- TO IMPLEMENT -->
{% for person in persons.all %}
<li>{{ person }}</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -0,0 +1,13 @@
from django.urls import path
from ..views.person import *
app_name = 'person'
urlpatterns = [
path('', index, name='index'),
path('list', list_persons, name='list'),
path('form', form_person, name='form'),
path('add', add_person, name='add'),
]

View File

@ -0,0 +1,22 @@
from django.shortcuts import render
from django.http import HttpResponse
from pprint import pprint
from ..models import *
from ..forms import *
def index(request):
return HttpResponse("Hello Person")
def list_persons(request):
# TO IMPLEMENT
pass
def form_person(request):
# TO IMPLEMENT
pass
def add_person(request):
# TO IMPLEMENT
pass

7
static/css/gpp.css Normal file
View File

@ -0,0 +1,7 @@
.hidden {
display : none;
}
ul {
list-style-type : none;
}

View File

@ -1,49 +0,0 @@
HOME:
- NEW STAY
- NEW PAYMENT
NEW STAY
- enter boat name:
- list of existing boats with same/similar name: choose one
or
- add a new boat: boat form
NEXT
- same insurance?:
- yes
or
- no:
- enter company(insurance) name:
- list of existing companies with same/similar name: choose one
or
- add a new company: company form
NEXT
- persons:
- list of persons on this boat in the past:
- edit
- checkbox: is 'captain', 'crew', etc, during this stay
- add new person: person form
NEXT
- stay: stay form (add number of passengers)
SAVE
NEW PAYMENT
- list of current stays: select one
NEXT
- bill: bill form
- number of nights:
- calculated if there is a departure date
or
- enter a number if no departure date
- shower
- water: number of tons used for passenger boats