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


Python DBSession.flush方法代码示例

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


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

示例1: originate

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

示例2: create

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

示例3: save

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

示例4: create_phones

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import flush [as 别名]
def create_phones(base):
   for i in range(0,100):
      p = Phone()
      p.number = '%s%02d' % (base, i)
      p.department_id = -1
      DBSession.add(p)
   DBSession.flush()
   transaction.commit()
开发者ID:sysnux,项目名称:astportal,代码行数:10,代码来源:import_annuaire.py

示例5: create

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

示例6: setup

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import flush [as 别名]
 def setup(self):
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
开发者ID:sysnux,项目名称:astportal,代码行数:14,代码来源:__init__.py

示例7: put

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import flush [as 别名]
   def put(self, name, comment, type, begin, end, file, cmp_id, active=None):

      log.debug('Save "%s"!' % file)

      c = DBSession.query(Campaign).get(cmp_id)
      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 modifiée' % c.cmp_id)

      if file is not None:
         process_file(file, c.cmp_id)

      flash(u'Campagne "%s" modifiée' % name)
      redirect('/cc_campaign/')
开发者ID:sysnux,项目名称:astportal,代码行数:22,代码来源:cc_campaign.py

示例8: create

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import flush [as 别名]
    def create(self, name, exten, dnis, comment, app_begin=None, app_end=None, active=True, owner_id=None, **kw):
        """ Add new application  and initial dialplan to DB
      """
        a = Application()
        a.name = name
        a.exten = exten
        a.dnis = dnis
        a.active = active
        a.begin = app_begin
        a.end = app_end
        a.comment = comment
        a.created_by = request.identity["user"].user_id
        if owner_id:
            a.owner_id = owner_id
        else:
            a.owner_id = request.identity["user"].user_id

        # Try to insert file in DB: might fail if name already exists
        try:
            DBSession.add(a)
            DBSession.flush()
        except:
            log.error(u"Insert failed %s" % a)
            flash(u"Impossible de créer l'application (vérifier son nom)", "error")
            redirect("/applications/")

        s = Scenario()
        s.app_id = a.app_id
        s.context = "Entrant"
        s.extension = "s"
        s.step = 1
        s.action = 0
        s.parameters = None
        DBSession.add(s)

        flash(u'Nouvelle application "%s" créée' % (name))
        redirect("/applications/")
开发者ID:sysnux,项目名称:astportal,代码行数:39,代码来源:application.py


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