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


Python DBSession.delete方法代码示例

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


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

示例1: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
   def delete(self, id, **kw):
      ''' Delete queue from DB
      '''
      log.info(u'delete ' + kw['_id'])
      q = DBSession.query(Queue).get(kw['_id'])
      gn = (u'SV %s' % q.name, u'AG %s' % q.name)
      log.info(u'delete ' + kw['_id'])
      DBSession.delete(q)

      # Delete supervisor and members groups
      for g in DBSession.query(Group).filter(Group.group_name.in_(gn)):
         log.info(u'delete group "%s"' % g)
         DBSession.delete(g)

      # Remove MOH dir
      moh_class = asterisk_string(q.name, no_space=True)
      moh_dir = '/var/lib/asterisk/moh/fr/astportal/%s' % moh_class
      asterisk_shell('rm -rf "%s"' % moh_dir)
      res = Globals.manager.update_config(
         dir_asterisk  + 'musiconhold.conf', None, [('DelCat', moh_class)])

      # Delete Asterisk queue
      res = Globals.manager.update_config(
         dir_asterisk + 'queues.conf', 
         None, [('DelCat', moh_class)])
      log.debug('Delete queue "%s" returns %s' % (moh_class, res))
      Globals.manager.send_action({'Action': 'QueueReload'})
      if q.name in Globals.asterisk.queues.keys():
         # Delete from list of queues
         del(Globals.asterisk.queues[moh_class])
      Globals.manager.send_action({'Action': 'QueueStatus'})

      flash(u'Groupe d\'appels supprimé', 'notice')
      redirect('/queues/')
开发者ID:sysnux,项目名称:astportal,代码行数:36,代码来源:queues.py

示例2: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
 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/')
开发者ID:sysnux,项目名称:astportal,代码行数:9,代码来源:department.py

示例3: put

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
   def put(self, **kw):
      ''' Update sound in DB
      '''
      id = int(kw['id'])
      s = DBSession.query(Sound).get(id)
      if kw.has_key('owner_id'):
         s.owner_id = kw['owner_id']
      s.comment = kw['comment']

      wav = kw['file']
      filetype = wav.type
      filedata = wav.file
      filename = '%s/%d_%s' % (dir_tmp, s.sound_id, wav.filename)
      # Temporarily save uploaded audio file
      out = open(filename, 'w')
      out.write(filedata.read())
      out.close()

      ret = process_file(filename, filetype, s.sound_id, filetype, s.name, s.language)

      if ret:
         flash(ret,'error')
         DBSession.delete(s)
         redirect('/moh/')

      flash(u'Son modifié')
      redirect('/moh/%d/edit' % id)
开发者ID:sysnux,项目名称:astportal,代码行数:29,代码来源:moh.py

示例4: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
 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/')
开发者ID:sysnux,项目名称:astportal,代码行数:9,代码来源:phonebook.py

示例5: create

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
   def create(self, **kw):
      ''' Add new fax to DB
      '''
      f = Fax()
      f.type = 0 # 0=Sent, 1=Received
      f.comment = kw['comment']
      f.dest = kw['dest']
      f.filename = kw['file'].filename
      u = DBSession.query(User).filter(User.user_name==request.identity['repoze.who.userid']).one()
      f.user_id = u.user_id
      try:
         f.src = u.phone[0].exten
      except:
         f.src = None

      # Try to insert file in DB: might fail if name already exists
      try:
         DBSession.add(f)
         DBSession.flush()
      except:
         flash(u'Impossible de créer le fax', 'error')
         redirect('/fax/')

      ret, pdf_data = process_file(kw['file'], f.fax_id, kw['dest'], u.email_address)
      
      if ret is not None:
         flash(ret,'error')
         DBSession.delete(f)
         redirect('/fax/')

      f.pdf = pdf_data

      flash(u'"%s" en cours d\'envoi à %s' % (kw['file'].filename, kw['dest']))
      redirect('/fax/')
开发者ID:sysnux,项目名称:astportal,代码行数:36,代码来源:fax.py

示例6: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
 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/')
开发者ID:sysnux,项目名称:astportal,代码行数:9,代码来源:shortcuts.py

示例7: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
 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/')
开发者ID:sysnux,项目名称:astportal,代码行数:9,代码来源:groups.py

示例8: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
 def delete(self, id, **kw):
    ''' Delete holiday from DB
    '''
    log.info('delete ' + kw['_id'])
    DBSession.delete(DBSession.query(Holiday).get(kw['_id']))
    update_extensions()
    flash(u'Jour férié supprimé', 'notice')
    redirect('/holidays/')
开发者ID:sysnux,项目名称:astportal,代码行数:10,代码来源:holidays.py

示例9: create

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
   def create(self, **kw):
      ''' Add new sound to DB
      '''
      s = Sound()
      s.name = kw['name']
      if kw['type'] == 'moh':
          s.type = 0
      elif kw['type'] == 'ringtone':
          s.type = 2
      else:
          s.type = 1
      s.comment = kw['comment']
      s.language = kw['lang']
      if 'owner_id' in kw.keys():
         s.owner_id = kw['owner_id']
      else:
         s.owner_id = request.identity['user'].user_id

      # Try to insert file in DB: might fail if name already exists
      try:
         DBSession.add(s)
         DBSession.flush()
      except:
         flash(u'Impossible de créer le son (vérifier son nom)', 'error')
         redirect('/moh/')
      
      if kw['record']:
         uphones = DBSession.query(User).get(request.identity['user'].user_id).phone
