Beispiel #1
0
 def save_data(self, f, datos):
     data = {}
     if f.is_valid():
         use = User()
         use.username = datos['cedula']
         use.cedula = datos['cedula']
         use.first_name = datos['first_name']
         use.last_name = datos['last_name']
         use.sexo = datos['sexo']
         use.email = datos['email']
         use.telefono = datos['telefono']
         use.celular = datos['celular']
         use.direccion = datos['direccion']
         use.tipo = 0
         use.password = make_password(datos['cedula'])
         use.save()
         data['resp'] = True
         data['cliente'] = use.toJSON()
         grupo = Group.objects.get(name__icontains='cliente')
         usersave = User.objects.get(id=use.id)
         usersave.groups.add(grupo)
         usersave.save()
     else:
         data['error'] = f.errors
     return data
Beispiel #2
0
def cliente_add(request):
    data = {}
    f = UserForm_cliente(request.POST)
    datos = request.POST
    if f.is_valid():
        with transaction.atomic():
            if verificar(f.data['cedula']):
                use = User()
                use.username = datos['cedula']
                use.cedula = datos['cedula']
                use.first_name = datos['first_name']
                use.last_name = datos['last_name']
                use.sexo = datos['sexo']
                use.email = datos['email']
                use.telefono = datos['telefono']
                use.celular = datos['celular']
                use.direccion = datos['direccion']
                use.tipo = 0
                use.password = make_password(datos['cedula'])
                use.save()
                permission = Permission.objects.get(codename='add_venta')
                permission2 = Permission.objects.get(codename='view_venta')
                use.user_permissions.add(permission)
                use.user_permissions.add(permission2)
                # venta.add_venta

                # u.user_permissions.add(permission)
                data['resp'] = 'error'
            else:
                f.add_error("cedula",
                            "Numero de Cedula no valido para Ecuador")
                data['error'] = f.errors
    else:
        data['error'] = f.errors
    return HttpResponse(json.dumps(data), content_type="application/json")