本文整理汇总了Python中astportal2.model.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: originate
def originate(self, exten, cust):
''' Originate call
'''
uphones = DBSession.query(User).get(request.identity['user'].user_id).phone
if len(uphones)<1:
return dict(status=2)
o = Outcall()
o.user_id = request.identity['user'].user_id
o.cust_id = cust
o.cookie = randint(-2147483648, 2147483647)
DBSession.add(o)
DBSession.flush() # needed to get the out_id
chan = uphones[0].sip_id
exten = sub(r'\D', '', exten)
log.debug('originate: outcall %d from extension %s to %s' % (
o.out_id, chan, exten))
res = Globals.manager.originate(
'SIP/' + chan.encode('iso-8859-1'), # Channel
exten.encode('iso-8859-1'), # Extension
context=chan.encode('iso-8859-1'),
priority='1',
caller_id=default_cid,
variables= {'OUTCALL': o.out_id,
'COOKIE': o.cookie},
async = True # Seems to be needed else DB is not commited and
# call to uniqueid below fails with "inexistant call"
)
status = o.out_id if res.headers['Response']==u'Success' else -1
log.debug('originate: res=%s, outcall=%d, status=%s, cookie=%d' % (
res, o.out_id, status, o.cookie))
return dict(status=status)
示例2: listen
def listen(self, id, **kw):
''' Listen record
'''
r = DBSession.query(Record).get(id)
fn = '%s/rec-%s.wav' % (dir_monitor, r.uniqueid)
try:
st = stat(fn)
except:
flash(u'Enregistrement introuvable: %s' % fn, 'error')
redirect('/records/')
phones = DBSession.query(User).filter(User.user_name==request.identity['repoze.who.userid']).one().phone
if len(phones)<1:
log.debug('Playback from user %s : no extension' % (
request.identity['user']))
flash(u'Poste de l\'utilisateur %s introuvable' % \
request.identity['user'], 'error')
redirect('/records/')
sip = phones[0].sip_id
res = Globals.manager.originate(
'SIP/' + sip, # Channel
sip, # Extension
application = 'Playback',
data = fn[:-4],
)
log.debug('Playback %s from user %s (%s) returns %s' % (
fn[:-4], request.identity['user'], sip, res))
redirect('/records/')
示例3: check_access
def check_access():
'''Check access rights / group: admin=full access, boss=users from same department, user.
Returns SA Query object for selected CDRs
'''
if in_any_group('admin', 'APPELS'):
cdrs = DBSession.query(CDR)
elif in_group('CDS'):
# Find list of phones from the user's list of phones
# user_phones -> departments -> phones
phones = []
for p in request.identity['user'].phone:
log.info('CDS phone %s -> department %s' % (p, p.department))
for d in [d.department for d in request.identity['user'].phone]:
log.info('CDS department <%s>' % (d))
for p in d.phones:
phones.append(p)
src = [prefix_src + p.exten for p in phones]
dst = [p.exten for p in phones]
cdrs = DBSession.query(CDR).filter( (CDR.src.in_(src)) | (CDR.dst.in_(dst)) )
log.info('CDS phone <%s> -> source <%s>, destination <%s>' % (
request.identity['user'].phone, src, dst))
elif in_group('utilisateurs'):
src = [prefix_src + p.exten for p in request.identity['user'].phone]
dst = [p.exten for p in request.identity['user'].phone]
cdrs = DBSession.query(CDR).filter( (CDR.src.in_(src)) | (CDR.dst.in_(dst)) )
else:
flash(u'Accès interdit')
redirect('/')
return cdrs
示例4: save
def save(self, name, comment, type, begin, end, file, active=None):
log.debug('Save "%s"!' % file)
c = Campaign()
c.name = name
c.comment = comment
c.type = type
c.active = active
c.begin = begin
c.end = end
DBSession.add(c)
DBSession.flush()
log.debug(u'nouvelle campagne %s créée' % c.cmp_id)
msg = u'Campagne "%s" créée' % name
if file is not None:
l, e, m = process_file(file, c.cmp_id)
if l==0:
msg += m
else:
msg += u', %d lignes intégrées' % l
if e!=0:
msg += u', %d erreurs' % e
flash(msg)
redirect('/cc_campaign/')
示例5: delete
def delete(self, id, **kw):
''' Delete shortcut from DB
'''
log.info('delete ' + kw['_id'])
DBSession.delete(DBSession.query(Shortcut).get(kw['_id']))
flash(u'Raccourci supprimé', 'notice')
redirect('/shortcuts/')
示例6: create
def create(self, pwd1, pwd2, **kw):
''' Add new user to DB
'''
if DBSession.query(User).filter(User.user_name==kw['user_name']).all():
flash(u'Ce compte existe déjà, utilisateur pas créé', 'error')
redirect('/users/')
log.info('new ' + kw['user_name'])
u = User()
u.user_name = kw['user_name']
u.firstname = kw['firstname']
u.lastname = kw['lastname']
u.email_address = kw['email_address']
u.fax = kw['fax']
u.voicemail = kw['voicemail']
u.email_voicemail = kw['email_voicemail']
u.password = pwd1
u.display_name = u.lastname + ' ' + u.firstname
u.ascii_name = asterisk_string(u.display_name)
over = kw.get('over')
if over is not None:
Globals.manager.send_action({'Action': 'DBput',
'Family': 'over', 'Key': over, 'Val': 'context'})
if 'groups' in kw:
u.groups = DBSession.query(Group).\
filter(Group.group_id.in_(kw['groups'])).all()
DBSession.add(u)
flash(u'Nouvel utilisateur "%s" créé' % (kw['user_name']))
redirect('/users/')
示例7: create
def create(self, **kw):
''' Add new pickup to DB
'''
if DBSession.query(Pickup).filter(Pickup.name==kw['name']).all():
flash(u'Ce groupe existe déjà, pas créé', 'error')
redirect('/pickups/')
# Find new pickup group (0-63)
i = 0
for p in DBSession.query(Pickup).order_by(Pickup.pickup_id):
if p.pickup_id!=i: break
i += 1
if i>63:
flash(u'Nombre maximum de groupe d\'interceptions atteint, création impossible',
'error')
else:
p = Pickup()
p.pickup_id = i
p.name = kw['name']
p.comment = kw['comment']
DBSession.add(p)
flash(u'Nouveau groupe d\'interception "%s" créé' % (kw['name']))
redirect('/pickups/')
示例8: delete
def delete(self, id, **kw):
''' Delete department from DB
'''
log.info('delete ' + kw['_id'])
DBSession.delete(DBSession.query(Department).get(kw['_id']))
flash(u'Service supprimé', 'notice')
redirect('/departments/')
示例9: create_admin
def create_admin(self, cf_types, exten, to_intern, to_extern):
''' Add call forward to Asterisk database
'''
try:
p = DBSession.query(Phone).filter(Phone.exten==exten).one()
except:
log.warning('No phone for extension %s' % exten)
flash(u'Poste %s inexistant, renvoi non créé' % exten, 'error')
redirect('/forwards/')
dest = to_extern if to_extern else to_intern
man = Globals.manager.command('database put %s %s %s' % (
cf_types, p.sip_id, dest))
log.debug('database put %s %s %s returns %s' % (
cf_types, p.sip_id, dest, man))
# Notify user's phone
man = Globals.manager.command('sip notify grandstream-idle-screen-refresh %s' % (
p.sip_id))
log.debug('sip notify grandstream-idle-screen-refresh %s returns %s' % (
p.sip_id, man))
if len(dest) < 6:
# Notify dest phone if not external
try:
p = DBSession.query(Phone).filter(Phone.exten==dest).one()
man = Globals.manager.command('sip notify grandstream-idle-screen-refresh %s' % (
p.sip_id))
log.debug('sip notify grandstream-idle-screen-refresh %s returns %s' % (
p.sip_id, man))
except:
log.warning('Phone not found for dest "%s"')
# flash(u'Une erreur est survenue', 'error')
redirect('/forwards/')
示例10: delete
def delete(self, id, **kw):
''' Delete group from DB
'''
log.info('delete ' + kw['_id'])
DBSession.delete(DBSession.query(Group).get(kw['_id']))
flash(u'Groupe supprimé', 'notice')
redirect('/groups/')
示例11: delete
def delete(self, id, **kw):
''' Delete call forward
'''
exten, cf, to = kw['_id'].split(':')
try:
p = DBSession.query(Phone).filter(Phone.exten==exten).one()
except:
log.warning('No phone for extension %s' % exten)
flash(u'Poste %s inexistant, renvoi non supprimé' % exten, 'error')
redirect('/forwards/')
log.info('delete %s %s %s' % (p.sip_id, cf, to))
if in_any_group('admin', 'CDS'):
man = Globals.manager.command('database del %s %s' % (
cf, p.sip_id))
log.debug('admin: database delete %s %s returns %s' % (
cf_types, p.sip_id, man))
else:
u = DBSession.query(User).get(request.identity['user'].user_id)
for p in u.phone:
man = Globals.manager.command('database del %s %s' % (
cf, p.sip_id))
log.debug('database delete %s %s returns %s' % (
cf, p.sip_id, man))
# flash(u'Une erreur est survenue', 'error')
redirect('/forwards/')
示例12: play_or_tts
def play_or_tts(typ, val, brk=None):
""" Choose Playback / Background or RealSpeak
Return app, param
"""
if typ == "s":
# XXX if val not in application.sounds:
# XXX application.sounds.append(DBSession.query(Sound).get(val))
s = DBSession.query(Sound).get(val)
name = "astportal/%s" % s.name if s is not None else "beep"
if brk is not None:
app = u"Background"
param = u"%s" % (name)
else:
app = u"Playback"
param = u"%s" % (name)
elif typ == "t":
# XXX if val not in application.texts:
# XXX application.texts.append(DBSession.query(Text).get(val))
app = u"RealSpeak"
txt = DBSession.query(Text).get(val)
param = u"%s" % (txt.text.replace(",", "\,"))
if brk is not None:
param += u",%s" % (brk)
return (app, param)
示例13: create
def create(self, **kw):
''' Add new shortcut to DB
'''
if DBSession.query(Shortcut).filter(Shortcut.exten==kw['exten']).all() or \
DBSession.query(Shortcut).filter(Shortcut.number==kw['number']).all():
flash(u'Erreur : raccourci %s ou numéro %s existe déjà' % (
kw['exten'], kw['number']), 'error')
redirect('/shortcuts/')
s = Shortcut()
s.exten = kw['exten']
s.number = kw['number']
s.comment = kw['comment']
s.phone = kw['phone']
DBSession.add(s)
flash(u'Nouveau raccourci "%s -> %s" créé' % (s.exten, s.number))
if p.exten is not None:
# Create new hint (extensions.conf)
res = Globals.manager.update_config(
directory_asterisk + 'extensions.conf',
None, [('Append', 'shortcuts', 'exten',
'>%s,1,%s/%s' % \
(p.exten, 'SIP' if sip_type=='sip' else 'PJSIP', p.sip_id))])
log.debug('Update hints extensions.conf returns %s' % res)
redirect('/shortcuts/')
示例14: create_forward
def create_forward(self, cf_types, to_intern, to_extern=None, **kw):
''' Add call forward to Asterisk database
'''
log.debug('create_forward: %s %s %s' % (cf_types, to_intern, to_extern))
dest = to_extern if to_extern else to_intern
u = DBSession.query(User). \
filter(User.user_name==request.identity['repoze.who.userid']). \
one()
for phone in u.phone:
man = Globals.manager.command('database put %s %s %s' % (
cf_types, phone.sip_id, dest))
log.debug('database put %s %s %s returns %s' % (
cf_types, phone.sip_id, dest, man))
# Notify user's phone
man = Globals.manager.command('sip notify grandstream-idle-screen-refresh %s' % (
phone.sip_id))
log.debug('sip notify grandstream-idle-screen-refresh %s returns %s' % (
phone.sip_id, man))
if len(dest) < 6:
# Notify dest phone if not external
try:
phone = DBSession.query(Phone).filter(Phone.exten==dest).one()
man = Globals.manager.command('sip notify grandstream-idle-screen-refresh %s' % (
phone.sip_id))
log.debug('sip notify grandstream-idle-screen-refresh %s returns %s' % (
phone.sip_id, man))
except:
log.warning('Phone not found for dest "%s"')
# flash(u'Une erreur est survenue', 'error')
redirect('/forwards/')
示例15: delete
def delete(self, id, **kw):
''' Delete contact from DB
'''
log.info('delete ' + kw['_id'])
DBSession.delete(DBSession.query(Phonebook).get(kw['_id']))
flash(u'Contact supprimé', 'notice')
redirect('/phonebook/')