gpp/port/views/port.py

48 lines
1.3 KiB
Python

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 form_port(request):
port_form = PortForm(prefix='por')
dock_forms = DockFormSet(prefix='doc')
plug_forms = PlugFormSet(prefix='plu')
tap_forms = TapFormSet(prefix='tap')
return render(request, 'port/form.html',
{'port_form': port_form,
'dock_forms': dock_forms,
'plug_forms': plug_forms,
'tap_forms': tap_forms,
'employees': Employee.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:
pprint(dock_data)
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)