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


Python Model.query方法代码示例

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


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

示例1: render_mailbox

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
    def render_mailbox(self, user_ext):
	output = "<h1>Correo de voz</h1>\n"
	model = Model()
	model.session.commit() # refresh session
	all_messages = model.query(VoiceMailMessage).filter_by(mailboxuser=user_ext)
	folders = set()
	for message in all_messages:
		folders.add(message.dir)
	folders = list(folders)
	folders.sort()
	for folder in folders:
		result = []
		messages = model.query(VoiceMailMessage).filter_by(mailboxuser=user_ext, dir=folder)
		output += "<h2>"+os.path.basename(folder)+"</h2>\n"
		for message in messages:
			actions2 = ""
			if message.msg_id:
				audio = html.format_audio('/voicemail/message/' + message.msg_id)
				actions = '<form method="POST" action="/voicemail/delete/%s/%s"><input type="hidden" name="msg_id" value="%s" /><input type="hidden" name="user_ext" value="%s" /><input type="submit" name="submit" value="Borrar" /></form>' % (user_ext, message.msg_id, message.msg_id, user_ext)
				if folder.endswith('INBOX'):
					actions2 += '<form method="POST" action="/voicemail/archive/%s/%s"><input type="hidden" name="msg_id" value="%s" /><input type="hidden" name="user_ext" value="%s" /><input type="submit" name="submit" value="Archivar" /></form>' % (user_ext, message.msg_id, message.msg_id, user_ext)
			else:
				audio = ""
				actions = ""
			result.append([message.callerid, time.ctime(message.origtime), str(message.duration), audio, actions, actions2])
		output += html.format_table([['origen', 'fecha', 'duracion', 'audio', 'actions', '']] + result)
	return output
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:29,代码来源:voicemail.py

示例2: __init__

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
    def __init__(self, id, cost, app_from, app_to):
	    self._id = id
	    self._callID = 0
            self._provider = 'unknown'
            if cost:
		    self._realcost = Decimal(cost)
	    else:
		    self._realcost = Decimal()
	    try:
		    self._cost = Decimal(cost)
		    if self._cost:
			    self._cost += Decimal(0.001) # benefit margin
	    except:
		    self._cost = Decimal(0.0)
	    self._from = app_from
	    self._to = app_to
	    self._real_to = app_to
	    model = Model()
	    peer = model.query(SipPeer).filter_by(regexten=self._from).first()
	    if peer:
		self._from = peer.name
		self._user = model.query(User).filter_by(voip_id=peer.regexten).first()
		self._from_exten = peer.regexten
	    else:
		self._user = None
		self._from_exten = ''
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:28,代码来源:rtcheckcalls.py

示例3: render_all

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
    def render_all(self, user_ext=None):
	"""
	Render calls for the given extensions.

	user_ext -- extension to render calls for.
	"""
	model = Model()
	result = {}
	result['dateTimeFormat'] = 'iso8601'
	result['wikiURL'] = 'http://simile.mit.edu/shelf/'
	result['wikiSection'] = 'Simile Cubism Timeline'
	result['events'] = []
	events = result['events']
	if user_ext:
		user = model.query(User).filter_by(voip_id=user).first()
		calls = model.query(Call).filter_by(user=user)
	else:
		calls = model.query(Call)
	for call in calls:
		if not call.user:
			print "call without user!", call
			continue
		event = {}
		event['start'] = self.format_date(call.timestamp)
		event['end'] = self.format_date(call.timestamp+datetime.timedelta(seconds=float(call.duration)))
		event['title'] = "from %s to %s" % (call.user.voip_id, call.destination)
		provider_name = self.get_provider_name(call.provider)
		event['description'] = "from %s to %s.<br/>duration: %.2fmin<br/>provider: %s" % (call.user.voip_id, call.destination, float(call.duration)/60.0, provider_name)
		event['color'] = self.get_color(call.provider)
	#	event['description'] = ""
#		event['image'] = ""
#		event['link'] = ""
		events.append(event)
        return json.dumps(result)
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:36,代码来源:calls.py

示例4: change_options

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
def change_options(user_ext, options):
    model = Model()
    peer = model.query(SipPeer).filter_by(regexten=user_ext).first()
    if not peer:
        return False
    username = peer.name
    # password
    if "passwd" in options:
        pass_string = "%s:asterisk:%s" % (username, options["password"])
        hashed = md5.new(pass_string).hexdigest()
        peer.md5secret = hashed
        peer.secret = ""
        # newcodecs
    newcodecs = options.get("codecs", False)
    if newcodecs:
        peer.disallow = "all"
        peer.allow = ",".join(newcodecs)
    else:
        peer.disallow = ""
        peer.allow = ""

        # tls
    if options.get("tls", False):
        peer.transport = "tls"
    else:
        peer.transport = "udp"
        # srtp
    if options.get("srtp", False):
        peer.encryption = "yes"
    else:
        peer.encryption = "no"

        # voicemail
    exten = model.query(Extension).filter_by(exten=peer.regexten).first()
    if options.get("voicemail", False):
        exten.app = "Gosub"
        exten.appdata = "stdexten,%s,1(SIP/%s,default)" % (peer.regexten, peer.name)
    else:
        exten.app = "Dial"
        exten.appdata = "SIP/%s,60" % (peer.name,)
    exten_sip = model.query(Extension).filter_by(exten=peer.name).first()
    exten_sip.app = exten.app
    exten_sip.appdata = exten.appdata
    model.session.commit()

    # reload asterisk
    reload_peer(peer.name)
    return True
