def new( request ): d2p = DictToPoint( request.REQUEST ) pnt = d2p.pnt() if request.method == "POST": #an UpdateForm is bundled inside ReportForm report_form = ReportForm( request.POST, request.FILES, user=request.user ) # this checks update is_valid too if report_form.is_valid(): # this saves the update as part of the report. report = report_form.save() if report: return( HttpResponseRedirect( report.get_absolute_url() )) else: initial = {} initial['lat' ] =request.GET['lat'] initial['lon'] = request.GET['lon'] initial['address'] = request.GET.get('address',None) report_form = ReportForm( initial=initial, user=request.user ) return render_to_response("reports/new.html", { "google": FixMyStreetMap(pnt, True), 'GOOGLE_KEY': settings.GMAP_KEY, "report_form": report_form, "update_form": report_form.update_form, 'ward': report_form.ward }, context_instance=RequestContext(request))
def new( request ): if request.method == "POST": pnt = DictToPoint( request.POST ).pnt() report_form = ReportForm( request.POST, request.FILES ) # this checks update is_valid too if report_form.is_valid(): # this saves the update as part of the report. report = report_form.save() if report: return( HttpResponseRedirect( report.get_absolute_url() )) else: pnt = DictToPoint( request.GET ).pnt() report_form = ReportForm(initial={ 'lat': request.GET['lat'], 'lon': request.GET['lon'] } ) ward=None wards = Ward.objects.filter(geom__contains=pnt)[:1] if wards: ward = wards[0] return render_to_response("reports/new.html", { "google": FixMyStreetMap(pnt, True), "report_form": report_form, "update_form": report_form.update_form, 'ward':ward }, context_instance=RequestContext(request))
def new( request ): category_error = None if request.method == "POST": pnt = fromstr("POINT(" + request.POST["lon"] + " " + request.POST["lat"] + ")", srid=4326) f = request.POST.copy() update_form = ReportUpdateForm( {'email':request.POST['email'], 'desc':request.POST['desc'], 'author':request.POST['author'], 'phone': request.POST['phone']}) report_form = ReportForm({'title' : request.POST['title']}, request.FILES ) # this is a lot more complicated than it has to be because of the infortmation # spread across two records. if request.POST['category_id'] != "" and update_form.is_valid() and report_form.is_valid(): report = report_form.save( commit = False ) report.point = pnt report.category_id = request.POST['category_id'] report.author = request.POST['author'] report.desc = request.POST['desc'] report.ward = Ward.objects.get(geom__contains=pnt) report.save() update = update_form.save(commit=False) update.report = report update.first_update = True update.created_at = report.created_at update.save() return( HttpResponseRedirect( report.get_absolute_url() )) # other form errors are handled by the form objects. if not request.POST['category_id']: category_error = _("Please select a category") else: pnt = fromstr("POINT(" + request.GET["lon"] + " " + request.GET["lat"] + ")", srid=4326) report_form = ReportForm() update_form = ReportUpdateForm() return render_to_response("reports/new.html", { "lat": pnt.y, "lon": pnt.x, "google": FixMyStreetMap(pnt, True), "categories": ReportCategory.objects.all().order_by("category_class"), "report_form": report_form, "update_form": update_form, "category_error" : category_error, }, context_instance=RequestContext(request))
def new(request): d2p = DictToPoint(request.REQUEST) pnt = d2p.pnt() if request.method == "POST": #an UpdateForm is bundled inside ReportForm report_form = ReportForm(request.POST, request.FILES, user=request.user) # this checks update is_valid too if report_form.is_valid(): # this saves the update as part of the report. report = report_form.save() if report: return (HttpResponseRedirect(report.get_absolute_url())) else: initial = {} initial['lat'] = request.GET['lat'] initial['lon'] = request.GET['lon'] initial['address'] = request.GET.get('address', None) report_form = ReportForm(initial=initial, user=request.user) return render_to_response("reports/new.html", { "google": FixMyStreetMap(pnt, True), 'GOOGLE_KEY': settings.GMAP_KEY, "report_form": report_form, "update_form": report_form.update_form, 'ward': report_form.ward }, context_instance=RequestContext(request))
def new(request): form_error = category_error = title = street = author = email = phone = desc = pnt = city = None if request.method == "POST": POST = request.POST.copy() point_str = "POINT(" + POST['lon'] + " " + POST['lat'] + ")" pnt = fromstr(point_str, srid=4326) title = POST['title'] street = POST['street'] author = POST['author'] email = POST['email'] phone = POST['phone'] desc = POST['desc'] city = POST['city'] update_form = ReportUpdateForm({'email': email, 'desc': desc, 'author': author, 'phone': phone}, request.FILES) report_form = ReportForm({'title': title, 'street': street}, request.FILES) if update_form.is_valid and report_form.is_valid: pass else: HttpResponseRedirect('/') if request.POST.get('step') == '2': # this is a lot more complicated than it has to be because of the infortmation # spread across two records. if request.POST['category_id'] != "" and update_form.is_valid() and report_form.is_valid(): report = report_form.save(commit=False) report.point = pnt report.category_id = request.POST['category_id'] report.ip = utils.get_client_ip(request) report.author = request.POST['author'] report.desc = request.POST['desc'] report.ward = Ward.objects.get(geom__contains=pnt) report.save() update = update_form.save(commit=False) update.report = report update.ip = utils.get_client_ip(request) update.first_update = True update.created_at = report.created_at update.save() return HttpResponseRedirect(report.get_absolute_url()) # other form errors are handled by the form objects. if not request.POST['category_id']: category_error = _("Please select a category") else: return HttpResponseRedirect('/') return render_to_response("reports/new.html", {"lat": pnt.y, "lon": pnt.x, "city": city, "google": FixMyStreetMap(pnt, True), "title": title, "street": street, "author": author, "email": email, "phone": phone, "update_form": update_form, "report_form": report_form, "categories": ReportCategory.objects.all().order_by("category_class"), "category_error": category_error, "form_error": form_error}, context_instance=RequestContext(request))