ok, i tried to minimalized the scope (start from simple scratch)
*1. copy welcome scaffolding app*
cp -R ~/site/web2py/applications/welcome/ ~/site/web2py/applications/z
*2. Run Web2py with profiler*
source ~/site/bin/activate
python ~/site/web2py/web2py.py --nogui --no-banner -a 'a' -i 0.0.0.0 -p 
8000 -F ~/Downloads/profiler
*3. modified models/db.py (put in the bottom the code in example 1 above)*
def login_onfail(form):
    username = request.vars.username
    row = db((db.auth_user.username == username ) ).iterselect(cache = 
cache_db, 
                                                               cacheable = 
True).first()
    if row is not None:
        db.auth_event.insert(time_stamp = request.now, 
                             client_ip = request.client, 
                             user_id = id, 
                             origin = '%s/%s' % (request.controller, 
request.function), 
                             description = '%s login failed' % (username) )

auth.settings.login_onfail.append(login_onfail)
*4. create new file models/db_schema_1_person.py (to eliminate another code 
i make a new file that contain code in example 2 above)*
# -*- coding: utf-8 -*-

def before_insert_person(f):
    if f['auth_user']:
        query_auth_user = (db.auth_user.id == f['auth_user'] )
        row_auth_user = db(query_auth_user).iterselect(cache = (cache.ram, 
3600), 
                                                       cacheable = 
True).first()
        f['username'] = row_auth_user.username
        f['first_name'] = row_auth_user.first_name
        f['last_name'] = row_auth_user.last_name
        f['email'] = row_auth_user.email

def on_define_person(table): 
    table._before_insert.append(before_insert_person)

db.define_table('person', 
    Field('is_auth', 'boolean'),
    Field('auth_user', 'reference auth_user'), 
    Field('username'), 
    Field('first_name'), 
    Field('last_name'), 
    Field('email', 'list:string'), 
    on_define = on_define_person, 
    format = lambda r: '%s %s' % (r.first_name, r.last_name) )
*5. Remove profiled files from previous to make easiest to see the current 
one running*
rm -rf ~/Downloads/profiler/*
*6. Go to new web2py app using browser : http://127.0.0.1:8000/z*
*7. Run snakeviz*
source ~/site/bin/activate
snakeviz ~/Downloads/profiler/req_uuid.prof
*8. Snakeviz result in models side :*
*filename:lineno(funtion)*
*db.py:8(<module>)*
*db_schema_1_person.py:13(on_define_person)*
*db_schema_1_person.py:3(<module>)*

explain db.py:8 is about, (the default scaffolding app)
if request.global_settings.web2py_version < "2.14.1":
    raise HTTP(500, "Requires web2py 2.13.3 or newer")

db_schema_1_person.py:13(on_define_person), no question in here either

db_schema_1_person.py:3(<module>)
*question*
why the same callback function (comparing login_onfail (not executed) and 
before_insert_person (executed) ) ?
as you see in my step above, i just trying to hit http://127.0.0.1:8000/z, 
no trying to login or insert the new record of table person

*another question is about validator*
e.g.
requires_person = IS_IN_DB(db, db.person.id, db.person._format)

the above code works when put in models and controllers, why i can't put it 
on modules, it's return an error, is there any way to put it on modules 
using web2py way?
*modules/test_field_constructor.py*
requires_person = IS_IN_DB(current.db, current.db.person.id, 
current.db.person._format)* # return an error*

thanks and best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to