def agregar_alumno(request): if request.method == 'POST': form = AlumnoForm(request.POST) if form.is_valid(): form.save() return redirect('/dash/') else: render(request, 'agregar_alumno.html', {'form': form}) else: form = AlumnoForm() return render(request, 'agregar_alumno.html', {'form': form})
def vista_inscripcion(request): vista = 'Inscripcion de alumnos' #el nombre de la pagina en la que nos encontramos if request.method == 'POST': formulario =AlumnoForm(request.POST, request.FILES) if formulario.is_valid(): formulario.save() return HttpResponseRedirect('/alumnos/inscripcion') else: formulario = AlumnoForm() ctx ={'formulario': formulario , 'pagina':vista} return render_to_response ('alumnos/inscripcion.html',ctx,context_instance=RequestContext(request))
def crearAlumno(request): if request.user.tipoUsuario != 'admin': messages.warning(request, "Permisos de Administrador Requeridos") return redirect('inicio') else: alumnoForm = AlumnoForm() if request.method == 'POST': try: alumnoForm = AlumnoForm(request.POST, request.FILES) if alumnoForm.is_valid(): alumnoForm.save() messages.success(request, "Guardado Correctamente") return redirect('añadir-alumno') except: messages.warning(request, "Error al Guardar") return redirect('añadir-alumno') return render(request, 'crear-alumno.html', {'form': alumnoForm})
def editar_post(request): if request.POST.get('idEditar'): alumno = User.objects.get(id = request.POST.get('idEditar')) form = AlumnoForm(instance=alumno) else: alumno = User.objects.get(id = request.POST.get('id')) form = AlumnoForm(request.POST, instance=alumno) if form.is_valid(): alumno = form.save() alumno.save() return redirect('alumnos/listar') return render(request, 'alumnos/nuevoAlumno.html', {'form':form, 'id' : alumno.id, 'etiqueta': 'Actualizar'})
def nuevoA(request): if request.method == "POST": form = AlumnoForm(request.POST) if form.is_valid(): al = form.save() al.save() al.is_staff = True g = Group.objects.get(name='GroupAlum') g.user_set.add(al) return redirect('alumnos.views.login_view') else: form = AlumnoForm return render (request,'alumnos/nuevoAlumno.html',{'form':form, 'etiqueta':'Nuevo'})
def alumnos_save(request, id): print request.POST if request.method == "POST": provincia = Provincia.objects.get(pk = request.POST.get("provincia")) autoescuela = Autoescuela.objects.get(pk = 2) if id == "0": form = AlumnoForm(request.POST) form.save() else: alumno = Alumno.objects.get( pk = id ) alumno = AlumnoForm(request.POST, instance= alumno) alumno.save() # actualizando # autoescuela = Autoescuela.objects.get( pk = request.POST.get('pk') ) # AutoForm = AutoescuelaForm(request.POST, instance = autoescuela) # AutoForm.save() # insertando # user = User.objects.get(id=2) # autoescuela = Autoescuela(nombre= request.POST.get('nombre'), user = user) # autoescuela.save() # autoescuela = Autoescuela.objects.get( pk = request.POST.get('id') ) # autoescuela.nombre = request.POST.get('nombre') # autoescuela.save() return HttpResponse('Success')