I use decorator for reduce count of sql queries for logged in users like 
that:
def is_info(fun):
    def decorated():
        if session.is_info is None:
            entrant = db(db.a_persons.WEB_ID == auth.user_id).select(
                db.a_persons.FILE_CODE0, db.a_persons.F, db.a_persons.I, 
db.a_persons.O, db.a_persons.id,
                db.a_persons.BIRTHDAY, db.a_persons.GENDER, 
db.a_persons.BIRTHPLACE, db.a_persons.GRADUATION_LEVEL,
                db.a_persons.COUNTRY, db.a_persons.REGION, 
db.a_persons.ADR_INDEX, db.a_persons.ADR_DISTRICT,
                db.a_persons.ADR_LOC_TYPE, db.a_persons.ADR_TOWN, 
db.a_persons.ADR_STREET_TYPE, db.a_persons.ADR_STREET,
                db.a_persons.ADR_HOUSE, db.a_persons.ADR_BUILDING, 
db.a_persons.ADR_FLAT, db.a_persons.PHONE,
                db.a_persons.NEED_HOSTEL, db.a_persons.PREP_COURSE, 
db.a_persons.ARMY, db.a_persons.EXTRA,
                db.a_persons.WORK_EXP, db.a_persons.PASS_ID, 
db.a_persons.GRADUATION_YEAR, db.a_persons.EDU_REGION,
                db.a_persons.LANGUAGE).first()
            if entrant is None:
                redirect(URL('user', 'index', args=['logout']))        
            session.is_info = True
            session.myvar = auth.user_id
            session.is_info = True
            session.file_code = entrant.FILE_CODE0
            session.middle_name = entrant.O
            session.entrant_id = entrant.id
            session.birthday = entrant.BIRTHDAY
            session.sex = entrant.GENDER
            session.birthplace = entrant.BIRTHPLACE
            session.country = entrant.COUNTRY
            session.region = entrant.REGION
            session.adr_index = entrant.ADR_INDEX
            session.adr_district = entrant.ADR_DISTRICT
            session.adr_loc_type = entrant.ADR_LOC_TYPE
            session.adr_town = entrant.ADR_TOWN
            session.adr_street_type = entrant.ADR_STREET_TYPE
            session.adr_street = entrant.ADR_STREET
            session.adr_house = entrant.ADR_HOUSE
            session.adr_building = entrant.ADR_BUILDING
            session.adr_flat = entrant.ADR_FLAT
            session.phone = entrant.PHONE
            session.need_hostel = entrant.NEED_HOSTEL
            session.prep_course = entrant.PREP_COURSE
            session.army = entrant.ARMY
            session.extra = entrant.EXTRA
            session.work_exp = entrant.WORK_EXP
            session.pass_id = entrant.PASS_ID
            session.graduation_level = entrant.GRADUATION_LEVEL
            session.graduation_year = entrant.GRADUATION_YEAR
            session.edu_region = entrant.EDU_REGION
            session.language = entrant.LANGUAGE
            return fun()
        else:
            return fun()
    return decorated
As I understund after that decorator inside my function I check 
session.myvar and have None. I can't use auth.user_id inside decorator?
tables.py
db.define_table('a_persons', Field('FILE_CODE0', length=15), 
Field('WEB_ID', 'reference auth_user')
                # ...
)
Why I don't have error in query, becouse b.a_persons.WEB_ID == None? I have 
the first user information.
Web2py - 2.18.5-stable+timestamp.2019.04.08.04.22.03

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/5eaa71be-d785-4c92-960a-3e7da582d51bo%40googlegroups.com.

Reply via email to