def getUsers(self, sid): users = [] ep_stats = [] user = User.query.filter_by(session_id=sid).first() try: if user: context = user.get_context() else: raise Exception("No session id in db matching the user calling this method.") for r in db.execute("SELECT DISTINCT users.first_name, users.last_name, users.id, users.customer_id, " "customers.context AS context, users.portal_extension, " "users.tel, users.mobile, users.username, sip_dialogs.uuid AS uuid " "FROM users " "INNER JOIN customers ON users.customer_id = customers.id " "LEFT JOIN sip_dialogs ON sip_dialogs.presence_id = users.portal_extension || '@' || customers.context " "WHERE customers.context = :context ORDER BY users.id", {'context': context}): for pbx_reg in PbxRegistration.query.filter(PbxRegistration.sip_realm==context).filter(PbxRegistration.sip_user==r[5]).all(): ep_stats.append({'ip': pbx_reg.network_ip, 'port':pbx_reg.network_port}) is_online = True if len(ep_stats) > 0 else False ep_stats = [] # make_broker_user(name, id, customer_id, email, tel, mobile, ext, uuid, is_online): users.append(make_broker_user(r[0]+' '+r[1], r[2], r[3], r[8], r[6], r[7], r[5], r[9], is_online)) db.remove() return users except Exceptio, e: log.debug("Exception: %s" % e) return []
def getCallers(self, sid): callers = [] user = User.query.filter_by(session_id=sid).first() if user: context = user.get_context() for row in PbxDid.query.filter(PbxDid.context==context).all(): for cal in db.execute("SELECT * FROM channels WHERE dest like :did", {'did': "%"+row.did}).fetchall(): #PbxChannel.query.filter(PbxChannel.dest.like('%'+row.did).all(): l = PbxChannel.query.filter_by(uuid=cal.uuid).first() if l: to_user = l.dest status = l.callstate else: to_user = "" status = "" direction = "inbound" if len(cal.cid_num) > 10: cid_num = cal.cid_num[len(cal.cid_num)-10:] else: cid_num = cal.cid_num time_in_queue = db.execute("SELECT now() FROM channels WHERE uuid = :uuid", {'uuid': cal.uuid}).fetchone() callers.append(make_caller(cal.dest, cal.cid_name,cid_num, direction, cal.created, time_in_queue[0], to_user, cal.uuid, status)) for cal in PbxChannel.query.filter_by(context=context).distinct(PbxChannel.call_uuid).all(): if len(cal.presence_id)>3: if cal.presence_id.split("@")[1] == context: time_in_queue = db.execute("SELECT now() FROM channels WHERE uuid = :uuid", {'uuid': cal.uuid}).fetchone() callers.append(make_caller(cal.dest, cal.cid_name, cal.cid_num, "outbound", cal.created, "", cal.dest, cal.uuid, cal.callstate)) db.remove() return callers
def __call__(self, environ, start_response): """Invoke the Controller""" # WSGIController.__call__ dispatches to the Controller method # the request is routed to. This routing information is # available in environ['pylons.routes_dict'] try: return WSGIController.__call__(self, environ, start_response) finally: db.remove()
def get_talk_time(ext, context): rows = db.execute("SELECT coalesce(sum(billsec)/60,0) AS mins FROM cdr " "WHERE (caller_id_number=:ext OR destination_number=:ext) " "AND start_stamp BETWEEN CURRENT_DATE AND CURRENT_TIMESTAMP " "AND bleg_uuid IS NOT NULL AND context = :context", {'ext':ext, 'context': context}) r = rows.fetchone() db.remove() return r.mins
def get_volume(ext, context): rows = db.execute("SELECT count(*) AS ct " "FROM cdr " "WHERE (caller_id_number=:ext OR destination_number=:ext) " "AND start_stamp BETWEEN CURRENT_DATE " "AND CURRENT_TIMESTAMP AND bleg_uuid IS NOT NULL " "AND context = :context", {'ext':ext, 'context': context}) r = rows.fetchone() db.remove() return r.ct
def billing_service_types(self): items=[] try: for billing_servicde_type in BillingServiceType.query.all(): items.append({'id': billing_servicde_type.id, 'name': billing_servicde_type.name, 'description': billing_servicde_type.description}) db.remove() return {'identifier': 'id', 'label': 'name', 'items': items} except Exception, e: return {'identifier': 'id', 'label': 'name', 'items': items, 'is_error': True, 'message': str(e)}
def campaigns_ids(self): names=[] ids=[] try: for row in CrmCampaign.query.filter(context=session['context']).all(): names.append(row.name) ids.append(row.id) db.remove() return {'names': names, 'ids': ids} except Exception, e: return {'names': names, 'ids': ids, 'is_error': True, 'message': str(e)}
def get_route_labels_ids(): route_labels = [] route_ids = [] for row in db.execute("SELECT sr.id, srt.name|| ':' ||sr.name AS name " "FROM pbx_routes sr " "INNER JOIN pbx_route_types srt ON sr.pbx_route_type_id = srt.id " "WHERE sr.context = :context", {'context': session['context']}): route_labels.append(row.name) route_ids.append(row.id) db.remove() return (route_labels,route_ids)
def get_route_labels_ids(): route_labels = [] route_ids = [] for row in db.execute( "SELECT sr.id, srt.name|| ':' ||sr.name AS name " "FROM pbx_routes sr " "INNER JOIN pbx_route_types srt ON sr.pbx_route_type_id = srt.id " "WHERE sr.context = :context", {'context': session['context']}): route_labels.append(row.name) route_ids.append(row.id) db.remove() return (route_labels, route_ids)
def campaigns(self): items=[] members = [] try: for campaign in CrmCampaign.query.filter(context=session['context']).all(): for member in CrmGroupMember.query.join(CrmGroup).join(CrmCampaignGroup).filter(CrmCampaignGroup.crm_campaign_id==campaign.id).all(): members.append(member.extension) items.append({'id': campaign.id, 'name': campaign.name, 'members': ",".join(members)}) members = [] db.remove() return {'identifier': 'id', 'label': 'name', 'items': items} except Exception, e: return {'identifier': 'id', 'label': 'name', 'items': items}
def getAgents(self, sid): agents = [] user = User.query.filter_by(session_id=sid).first() if user: context = user.get_context() else: raise Exception("No user in session...") for row in User.query.filter(User.customer_id==user.customer_id).all(): if not len(row.portal_extension): continue else: extension = row.portal_extension agent = make_agent(row.first_name+' '+row.last_name, get_volume(extension, context), get_talk_time(extension, context)) agents.append(agent) db.remove() return agents
def billing_service_types(self): items = [] try: for billing_servicde_type in BillingServiceType.query.all(): items.append({ 'id': billing_servicde_type.id, 'name': billing_servicde_type.name, 'description': billing_servicde_type.description }) db.remove() return {'identifier': 'id', 'label': 'name', 'items': items} except Exception, e: return { 'identifier': 'id', 'label': 'name', 'items': items, 'is_error': True, 'message': str(e) }
def get_context(self): context = PbxContext.query.filter(PbxContext.customer_id==session['customer_id']).first() db.remove() return context.context
def get_context(self): context = PbxContext.query.filter( PbxContext.customer_id == session['customer_id']).first() db.remove() return context.context