def find_by_username(cls, username): key = 'csr_detail_%s' % username if cache.get(key): return cache.get(key) csr = CSR.query.filter(CSR.deleted.is_(None)).filter_by(username=username.split("idir/")[-1]).first() cache.set(key, csr) return csr
def find_by_userid(cls, userid): csr = CSR.query.filter( CSR.deleted.is_(None)).filter_by(csr_id=userid).first() key = (CSR.format_string % csr.username).lower() if cache.get(key): return cache.get(key) cache.set(key, csr) return csr
def find_by_username(cls, username): idir_id = username.split("idir/")[-1] key = (CSR.format_string % idir_id).lower() if cache.get(key): return cache.get(key) csr = CSR.query.filter( CSR.deleted.is_(None)).filter_by(username=idir_id).first() cache.set(key, csr) return csr
def build_cache(cls): """Build cache.""" try: all_offices = cls.query.all() for office in all_offices: key = Office.format_string % office.office_id office.timeslots office.timezone cache.set(key, office) except Exception: print('Error on building cache')
def update_user_cache(cls, userid): try: if type(userid) is str: userid = int(userid) csr_db = CSR.query.filter_by(csr_id=userid).first() key = (CSR.format_string % csr_db.username).lower() cache.set(key, csr_db) except Exception as ex: print("==> csr.py, update_user_cache, userid: " + str(userid) + "; type: " + str(type(userid))) print(" --> Exception: " + str(ex))
def get_all_active_offices(cls): """Return all active offices.""" from app.schemas.theq import OfficeSchema active_offices = cache.get(Office.offices_cache_key) if not active_offices: office_schema = OfficeSchema(many=True) active_offices = office_schema.dump( Office.query.filter(Office.deleted.is_(None))) cache.set(Office.offices_cache_key, active_offices) return active_offices
def find_by_username(cls, username): # Possible keycloak->TheQ id values are user@idir->user, idir/user->user or user@bceid->user@bceid idir_id = username.split("idir/")[-1].lower() if "@idir" in username: idir_id = username.split("@idir")[0].lower() key = CSR.format_string % idir_id if cache.get(key): return cache.get(key) csr = CSR.query.filter( CSR.deleted.is_(None)).filter(CSR.username == idir_id).first() cache.set(key, csr) return csr
def update_user_cache(cls, userid): csr_db = CSR.query.filter_by(csr_id=userid).first() key = (CSR.format_string % csr_db.username).lower() cache.set(key, csr_db)