Beispiel #1
0
def update(request, id = None):
	instance = None
	if id is not None:
		instance = Usuario.objects.get(id = id)
	if request.method == 'POST':
		form = UsuarioForm(request.POST, instance = instance)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/usuarios')
	else:
		form = UsuarioForm(instance = instance)
	return render_to_response('common/detail.html',{'form':form})
Beispiel #2
0
def login(request, id = None):
	request.session['user_id'] = None
	if request.method == 'POST':
		form = UsuarioForm(request.POST)
		request.session['user_id'] = None
		if form.is_valid():
			attempt = form.save(commit = False)
			try:
				coincident = Usuario.objects.get(nombre = attempt.nombre)
			except Exception:
				coincident = None
			if coincident:
				if (coincident.contrasena == attempt.contrasena):
					request.session['user_id'] = coincident.id
				else:
					return HttpResponse('Contrasena incorrecta')
			else:
				return HttpResponse('Usuario no registrado.')
	else:
		form = UsuarioForm()
	login_attempt = True
	return render_to_response('guardian/index.html',{'form':form, 'login_attempt':login_attempt}, context_instance = RequestContext(request))