当前位置: 首页>>代码示例>>Python>>正文


Python Model.get_user_fromext方法代码示例

本文整理汇总了Python中obelisk.model.Model.get_user_fromext方法的典型用法代码示例。如果您正苦于以下问题:Python Model.get_user_fromext方法的具体用法?Python Model.get_user_fromext怎么用?Python Model.get_user_fromext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在obelisk.model.Model的用法示例。


在下文中一共展示了Model.get_user_fromext方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_user

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import get_user_fromext [as 别名]
    def render_user(self, user_ext, request):
	model = Model()
	peer = model.query(SipPeer).filter_by(regexten=user_ext).first()
	creditlink = ''
	if peer:
		username = peer.name
	else:
		username = user_ext
	user = model.get_user_fromext(user_ext)
	logged = session.get_user(request)
	if user:
		credit = "%.3f" % (user.credit,)
		user_charges = charges.get_charges(user_ext)
		n_calls = len(user.calls)
		pager = self.render_pager(user_ext, n_calls)
		user_calls = calls.get_calls(user_ext, logged, 10) + "<p>%s</p>" % (pager,)

		creditlink = ""
		if user.credit > 0:
			if user.voip_id == logged.voip_id:
				creditlink += '<a href="/credit/transfer">Transferir</a>'
			else:
				creditlink += '<a href="/credit/transfer/%s">Transferir</a>' % (user.voip_id)
		if logged.admin:
			creditlink += ' <a href="/credit/add/%s">Crear</a>' % (user.voip_id)
	else:
		credit = 0.0
		user_charges = ""
		user_calls = ""
	all_calls = self.render_user_calls(user_ext, request)
	args = {'ext': user_ext, 'username': username, 'credit': credit, 'credit_link':creditlink ,'calls': user_calls, 'charges': user_charges, 'all_calls': all_calls}
	return print_template('user-pbx-lorea', args)
开发者ID:guyt101z,项目名称:rtcheckcalls,代码行数:34,代码来源:user.py

示例2: get_charges

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import get_user_fromext [as 别名]
def get_charges(user_ext):
	model = Model()
	user = model.get_user_fromext(user_ext)

	res = ""
	for charge in user.charges:
		date = charge.timestamp
		credit = charge.credit
		if charge.concept:
			concept = charge.concept
		else:
			concept = ''
		res += "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (date, credit,concept)
	return res
开发者ID:guyt101z,项目名称:rtcheckcalls,代码行数:16,代码来源:charges.py

示例3: add_charge

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import get_user_fromext [as 别名]
def add_charge(user_ext, amount, concept=""):
	model = Model()
	user = model.get_user_fromext(user_ext)
	if not user:
		user = User(user_ext)
		model.session.add(user)

	if concept:
		charge = Charge(user=user, timestamp=datetime.now(), credit=amount, concept=concept)
	else:
		charge = Charge(user=user, timestamp=datetime.now(), credit=amount)
	model.session.add(charge)
	
	model.session.commit()
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:16,代码来源:charges.py

示例4: add_charge

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import get_user_fromext [as 别名]
def add_charge(logged, user_ext, amount, concept=""):
	model = Model()
	user = model.get_user_fromext(user_ext)
        initiator_id = logged.id
	if not user:
		user = User(user_ext)
		model.session.add(user)

	if concept:
		charge = Charge(user=user, timestamp=datetime.now(), credit=amount, concept=concept, initiator_id=initiator_id, funded=True)
	else:
		charge = Charge(user=user, timestamp=datetime.now(), credit=amount, initiator_id=initiator_id, funded=True)
	model.session.add(charge)
	
	model.session.commit()
开发者ID:guyt101z,项目名称:rtcheckcalls,代码行数:17,代码来源:charges.py

示例5: add_call

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import get_user_fromext [as 别名]
def add_call(user_ext, destination, date, real_duration, duration, cost, rate, provider_name):
	model = Model()
	user = model.get_user_fromext(user_ext)
	provider = model.query(Provider).filter_by(name=provider_name).first()
	if not provider:
		provider = Provider(provider_name)
		model.session.add(provider)
		model.session.commit()
	call = Call(user=user,
			destination=destination,
			timestamp=datetime.fromtimestamp(float(date)),
			duration=real_duration,
			charged=duration,
			cost=cost,
			rate=rate,
			provider=provider)

	model.session.add(call)
	model.session.commit()
开发者ID:hungld,项目名称:rtcheckcalls,代码行数:21,代码来源:calls.py

示例6: login

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import get_user_fromext [as 别名]
    def login(self, login, password, request, email=''):
	peer = self.check_password(login, password)
	if peer:
		user_ext = peer.regexten
		model = Model()
		user = model.get_user_fromext(user_ext)
		if not user:
			user = User(user_ext)
			if email:
				user.email = email
			model.session.add(user)
			model.session.commit()
		session_id = str(request.getSession().uid)
		web_session = model.query(WebSession).filter_by(session_id=session_id).first()
		if not web_session:
			web_session = WebSession(session_id=session_id, timestamp=datetime.now(), user=user)

		model.session.add(web_session)
		model.session.commit()
		return redirectTo("/user/"+user_ext, request)
	return redirectTo("/", request)
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:23,代码来源:login.py

