def get_sales_rep_name(id): try: with tb_loader() as l: reps = l.query(SalesReps).filter(SalesReps.id == id).one() return reps.sfdc_alias except NoResultFound as e: return 'loggly'
def get_sales_rep_id(name): repname = '%' + name + '%' try: with tb_loader() as l: reps = l.query(SalesReps).filter( SalesReps.sfdc_alias.like(repname)).one() return reps.id except NoResultFound as e: return 1
def touchbiz_rows(self): with tb_loader() as l: items = l.query( Touchbiz )\ .order_by( Touchbiz.acct_id, Touchbiz.created )\ .all() #Make a dictionary keyed by acct_id acct_rows = defaultdict(list) for row in items: acct_rows[row.acct_id].append(row) return dict(acct_rows)
def get_sales_rep_details(name): repname = '%' + name + '%' with tb_loader() as l: try: reps = l.query(SalesReps.first, SalesReps.last, SalesReps.sfdc_alias, SalesReps.id).filter( or_(SalesReps.last.like(repname), SalesReps.first.like(repname))).limit(10) return reps except NoResultFound as e: return None
def initial_touchbiz_entry(): epoch_start = datetime(1970, 1, 1) with tb_loader() as l: company = l.query( SalesReps )\ .filter( SalesReps.email == config.get( 'touchbiz', 'company_user' ) )\ .one() initial = Touchbiz( created=epoch_start, modified=epoch_start, ) initial.owner = company return initial
def touchbiz_by_account_id(acct_id, localize=True): """ Munges subscription changes with our touchbiz entries""" with a2_loader() as l: sub_entries = l.query( AccountStateUncompressed )\ .filter( AccountStateUncompressed.acct_id == acct_id )\ .all() with tb_loader() as l: tb_entries = l.query( Touchbiz )\ .filter( Touchbiz.acct_id == acct_id )\ .all() return apply_touchbiz(sub_entries, tb_entries, initial_entry=initial_touchbiz_entry(), localize=localize)
def owner_id(email): with tb_loader() as l: return l.query(SalesReps).filter(SalesReps.email == email).one().id
def tbrows_by_acct_id(acct_id): with tb_loader() as l: tb_entries = l.query( Touchbiz )\ .filter( Touchbiz.acct_id == acct_id )\ .all() return tb_entries