# XXX     if len(uphones)<1:
#            return dict(status=2)
         chan = uphones[0].sip_id.encode('iso-8859-1')
         filename = '/tmp/record-%s.wav' % chan
         filetype = 'audio/wav'

      else:
         wav = kw['file']
         filetype = wav.type
         filedata = wav.file
         filename = '%s/%d_%s' % (dir_tmp, s.sound_id, wav.filename)
         # Temporarily save uploaded audio file
         out = open(filename, 'w')
         out.write(filedata.read())
         out.close()

      ret = process_file(filename, filetype, s.sound_id, s.type, s.name, kw['lang'])

      if ret:
         flash(ret,'error')
         DBSession.delete(s)
         redirect('/moh/')

      flash(u'"%s" ajouté à votre bibliothèque sonore' % (s.name))
      redirect('/moh/')
开发者ID:sysnux,项目名称:astportal,代码行数:55,代码来源:moh.py

示例10: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
   def delete(self, id, **kw):
      ''' Delete record
      '''
      r = DBSession.query(Record).get(kw['_id'])
      fn = '%s/rec-%s.wav' % (dir_monitor, r.uniqueid)

      # remove file
      try:
         unlink(fn)
      except:
         log.error('unlink failed %s' % r.uniqueid)
      DBSession.delete(r)
      flash(u'Enregistrement supprimé', 'notice')
      redirect('/records/')
开发者ID:sysnux,项目名称:astportal,代码行数:16,代码来源:record.py

示例11: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
 def delete(self, id, **kw):
    ''' Delete fax from DB
    '''
    id = kw['_id']
    log.info('delete ' + id)
    f = DBSession.query(Fax).get(id)
    # remove uploaded file
    try:
       if f.type==0:
          pdf = '%s/%d_%s' % (dir_fax, f.fax_id, re.sub(r'[^\w\.]', '_', f.filename))
       else:
          pdf = '%s/%s' % (dir_fax, f.filename)
       unlink(pdf)
    except:
       # No file since move into fax in database
       log.warning('unlink failed %s' % id)
    DBSession.delete(f)
    flash(u'Fax supprimé', 'notice')
    redirect('/fax/')
开发者ID:sysnux,项目名称:astportal,代码行数:21,代码来源:fax.py

示例12: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
    def delete(self, id, **kw):
        """ Delete application from DB
      """
        id = int(kw["_id"])
        a = DBSession.query(Application).get(id)
        log.info(u"Delete application %d" % id)

        # 1. Delete scenario
        DBSession.query(Scenario).filter(Scenario.app_id == a.app_id).delete()

        # 2. Delete application
        DBSession.delete(a)

        # 3. Recreate extensions
        result = generate_dialplan()
        if result == 0:
            flash(u"Application supprimée")
        else:
            flash(u"Application supprimée", error)
        redirect("/applications/")
开发者ID:sysnux,项目名称:astportal,代码行数:22,代码来源:application.py

示例13: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
   def delete(self, id, **kw):
      ''' Delete user from DB
      '''

      u = DBSession.query(User).get(kw['_id'])

      # Delete voicemail
      if u.voicemail:
         for p in u.phone:
            res = Globals.manager.update_config(
               dir_ast  + 'voicemail.conf', 
               None, [('Delete', 'astportal', p.exten)])
            log.debug('Delete voicemail.conf returns %s' % res)
            rmtree('%s/%s' % (dir_vm, p.exten), True)
            log.info('Delete voicemail directory %s/%s' % (dir_vm, p.exten))
            Globals.manager.send_action({'Action': 'Command',
               'command': 'voicemail reload'})

      # Then delete user
      log.info('delete ' + kw['_id'])
      DBSession.delete(u)
      flash(u'Utilisateur supprimé', 'notice')
      redirect('/users/')
开发者ID:sysnux,项目名称:astportal,代码行数:25,代码来源:user.py

示例14: delete

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import delete [as 别名]
 def delete(self, id, **kw):
    ''' Delete sound from DB
    '''
    id = kw['_id']
    log.info('delete ' + id)
    s = DBSession.query(Sound).get(id)
    # remove uploaded file
    try:
       dir = (dir_moh if s.type==0 else dir_sounds) % s.language
       unlink('%s/%s.wav' % (dir, re.sub(r'\W', '_', s.name)))
    except:
       log.error('unlink failed %s' % s.name)
    s = DBSession.delete(s)
    try:
       Globals.manager.send_action({'Action': 'Command',
          'Command': 'moh reload'})
    except:
       pass
    flash(u'Son supprimé', 'notice')
    redirect('/moh/')
开发者ID:sysnux,项目名称:astportal,代码行数:22,代码来源:moh.py


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