开发者ID:hungld,项目名称:rtcheckcalls,代码行数:50,代码来源:users.py

示例5: general_stats

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
    def general_stats(self):
	res = ""
	total = 0
	total_free = 0
	free_calls = 0
	cost_calls = 0
	total_cost = Decimal()
	total_benefit = Decimal()
	model = Model()
	calls = model.query(Call)
	for call in calls:
		cost = Decimal(call.cost)
		duration = call.charged
		minutes = duration/60
		if cost:
			total += duration
			cost_calls += 1
			total_cost += cost
			total_benefit += Decimal(minutes)*Decimal(0.001) + Decimal(0.001)
		else:
			total_free += duration
			free_calls += 1
	res += "<p>Minutos con coste: %s</p>\n" % (total/60,)
	res += "<p>Minutos gratis: %s</p>\n" % (total_free/60,)
	res += "<p>Llamadas: %s Gratis: %s Con coste: %s</p>\n" % (calls.count(), free_calls, cost_calls)
	res += "<p>Coste total %.3f Beneficio %.3f</p>\n" % (total_cost, total_benefit)
	return res
开发者ID:hungld,项目名称:rtcheckcalls,代码行数:29,代码来源:stats.py

示例6: render_user

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [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

示例7: render_GET

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
    def render_GET(self, request):
	res = None
	logged = session.get_user(request)
	if not logged:
		return redirectTo('/', request)
	parts = request.path.split("/")
	if len(parts) > 2 and logged.admin:
		user_ext = parts[2]
	else:
		user_ext = logged.voip_id
	args = {'ext': user_ext, 'lowquality': '', 'tls': '', 'srtp': '', 'voicemail': ''}
	options = get_options(user_ext)
	if 'codecs' in options and 'gsm' in options['codecs']:
		args['lowquality'] = ' checked '
	if options['tls']:
		args['tls'] = ' checked '
	if options['srtp']:
		args['srtp'] = ' checked '
	if options['voicemail']:
		args['voicemail'] = ' checked '
        model = Model()
        user = model.query(User).filter_by(voip_id=user_ext).first()
        if user and (logged.admin or user.id == logged.id):
            args['bitcoin'] = self.render_btc(logged, user, wallet)
        else:
            return redirectTo('/', request)
	content = print_template('options', args)
	return print_template('content-pbx-lorea', {'content': content})
开发者ID:guyt101z,项目名称:rtcheckcalls,代码行数:30,代码来源:options.py

示例8: check_password

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
    def check_password(self, username, password, user_ext=None):
	model = Model()
	peer = None
	if user_ext:
		peer = model.query(SipPeer).filter_by(regexten=user_ext).first()
	else:
		peer = model.query(SipPeer).filter_by(name=username).first()
	if peer:
		username = peer.name
		user_input = md5.new(username + ":asterisk:" + password).hexdigest()
		hashed = peer.md5secret
		if peer.secret and not hashed:
			hashed = md5.new(username + ":asterisk:" + peer.secret).hexdigest()
		if hashed == user_input:
			return peer
	return False
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:18,代码来源:login.py

示例9: delete_voicemail

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
    def delete_voicemail(self, request, logged, user_ext, msg_id):
	model = Model()
	msg = model.query(VoiceMailMessage).filter_by(msg_id=msg_id, mailboxuser=user_ext).first()
	if msg and msg.recording and (msg.mailboxuser == logged.voip_id or logged.admin):
		mb_user = msg.mailboxuser
		number = msg.msgnum
		msgdir = msg.dir
		model.session.delete(msg)
		model.session.commit()
		# reorder other messages in the folder
		msgs = model.query(VoiceMailMessage).filter_by(mailboxuser=mb_user)
		for amsg in msgs:
			if amsg.msgnum > number and amsg.dir == msgdir:
				amsg.msgnum -= 1
		model.session.commit()
		return mb_user
	return logged.voip_id
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:19,代码来源:voicemail.py

示例10: render_GET

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
    def render_GET(self, request):
	session_id = str(request.getSession().uid)
	request.getSession().expire()
	model = Model()
	web_session = model.query(WebSession).filter_by(session_id=session_id).first()
	if web_session:
		model.session.delete(web_session)
		model.session.commit()
        return redirectTo("/", request)
开发者ID:aleph1888,项目名称:rtcheckcalls,代码行数:11,代码来源:logout.py

示例11: parse_users

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
def parse_users(filename=None):
    extensions = {}

    model = Model()
    peers = model.query(SipPeer).order_by("regexten")
    for peer in peers:
        extensions[peer.regexten] = peer.name

    return extensions
开发者ID:hungld,项目名称:rtcheckcalls,代码行数:11,代码来源:users.py

示例12: change_password

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
def change_password(user_ext, password):
    model = Model()
    peer = model.query(SipPeer).filter_by(regexten=user_ext).first()
    pass_string = "%s:asterisk:%s" % (peer.name, password)
    hashed = md5.new(pass_string).hexdigest()
    peer.md5secret = hashed
    peer.secret = ""
    model.session.commit()
    # reload asterisk
    reload_peer(peer.name)
开发者ID:hungld,项目名称:rtcheckcalls,代码行数:12,代码来源:users.py

示例13: get_options

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
def get_options(user_ext):
    model = Model()
    peer = model.query(SipPeer).filter_by(regexten=user_ext).first()
    username = peer.name
    options = {"srtp": False, "tls": False, "codecs": []}
    if peer.encryption == "yes":
        options["srtp"] = True
    if peer.transport == "tls":
        options["tls"] = True
    if peer.disallow == "all":
        options["codecs"] = []
    if peer.allow:
        options["codecs"] = peer.allow.split(",")
    exten = model.query(Extension).filter_by(exten=peer.regexten).first()
    if exten.app == "Gosub":
        options["voicemail"] = True
    else:
        options["voicemail"] = False
    return options
开发者ID:hungld,项目名称:rtcheckcalls,代码行数:21,代码来源:users.py

示例14: render_user_calls

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
    def render_user_calls(self, user_ext, request):
	FILE = "/var/log/asterisk/cdr-csv/Master.csv"
	if not os.path.exists(FILE):
		return
	f = open(FILE)
	csv_file = csv.reader(f)
	data = list(csv_file)
	logged = session.get_user(request)
	model = Model()
	peer = model.query(SipPeer).filter_by(regexten=user_ext).first()
	user_extensions = [user_ext]
	if peer:
		user_extensions.append(peer.name)
	res = ""
	calls = ""
	for a in data:
		if 'queue-multicall' in a:
			continue
		time_1 = a[9]
		time_2 = a[10]
		time_3 = a[11]
		duration = a[12]
		billsecs = int(a[13])
		from_ext = a[1]
		from_name = a[4]
		appdata = a[8]
		status = a[-4]
		id = a[-2]
		delta = 0.0
		#totalsecs += int(billsecs)
		t1 = datetime.strptime(time_1, "%Y-%m-%d %H:%M:%S")
		to_ext = a[2]
		if to_ext.startswith("stdexten-"):
			status = to_ext.split("-")[1]
			to_ext = a[8].split("@")[0]
		if "@" in appdata and "/" in appdata:
			dest = appdata.split("/")[1].split(",")[0]
			to_ext = dest
		if time_3:
			t2 = datetime.strptime(time_3, "%Y-%m-%d %H:%M:%S")
			delta = t2-t1
		if from_ext in user_extensions or to_ext in user_extensions:
			#calls = "<p>[%s] %s to %s for %s secs on %s/%s/%s %s</p>" % (id, from_ext, to_ext, delta, t1.day, t1.month, t1.year, status) + calls
			date = "%s/%s/%s" % (t1.day, t1.month, t1.year)
			if not from_ext in user_extensions and logged.admin:
				from_ext = "<a href='/user/%s'>%s</a>" % (from_ext, from_ext)
			if not to_ext in user_extensions and logged.admin:
				to_ext = "<a href='/user/%s'>%s</a>" % (to_ext, to_ext)
			calls = ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % (date, from_ext, to_ext, delta, status)) + calls

		#if status == "ANSWERED" and (billsecs > umbra or not umbra):
		#	print from_ext,"->"," "*(14-len(a[2]))+a[2]+" ["+str(billsecs)+"]\t"+str(t1.day)+"\t"+str(t1.hour)
	res += calls
	return res
