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})