Gostaria de pedir ajuda dos colegas para uma questão quanto a importação de módulos. Baixei o tutorial do Bruno no youtube e estou tentando aprender um pouco mais sobre o web2py, só que na aula 10 tem a criação do modulo barcode e a importação nos validators. Nos validators se chego com o cursor em cima da chamada da função ele mostra o caminho corretamente mas na hora de executar diz que não encontrou o módulo. Já inseri o __init__.py nas pastas e também não resolveu.
- windows 10 64 bits
- python 2.7.13
- web2py src ultima versão
na pasta modules: customvalidators.py e __init__.py
na pasta models : validators.py
### customvalidators.py
from gluon import *
class IS_VALID_BARCODE(object):
"""docstring for IS_VALID_BARCODE"""
def __init__(self, start_with="", error_message="INVALID BARCOD"):
self.error_message=error_message
self.start_with = start_with
def __call__(self, value): #funcao execultada no submit
error = None
#startswith "funcao do python"
if not value.startswith(self.start_with):
return (value, self.error_message)
else:
return (value, None)
class VALIDATOR(object):
def __init__(self, error_message="SOMETHING WRONG"):
self.error_message = error_message
def __call__(self, value):
error = None
# CONDITION COMES HERE
if "ERROR":
error = self.error_message
# IF error != None - value is invalid
return (value, error)
class TRANSFORMATION(object):
def __init__(self, search, replace):
self.search = search
self.replace = replace
def __call__(self, value):
error = None
try:
# TRANSFORMATION COMES HERE
value = value.replace(self.search, self.replace)
except:
error = "Not possible to transform"
return (value, error)
class IS_ALLOWED_ZIP_CODE(object):
def __init__(self, zip_area, error_message="Zip code not allowed"):
self.zip_area = zip_ares
self.error_message = error_message
def __call__(self, value):
error = None
value = value.strip()
if not value.startswith(self.zip_area):
error = self.error_message
return (value, error)
class REPLACE_TEXT(object):
def __init__(self, search, replace):
self.search = str(search)
self.replace = str(replace)
def __call__(self, value):
error = None
try:
value = value.replace(self.search, self.replace)
except:
error = "Error replacing"
return (value, error)
### validators.py
from customvalidators import IS_VALID_BARCODE
db.product.description.requires = \
IS_NOT_EMPTY(error_message="Insira uma descrição")
db.product.barcode.requires = \
[
IS_NOT_EMPTY(error_message="Insira Barcode"),
IS_VALID_BARCODE("987", T("Barcode Invalid"))
]
### Erro
<type 'exceptions.ImportError'> No module named customvalidators
Versão
web2py™ |
Version 2.14.6-stable+timestamp.2016.05.10.00.21.47 |
Python |
Python 2.7.13: C:\Python27\python.exe (prefix: C:\Python27) |
Traceback
1. 2. 3. 4. 5. 6. 7. 8. 9. | Traceback (most recent call last): File "D:\Biblioteca\GoogleDrive\Programa��o\web2pysrc\gluon\restricted.py", line 227, in restricted exec ccode in environment File "D:/Biblioteca/GoogleDrive/Programa��o/web2pysrc/applications/ecommerce/models/validators.py", line 5, in <module> from customvalidators import IS_VALID_BARCODE File "D:\Biblioteca\GoogleDrive\Programa��o\web2pysrc\gluon\custom_import.py", line 95, in custom_importer return base_importer(pname, globals, locals, fromlist, level) ImportError: No module named customvalidators
|
Momento do Erro
<type 'exceptions.ImportError'>(No module named customvalidators)
Desde já agradeço