开发者ID:guyt101z,项目名称:rtcheckcalls,代码行数:56,代码来源:user.py

示例15: create_user

# 需要导入模块: from obelisk.model import Model [as 别名]
# 或者: from obelisk.model.Model import query [as 别名]
def create_user(username, password):
    username_avail = 1
    model = Model()

    # check if username is taken
    if model.query(SipPeer).filter_by(name=username).first():
        print "username already taken", username
        return False

        # find next available extension
    peers = model.query(SipPeer).order_by("regexten")
    maxexten = 0
    for peer in peers:
        exten = int(peer.regexten)
        if exten < 9999 and exten > maxexten:
            maxexten = exten

    nextexten = maxexten + 1
    if nextexten < 1000:
        nextexten = 1000

        # create user in database
    password = md5.new("%s:asterisk:%s" % (username, password)).hexdigest()
    peer = create_user_internal(
        model,
        regexten=str(nextexten),
        name=username,
        md5secret=password,
        callerid="%s <%s>" % (username, nextexten),
        type="friend",
        host="dynamic",
        nat="comedia,force_rport",  # natted
        qualify="yes",  # follow status
        mailbox=str(nextexten),  # register with voicemail mwi
        context="from-freeuser",
    )

    # reload asterisk
    reload_peer(peer.name)
    print "user created", username, nextexten
    return peer
开发者ID:hungld,项目名称:rtcheckcalls,代码行数:43,代码来源:users.py


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