示例7: get_calls

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import get_user_fromext [as 别名]
def get_calls(user_ext, logged, limit=0, offset=0, format='html'):
	model = Model()
	user = model.get_user_fromext(user_ext)
	if not user:
		return ""

	if format == 'html':
		res = ""
	else:
		res = []
	all_calls = user.calls
	last = len(all_calls)
	if limit and len(user.calls) > limit + offset:
		all_calls = user.calls[last-offset-limit:last-offset]
	for call in all_calls:
		destination = call.destination
		date = call.timestamp
		duration = call.duration
		duration = "%sm %ss" % (duration/60, duration%60)
		cost = call.cost
		rate = call.rate
		if call.provider:
			provider = call.provider.name
		else:
			provider = 'unknown'
		pars = [date, destination, duration, cost, rate]
		if logged and logged.admin:
			pars.append(provider)
			if format == 'html':
				res = ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%.3f</td><td>%.3f</td><td>%s</td></tr>\n" % tuple(pars)) + res
		else:
			if format == 'html':
				res = ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%.3f</td><td>%.3f</td></tr>\n" % tuple(pars)) + res
		if format == 'json':
			pars[0] = str(pars[0])
			pars[3] = float(pars[3])
			pars[4] = float(pars[4])
			res = [pars] + res
	return res
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:41,代码来源:calls.py

示例8: get_calls

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import get_user_fromext [as 别名]
def get_calls(user_ext, logged):
	model = Model()
	user = model.get_user_fromext(user_ext)
	if not user:
		return ""

	res = ""
	for call in user.calls:
		destination = call.destination
		date = call.timestamp
		duration = call.duration
		duration = "%sm %ss" % (duration/60, duration%60)
		cost = call.cost
		rate = call.rate
		if call.provider:
			provider = call.provider.name
		else:
			provider = 'unknown'
		if logged and logged.admin:
			res = ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%.3f</td><td>%.3f</td><td>%s</td></tr>\n" % (date, destination, duration, cost, rate, provider)) + res
		else:
			res = ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%.3f</td><td>%.3f</td></tr>\n" % (date, destination, duration, cost, rate)) + res

	return res
开发者ID:hungld,项目名称:rtcheckcalls,代码行数:26,代码来源:calls.py

示例9: Accounting

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import get_user_fromext [as 别名]
class Accounting(object):
	def __init__(self):
		self.model = Model()

	def get_data(self):
		data = {}
		users = self.model.query(User)
		for user in users:
			if user.credit:
				data[user.voip_id] = user.credit
		return data

	def get_credit(self, user_ext):
		user = self.model.get_user_fromext(user_ext)
		if user:
			return user.credit
		else:
			return Decimal()

	def reset_credit(self, user_ext):
		user = self.model.get_user_fromext(user_ext)
		user.credit = Decimal()
		self.model.session.commit()
		self.update_user_context(user)

	def update_user_context(self, user):
		peer = self.model.query(SipPeer).filter_by(regexten=user.voip_id).first()
		if not peer:
			# old user
			print "user unavailable to update context", user.voip_id
			return
		if user.credit > Decimal(0.0) and peer.context == "from-freeuser":
			peer.context = "from-payuser"
			self.model.session.commit()
			reload_peer(peer.name)
		elif user.credit <= Decimal(0.0) and peer.context == "from-payuser":
			peer.context = "from-freeuser"
			self.model.session.commit()
			reload_peer(peer.name)

	def get_user_for_credit(self, user_ext):
		user = self.model.get_user_fromext(user_ext)
		if not user:
			# check at least user exists as asterisk user
			peer = self.model.query(SipPeer).filter_by(regexten=user_ext).first()
			if not peer:
				# check by name
				peer = self.model.query(SipPeer).filter_by(name=user_ext).first()
				if not peer:
					return
				else:
					user =  self.model.get_user_fromext(peer.regexten)
			if not user:
				user = User(peer.regexten)
				self.model.session.add(user)
		return user
	
	def transfer_credit(self, logged, user_ext, credit):
		from obelisk.resources import sse
		if not (credit > 0.0 and logged.credit >= credit):
			return
		user = self.get_user_for_credit(user_ext)
		if not user:
			return
		logged.credit -= Decimal(credit)
		user.credit += Decimal(credit)
		self.model.session.commit()
		self.update_user_context(user)
		self.update_user_context(logged)
		charges.add_charge(user.voip_id, credit, 'transferencia de ' + logged.voip_id)
		charges.add_charge(logged.voip_id, -credit, 'transferencia a ' + user.voip_id)
		sse.resource.notify({'credit': float(user.credit), 'user': user.voip_id}, "credit", user)
		sse.resource.notify({'credit': float(logged.credit), 'user': logged.voip_id}, "credit", logged)
	
	def add_credit(self, user_ext, credit, reason=""):
		from obelisk.resources import sse
		user = self.get_user_for_credit(user_ext)
		if not user:
			return
		user.credit += Decimal(credit)
		self.model.session.commit()
		self.update_user_context(user)
		charges.add_charge(user.voip_id, credit, reason)
		sse.resource.notify({'credit':float(user.credit), 'user':user.voip_id}, "credit", user)
		return user.voip_id

	def remove_credit(self, user_ext, credit):
		user = self.model.get_user_fromext(user_ext)
		if not user:
			return

		user.credit -= Decimal(credit)
		self.model.session.commit()
		self.update_user_context(user)
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:96,代码来源:accounting.py


注:本文中的obelisk.model.Model.get_user_fromext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。