gpp/port/views.py

50 lines
1.4 KiB
Python
Raw Normal View History

2019-05-27 08:04:29 +02:00
from django.shortcuts import render
from django.http import HttpResponse
from pprint import pprint
from .models import *
from .forms import *
2019-05-27 08:04:29 +02:00
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})