def delete(request): if not request.user.is_authenticated(): return render_to_response('vlogin.html', {}, context_instance=RequestContext(request)) id = eval("request." + request.method + "['id']") if request.method == 'POST': veiculo = Veiculo.objects(id=id)[0] veiculo.delete() template = 'index.html' params = {'Veiculos': Veiculo.objects} elif request.method == 'GET': template = 'delete.html' params = {'id':id} return render_to_response(template, params, context_instance=RequestContext(request))
def update(request): if not request.user.is_authenticated(): return render_to_response('vlogin.html', {}, context_instance=RequestContext(request)) id = eval("request." + request.method + "['id']") veiculo = Veiculo.objects(id=id)[0] if request.method == 'POST': veiculo.ano = request.POST['ano'] veiculo.fabricante = request.POST['fabricante'] veiculo.modelo = request.POST['modelo'] foto = request.FILES.get('foto') if foto: veiculo.foto.replace(foto) veiculo.save() template = 'index.html' params = {'Veiculos': Veiculo.objects} elif request.method == 'GET': template = 'update.html' params = {'veiculo':veiculo} return render_to_response(template, params, context_instance=RequestContext(request))