def planes(request): planes = Plane.objects.filter(user=request.display_user) form = PopupPlaneForm() changed = False if request.POST.get('submit') == "Create New Plane": plane = Plane(user=request.display_user) form = PopupPlaneForm(request.POST, instance=plane) edit_or_new = "new" if form.is_valid(): plane = form.save(commit=False) plane.user = request.display_user plane.save() changed = True elif request.POST.get('submit') == "Submit Changes": plane = Plane.objects.get(pk=request.POST.get("id")) form = PopupPlaneForm(request.POST, instance=plane) edit_or_new = "edit" if form.is_valid(): plane = form.save(commit=False) plane.user = request.display_user plane.save() changed = True elif request.POST.get('submit') == "Delete Plane": plane = Plane.objects.get(pk=request.POST.get("id")) if not plane.flight_set.all().count() > 0: plane.delete() changed = True if changed: from backup.models import edit_logbook edit_logbook.send(sender=request.display_user) return locals()
def planes(request): planes = Plane.objects.filter(user=request.display_user) form = PopupPlaneForm() changed = False if request.POST.get('submit') == "Create New Plane": plane = Plane(user=request.display_user) form = PopupPlaneForm(request.POST, instance=plane) edit_or_new = "new" if form.is_valid(): plane=form.save(commit=False) plane.user=request.display_user plane.save() changed = True elif request.POST.get('submit') == "Submit Changes": plane = Plane.objects.get(pk=request.POST.get("id")) form = PopupPlaneForm(request.POST, instance=plane) edit_or_new = "edit" if form.is_valid(): plane=form.save(commit=False) plane.user=request.display_user plane.save() changed = True elif request.POST.get('submit') == "Delete Plane": plane = Plane.objects.get(pk=request.POST.get("id")) if not plane.flight_set.all().count() > 0: plane.delete() changed = True if changed: from backup.models import edit_logbook edit_logbook.send(sender=request.display_user) return locals()
def test_plane_profile_urls(self): """ Tests that 1 + 1 always equals 2. """ p1 = Plane(type="C-172", tailnumber="N12\34334") p2 = Plane(type="C17#2", tailnumber="N??1234") p3 = Plane(type="C/172", tailnumber="N/1234") p4 = Plane(type="C ^72", tailnumber="N1234#") p5 = Plane(type="C=172", tailnumber="N1234.") p6 = Plane(type="C+17 ", tailnumber="N1234-2") p7 = Plane(type="C 172", tailnumber="N1234(1)") p8 = Plane(type="c-172", tailnumber="N1234[1]") p9 = Plane(type="C-172", tailnumber="N1234{1}") p10 = Plane(type=None, tailnumber=None) p1.save() p2.save() p3.save() p4.save() p5.save() p6.save() p7.save() p8.save() p9.save() p10.save() self.failUnlessEqual("%s" % p1, "N1234 (C-172)") self.failUnlessEqual("%s" % p2, "N1234 (C172)") self.failUnlessEqual("%s" % p3, "N1234 (C172)") self.failUnlessEqual("%s" % p4, "N1234 (C72)") self.failUnlessEqual("%s" % p5, "N1234. (C172)") self.failUnlessEqual("%s" % p6, "N1234-2 (C17)") self.failUnlessEqual("%s" % p7, "N1234(1) (C172)") self.failUnlessEqual("%s" % p8, "N1234[1] (c-172)") self.failUnlessEqual("%s" % p9, "N1234{1} (C-172)") self.failUnlessEqual("%s" % p10, "")
def test_plane_profile_urls(self): """ Tests that 1 + 1 always equals 2. """ p1 = Plane(type="C-172", tailnumber="N12\34334") p2 = Plane(type="C17#2", tailnumber="N??1234") p3 = Plane(type="C/172", tailnumber="N/1234") p4 = Plane(type="C ^72", tailnumber="N1234#") p5 = Plane(type="C=172", tailnumber="N1234.") p6 = Plane(type="C+17 ", tailnumber="N1234-2") p7 = Plane(type="C 172", tailnumber="N1234(1)") p8 = Plane(type="c-172", tailnumber="N1234[1]") p9 = Plane(type="C-172", tailnumber="N1234{1}") p10 = Plane(type=None, tailnumber=None) p1.save() p2.save() p3.save() p4.save() p5.save() p6.save() p7.save() p8.save() p9.save() p10.save() self.failUnlessEqual("%s" % p1, "N1234 (C-172)") self.failUnlessEqual("%s" % p2, "N1234 (C172)") self.failUnlessEqual("%s" % p3, "N1234 (C172)") self.failUnlessEqual("%s" % p4, "N1234 (C72)") self.failUnlessEqual("%s" % p5, "N1234. (C172)") self.failUnlessEqual("%s" % p6, "N1234-2 (C17)") self.failUnlessEqual("%s" % p7, "N1234(1) (C172)") self.failUnlessEqual("%s" % p8, "N1234[1] (c-172)") self.failUnlessEqual("%s" % p9, "N1234{1} (C-172)") self.failUnlessEqual("%s" % p10, "")