示例#1
0
文件: views.py 项目: job-s/n-mat
def registrar_usuario(request):
    if request.POST:
        f=RegistrationForm(request.POST)
        if f.errors:
            messages.error(request, 'El formulario contiene errores')
            return render_to_response("registro_caja.html", {'form':f}, RequestContext(request))
        else:
            data = f.cleaned_data
            user=User()
            user.username=data["username"]
            passwd=get_pronounceable_password(1,2)
            user.set_password(passwd)
            user.email = data['email']
            user.first_name = data['first_name']
            user.last_name = data['last_name']
            user.save()

            profile = Profile()
            profile.user=user
            profile.telefono = data['phone_number']
            profile.celular = data['cellphone']
            profile.direccion = data['address']
            profile.tipo = CLIENTE
            profile.save()
            
            messages.success(request, 'Usuario creado con exito')

            return render_to_response('mostrar_usuario.html', {'user':user,'passwd':passwd}, RequestContext(request))

    else:
        f=RegistrationForm()

    return render_to_response("registro_caja.html", {'form':f}, RequestContext(request))