diff --git a/gpp/urls.py b/gpp/urls.py index b4ff80a..9a4093b 100644 --- a/gpp/urls.py +++ b/gpp/urls.py @@ -17,8 +17,8 @@ from django.contrib import admin from django.urls import include, path urlpatterns = [ - path('', include('port.urls')), - path('port/', include('port.urls', namespace='port')), - path('person/', include('port.urls', namespace='person')), + #path('', include('port.urls', namespace='index')), + path('port/', include('port.urls.port', namespace='port')), + path('person/', include('port.urls.person', namespace='person')), path('admin/', admin.site.urls), ] diff --git a/port/forms.py b/port/forms.py index 6c301d7..9c2d781 100644 --- a/port/forms.py +++ b/port/forms.py @@ -1,5 +1,5 @@ from django.forms import Form, CharField, IntegerField, DecimalField, \ - BooleanField, EmailField, DateTimeField, ImageField + BooleanField, EmailField, DateTimeField, ImageField, formset_factory from django_countries.fields import CountryField from phonenumber_field.formfields import PhoneNumberField @@ -15,3 +15,49 @@ class AddressForm(Form): zip_code = CharField(label='ZipCode', max_length=10) city = CharField(label='City', max_length=200) country = CountryField().formfield(label='Country') + +class DockForm(Form): + name = CharField(label='Name', max_length=10) + length = DecimalField( + label='Length', min_value=0, + max_digits=7, + decimal_places=2) + width = DecimalField( + label='Width', min_value=0, + max_digits=7, + decimal_places=2) + depth_min = DecimalField( + label='Depth (min.)', min_value=0, + max_digits=7, + decimal_places=2) + depth_max = DecimalField( + label='Depth (max.)', min_value=0, + max_digits=7, + decimal_places=2) + +DockFormSet = formset_factory(DockForm) + +class PortForm(Form): + name = CharField(label='Name', max_length=50) + address = CharField(label='Address', max_length=50) + company = CharField(label='Company', max_length=50) + +class PlugForm(Form): + name = CharField(label='Name', max_length=10) + amperage = DecimalField( + label='Amperage', + min_value=0, + max_digits=3, + decimal_places=0) + voltage = DecimalField( + label='Voltage', + min_value=0, + max_digits=3, + decimal_places=0) + +PlugFormSet = formset_factory(PlugForm) + +class TapForm(Form): + name = CharField(label='Name', max_length=10) + +TapFormSet = formset_factory(TapForm) diff --git a/port/migrations/0002_auto_20190607_1129.py b/port/migrations/0002_auto_20190607_1129.py new file mode 100644 index 0000000..df7ca36 --- /dev/null +++ b/port/migrations/0002_auto_20190607_1129.py @@ -0,0 +1,65 @@ +# Generated by Django 2.2.1 on 2019-06-07 09:29 + +from django.db import migrations, models +import django_countries.fields +import phonenumber_field.modelfields + + +class Migration(migrations.Migration): + + dependencies = [ + ('port', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='dock', + old_name='depth', + new_name='depth_max', + ), + migrations.RenameField( + model_name='dock', + old_name='num', + new_name='name', + ), + migrations.RenameField( + model_name='plug', + old_name='num', + new_name='name', + ), + migrations.RenameField( + model_name='tap', + old_name='num', + new_name='name', + ), + migrations.AddField( + model_name='billline', + name='value', + field=models.DecimalField(decimal_places=2, default=0.0, max_digits=7), + ), + migrations.AddField( + model_name='dock', + name='depth_min', + field=models.DecimalField(decimal_places=2, max_digits=7, null=True), + ), + migrations.AlterField( + model_name='address', + name='country', + field=django_countries.fields.CountryField(max_length=2), + ), + migrations.AlterField( + model_name='company', + name='phone', + field=phonenumber_field.modelfields.PhoneNumberField(max_length=128, null=True, region=None), + ), + migrations.AlterField( + model_name='person', + name='nationality', + field=django_countries.fields.CountryField(max_length=2, null=True), + ), + migrations.AlterField( + model_name='person', + name='phone', + field=phonenumber_field.modelfields.PhoneNumberField(max_length=128, null=True, region=None), + ), + ] diff --git a/port/models.py b/port/models.py index 7846cda..cbf4992 100644 --- a/port/models.py +++ b/port/models.py @@ -19,7 +19,7 @@ class Address(Model): class Person(Model): name = CharField(max_length=50,null=True) surname = CharField(max_length=50,null=True) - nationality = CountryField() + nationality = CountryField(null=True) email = EmailField(max_length=254,null=True) phone = PhoneNumberField(null=True) @@ -116,12 +116,12 @@ class Employee(Model): return '{}, {} at {}'.format(str(self.person), self.position, str(self.port)) - class Dock(Model): - num = CharField(max_length=10) + name = CharField(max_length=10) length = DecimalField(max_digits=7, decimal_places=2, null=True) width = DecimalField(max_digits=7, decimal_places=2, null=True) - depth = DecimalField(max_digits=7, decimal_places=2, null=True) + depth_min = DecimalField(max_digits=7, decimal_places=2, null=True) + depth_max = DecimalField(max_digits=7, decimal_places=2, null=True) # Foreign keys port = ForeignKey(Port,on_delete=PROTECT) @@ -129,7 +129,7 @@ class Dock(Model): return '{} : {}'.format(str(self.port), self.num) class Plug(Model): - num = CharField(max_length=10) + name = CharField(max_length=10) amperage = DecimalField(max_digits=7, decimal_places=2) voltage = DecimalField(max_digits=7, decimal_places=2) @@ -139,7 +139,7 @@ class Plug(Model): return '{} : {}'.format(str(self.port), self.num) class Tap(Model): - num = CharField(max_length=10) + name = CharField(max_length=10) # Foreign keys port = ForeignKey(Port,on_delete=PROTECT) @@ -184,7 +184,7 @@ class Bill(Model): class BillLine(Model): quantity = DecimalField(max_digits=7, decimal_places=2) - value = DecimalField(max_digits=7, decimal_places=2) + value = DecimalField(max_digits=7, decimal_places=2, default=0.) # Foreign keyks service = ForeignKey(Service,on_delete=PROTECT) diff --git a/port/templates/port/form.html b/port/templates/port/form.html new file mode 100644 index 0000000..bc51402 --- /dev/null +++ b/port/templates/port/form.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} +{% block content %} +
+ {% csrf_token %} +
+ Port + {{ port_form }} +
+
+ Dock + + {% for dock_form in dock_forms %} + {{ dock_form.as_table }} + {% endfor %} +
+
+
+ Plug + + {% for plug_form in plug_forms %} + {{ plug_form.as_table }} + {% endfor %} +
+
+
+ Tap + + {% for tap_form in tap_forms %} + {{ tap_form.as_table }} + {% endfor %} +
+
+ +
+ +{% endblock %} diff --git a/port/templates/port/list.html b/port/templates/port/list.html new file mode 100644 index 0000000..636f12a --- /dev/null +++ b/port/templates/port/list.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} +{% block content %} + +{% endblock %} diff --git a/port/urls.py b/port/urls.py index 92b8e27..11133d0 100644 --- a/port/urls.py +++ b/port/urls.py @@ -1,11 +1,8 @@ from django.urls import path -from . import views +from .views.index import * -app_name = 'port' +app_name = 'index' urlpatterns = [ - path('', views.index, name='index'), - path('', views.ports_status, name='list'), - path('new', views.add_person, name='add'), - path('list', views.list_persons, name='list'), + path('', index, name='index'), ] diff --git a/port/urls/__init__.py b/port/urls/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/port/urls/person.py b/port/urls/person.py new file mode 100644 index 0000000..5066e07 --- /dev/null +++ b/port/urls/person.py @@ -0,0 +1,9 @@ +from django.urls import path + +from ..views.person import * + +app_name = 'person' +urlpatterns = [ + path('', index, name='index'), +] + diff --git a/port/urls/port.py b/port/urls/port.py new file mode 100644 index 0000000..ee7523f --- /dev/null +++ b/port/urls/port.py @@ -0,0 +1,11 @@ +from django.urls import path + +from ..views.port import * + +app_name = 'port' +urlpatterns = [ + path('', index, name='index'), + path('list', list_ports, name='list'), + path('form', form, name='form'), + path('add', add_port, name='add'), +] diff --git a/port/views/__init__.py b/port/views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/port/views/index.py b/port/views/index.py new file mode 100644 index 0000000..b43261d --- /dev/null +++ b/port/views/index.py @@ -0,0 +1,17 @@ +from django.shortcuts import render +from django.http import HttpResponse + +from pprint import pprint + +from ..models import * +from ..forms import * +import ..views as Views + +def index(request): + return HttpResponse("Hello World") + +def index_port(request): + return Views.port.index(request) + +def index_person(request): + return Views.person.index(request) diff --git a/port/views/person.py b/port/views/person.py new file mode 100644 index 0000000..c834fd9 --- /dev/null +++ b/port/views/person.py @@ -0,0 +1,10 @@ +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") diff --git a/port/views/port.py b/port/views/port.py new file mode 100644 index 0000000..64064cb --- /dev/null +++ b/port/views/port.py @@ -0,0 +1,45 @@ +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 Port") + + +def list_ports(request): + return render(request, 'port/list.html', + {'ports': Port.objects.all}) + +def add_port(request): + if request.method == 'POST': + port_form = PortForm(request.POST) + if not port_form.is_valid(): + return form(request) + dock_forms = DockFormSet(request.POST) + dock_forms_data = dock_forms.save(commit=False) + for dock_data in dock_forms_data: + pass + + plug_forms = PlugFormSet(request.POST) + plug_forms_data = plug_forms.save(commit=False) + + tap_forms = tapFormSet(request.POST) + tap_forms_data = tap_forms.save(commit=False) + + + return form(request) + +def form(request): + port_form = PortForm() + dock_forms = DockFormSet() + plug_forms = PlugFormSet() + tap_forms = TapFormSet() + return render(request, 'port/form.html', + {'port_form': port_form, + 'dock_forms': dock_forms, + 'plug_forms': plug_forms, + 'tap_forms': tap_forms})