def crime_update(request, latitude, longitude): crime_details = get_object_or_404(Crime, latitude=latitude, longitude=longitude) init_crime = { "latitude": crime_details.latitude, "longitude": crime_details.longitude, "crime_type": crime_details.crime_type, "criminals": crime_details.criminals, } if request.method == "POST": crime_update_form = CrimeUpdateForm(request.POST) valid_crime_update_form = crime_update_form.is_valid() if valid_crime_update_form: crime_form_details = crime_update_form.save(commit=False) update_c = Crime.objects.get(latitude=latitude, longitude=longitude) update_c.latitude = crime_form_details.latitude update_c.longitude = crime_form_details.longitude update_c.crime_type = crime_form_details.crime_type update_c.criminals = crime_form_details.criminals update_c.save() return HttpResponseRedirect("/crisis/") else: return render_to_response( "assessment/crime_update.html", {"crime_form": CrimeUpdateForm(init_crime)}, RequestContext(request) ) else: return render_to_response( "assessment/crime_update.html", {"crime_form": CrimeUpdateForm(init_crime)}, RequestContext(request) )
def crime_update(request, latitude, longitude): crime_details = get_object_or_404(Crime, latitude = latitude ,longitude = longitude) init_crime = { 'latitude' : crime_details.latitude , 'longitude' : crime_details.longitude, \ 'crime_type' : crime_details.crime_type, 'criminals' : crime_details.criminals } if request.method == 'POST': crime_update_form = CrimeUpdateForm(request.POST) valid_crime_update_form = crime_update_form.is_valid() if valid_crime_update_form: crime_form_details = crime_update_form.save(commit = False) update_c = Crime.objects.get(latitude = latitude, longitude = longitude) update_c.latitude = crime_form_details.latitude update_c.longitude = crime_form_details.longitude update_c.crime_type = crime_form_details.crime_type update_c.criminals = crime_form_details.criminals update_c.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('assessment/crime_update.html', { 'crime_form' : CrimeUpdateForm(init_crime)}\ , RequestContext(request)) else: return render_to_response('assessment/crime_update.html', { 'crime_form' : CrimeUpdateForm(init_crime)}\ , RequestContext(request))
def crime_update(request, latitude, longitude): crime_details = get_object_or_404(Crime, latitude=latitude, longitude=longitude) init_crime = { 'latitude' : crime_details.latitude , 'longitude' : crime_details.longitude, \ 'crime_type' : crime_details.crime_type, 'criminals' : crime_details.criminals } if request.method == 'POST': crime_update_form = CrimeUpdateForm(request.POST) valid_crime_update_form = crime_update_form.is_valid() if valid_crime_update_form: crime_form_details = crime_update_form.save(commit=False) update_c = Crime.objects.get(latitude=latitude, longitude=longitude) update_c.latitude = crime_form_details.latitude update_c.longitude = crime_form_details.longitude update_c.crime_type = crime_form_details.crime_type update_c.criminals = crime_form_details.criminals update_c.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('assessment/crime_update.html', { 'crime_form' : CrimeUpdateForm(init_crime)}\ , RequestContext(request)) else: return render_to_response('assessment/crime_update.html', { 'crime_form' : CrimeUpdateForm(init_crime)}\ , RequestContext(request))
def update(request, id, template_name='crime/update.html'): """ Update an existing crime report. """ crime = get_object_or_404(Crime, pk=id) if request.method == 'POST': form = CrimeUpdateForm(request.POST, instance=crime) if form.is_valid(): crime = form.save() return HttpResponseRedirect(reverse('crime-show', args=[crime.id])) elif request.method == 'GET': crime.password = "" form = CrimeUpdateForm(instance=crime) else: return HttpResponseRedirect(request.path) context = RequestContext(request, { 'crime': crime, 'form': form, }) return render_to_response(template_name, context)