diff --git a/doc/gpp_todo b/doc/gpp_todo index e086686..c2e9981 100644 --- a/doc/gpp_todo +++ b/doc/gpp_todo @@ -5,3 +5,15 @@ TODO : - how to determine which is the right person if choosing from a list and two have the same names (rare) : 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 + diff --git a/doc/structure.txt b/doc/structure.txt index 8d11999..df6adc1 100644 --- a/doc/structure.txt +++ b/doc/structure.txt @@ -1,49 +1,55 @@ -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 +HOME: + - NEW STAY + - NEW PAYMENT + - FIND/EDIT STAY + - FIND/EDIT BOAT + - FIND/EDIT PERSON + - NEW PORT + - FIND/EDIT PORT + - SCHEDULE + - ACCOUNTING: FIND 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 \ No newline at end of file diff --git a/gpp/settings.py b/gpp/settings.py index 336e62b..7beefbb 100644 --- a/gpp/settings.py +++ b/gpp/settings.py @@ -128,3 +128,5 @@ STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static") ] + +## CUSTOM CONF diff --git a/gpp/urls.py b/gpp/urls.py index e0b7360..7adc9b9 100644 --- a/gpp/urls.py +++ b/gpp/urls.py @@ -17,7 +17,7 @@ from django.contrib import admin from django.urls import include, path urlpatterns = [ - #path('', include('port.urls', namespace='index')), + path('', include('port.urls.index', 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')), diff --git a/gpp_todo b/gpp_todo deleted file mode 100644 index 0ea1236..0000000 --- a/gpp_todo +++ /dev/null @@ -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) - diff --git a/port/forms.py b/port/forms.py index e2023fa..a38680d 100644 --- a/port/forms.py +++ b/port/forms.py @@ -1,11 +1,15 @@ from django.forms import Form, ModelForm, \ - CharField, IntegerField, DecimalField, \ + CharField, IntegerField, DecimalField, ChoiceField,\ BooleanField, EmailField, DateTimeField, ImageField, \ - formset_factory, SelectDateWidget -from django_countries.fields import CountryField -from phonenumber_field.formfields import PhoneNumberField + formset_factory, SelectDateWidget, TextInput, \ + RadioSelect + +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 Meta: @@ -55,6 +59,22 @@ class InsuranceForm(CompanyForm): '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 Meta: model = Boat diff --git a/port/gpp_todo b/port/gpp_todo deleted file mode 100644 index 0ea1236..0000000 --- a/port/gpp_todo +++ /dev/null @@ -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) - diff --git a/port/migrations/0004_auto_20190622_1946.py b/port/migrations/0004_auto_20190622_1946.py new file mode 100644 index 0000000..f9e9767 --- /dev/null +++ b/port/migrations/0004_auto_20190622_1946.py @@ -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]), + ), + ] diff --git a/port/templates/base.html b/port/templates/base.html index ad83992..479cdf4 100644 --- a/port/templates/base.html +++ b/port/templates/base.html @@ -18,6 +18,7 @@ + + + +{% endblock %} diff --git a/port/urls.py b/port/urls.py index 11133d0..2da6794 100644 --- a/port/urls.py +++ b/port/urls.py @@ -5,4 +5,5 @@ from .views.index import * app_name = 'index' urlpatterns = [ path('', index, name='index'), + path('/new_stay', new_stay, name='new_stay'), ] diff --git a/port/urls/index.py b/port/urls/index.py new file mode 100644 index 0000000..af73cc3 --- /dev/null +++ b/port/urls/index.py @@ -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'), +] diff --git a/port/views/index.py b/port/views/index.py index b43261d..9c665f9 100644 --- a/port/views/index.py +++ b/port/views/index.py @@ -1,17 +1,51 @@ from django.shortcuts import render from django.http import HttpResponse +from django.conf import settings +from django.forms import TextInput, RadioSelect from pprint import pprint from ..models import * from ..forms import * -import ..views as Views +#import ..views as Views def index(request): - return HttpResponse("Hello World") + return render(request, 'index.html') -def index_port(request): - return Views.port.index(request) +def new_stay(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): - return Views.person.index(request) + name = request.POST.get('search_name', '') + 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') diff --git a/route_template.tmp/gpp/urls.py b/route_template.tmp/gpp/urls.py new file mode 100644 index 0000000..e0b7360 --- /dev/null +++ b/route_template.tmp/gpp/urls.py @@ -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), +] diff --git a/route_template.tmp/gpp/views.py b/route_template.tmp/gpp/views.py new file mode 100644 index 0000000..e9fe858 --- /dev/null +++ b/route_template.tmp/gpp/views.py @@ -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: '
  • ' + str(x) + res = ''.join(map(li, ports)) + res = '' + 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}) diff --git a/route_template.tmp/port/templates/person/add.html b/route_template.tmp/port/templates/person/add.html new file mode 100644 index 0000000..6a3f59f --- /dev/null +++ b/route_template.tmp/port/templates/person/add.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% block content %} +
    + {% csrf_token %} +
    + + Person + {{ form.person }} +
    + +
    +{% endblock %} diff --git a/route_template.tmp/port/templates/person/list.html b/route_template.tmp/port/templates/person/list.html new file mode 100644 index 0000000..abcb9f3 --- /dev/null +++ b/route_template.tmp/port/templates/person/list.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block content %} + +{% endblock %} diff --git a/route_template.tmp/port/urls/person.py b/route_template.tmp/port/urls/person.py new file mode 100644 index 0000000..bebcae3 --- /dev/null +++ b/route_template.tmp/port/urls/person.py @@ -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'), + +] + diff --git a/route_template.tmp/port/views/person.py b/route_template.tmp/port/views/person.py new file mode 100644 index 0000000..bc8101e --- /dev/null +++ b/route_template.tmp/port/views/person.py @@ -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 diff --git a/static/css/gpp.css b/static/css/gpp.css new file mode 100644 index 0000000..87cac96 --- /dev/null +++ b/static/css/gpp.css @@ -0,0 +1,7 @@ +.hidden { + display : none; +} + +ul { + list-style-type : none; +} diff --git a/structure.txt b/structure.txt deleted file mode 100644 index 8d11999..0000000 --- a/structure.txt +++ /dev/null @@ -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 \ No newline at end of file