2019-05-27 08:04:29 +02:00
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
2019-06-05 20:06:51 +02:00
|
|
|
from pprint import pprint
|
|
|
|
|
2019-06-02 18:07:37 +02:00
|
|
|
from .models import *
|
2019-06-05 20:06:51 +02:00
|
|
|
from .forms import *
|
2019-06-02 18:07:37 +02:00
|
|
|
|
2019-05-27 08:04:29 +02:00
|
|
|
def index(request):
|
|
|
|
return HttpResponse("Hello, world.")
|
2019-06-02 18:07:37 +02:00
|
|
|
|
|
|
|
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})
|
2019-06-05 20:06:51 +02:00
|
|
|
|
|
|
|
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})
|