本文整理汇总了Python中obelisk.model.Model类的典型用法代码示例。如果您正苦于以下问题:Python Model类的具体用法?Python Model怎么用?Python Model使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_GET
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})
示例2: render_all
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)
示例3: render_user
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)
示例4: __init__
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 = ''
示例5: render_mailbox
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
示例6: general_stats
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
示例7: render_GET
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)
示例8: parse_users
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
示例9: change_password
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)
示例10: render_user_calls
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
示例11: render_voice_message
def render_voice_message(self, request, logged, msg_id):
model = Model()
msg = model.query(VoiceMailMessage).filter_by(msg_id=msg_id).first()
if msg and msg.recording and (msg.mailboxuser == logged.voip_id): # no admin here:
request.setHeader('Content-Description', 'File Transfer')
request.setHeader('Content-Type', 'application/octet-stream')
request.setHeader('Content-Disposition', 'attachment; filename=recording-'+msg_id+'-.ogg')
request.setHeader('Content-Transfer-Encoding', 'binary')
#request.setHeader('Expires', '0')
request.setHeader('Content-Length', len(msg.recording))
return msg.recording
return "no access"
示例12: minutes_stats
def minutes_stats(self, request, period, columns, val_checker, obj_class):
model = Model()
ts_start = time.time() - period
ts_end = time.time()
data = []
current = 0
for a in range(columns):
selected = model.query(obj_class).filter(and_(obj_class.timestamp>datetime.fromtimestamp(ts_start), obj_class.timestamp<datetime.fromtimestamp(ts_end)))
pars = list(val_checker(selected))
data.insert(0, [pars, {'label': str(current)}])
ts_start -= period
ts_end -= period
current -= 1
return json.dumps(data)
示例13: get_charges
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
示例14: add_charge
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()
示例15: add_charge
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()