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


Python DBSession.add方法代码示例

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


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

示例1: create

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

示例2: create

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

示例3: save

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

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

示例5: create

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

示例6: originate

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

示例7: create_phones

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

示例8: record

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import add [as 别名]
   def record(self, name, channel, queue, custom1=None, custom2=None):
      '''Record a queue member
         Called from call center monitor web page

Action: Monitor
Mix: 1
File: test
Channel: SIP/pEpSNlcv-000001b9
   '''
      log.debug('Record request "%s" (%s) on "%s"' % (name, channel, queue))

      # Check channel exists, else abort
      for cha in Globals.asterisk.channels.keys():
         if cha.startswith(channel):
            unique_id = Globals.asterisk.channels[cha]['Uniqueid']
            break
      else:
         log.warning('No active channel for %s ?' % channel)
         return dict(status=0)

      # XXX Authentification

      # Gather data from database
      user_id = DBSession.query(User).filter(
         User.user_name==request.identity['repoze.who.userid']).one().user_id
      member_id = DBSession.query(Phone).filter(
         Phone.sip_id==channel[-8:]).one().user_id
      queue_id = DBSession.query(Queue).filter(
            Queue.name==queue).one().queue_id

      # Create filename and send record action to Asterisk via manager
      f = 'rec-%s' % unique_id
      res = Globals.manager.send_action(
            {  'Action': 'Monitor',
               'Mix': 1,
               'Channel': cha,
               'File': f})
      log.info('Record request from userid "%s" to channel %s returns "%s"' % ( 
         user_id, cha, res))

      if res.get_header('Response')=='Success':
         status = 0
         # Set "recorded" flag on member
         Globals.asterisk.members[name]['Recorded'] = True
         # Insert record info into database
         r = Record()
         r.uniqueid = unique_id
         r.queue_id = queue_id
         r.member_id = member_id
         r.user_id = user_id
         r.custom1 = custom1
         r.custom2 = custom2
         DBSession.add(r)

      else:
         status = 1

      return dict(status=status)
开发者ID:sysnux,项目名称:astportal,代码行数:60,代码来源:cc_monitor.py

示例9: create

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import add [as 别名]
 def create(self, **kw):
    ''' Add new group to DB
    '''
    g = Group()
    g.group_name = kw['group_name']
    g.display_name = kw['display_name']
    DBSession.add(g)
    flash(u'Nouveau groupe "%s" créé' % (kw['group_name']))
    redirect('/groups/')
开发者ID:sysnux,项目名称:astportal,代码行数:11,代码来源:groups.py

示例10: create

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import add [as 别名]
 def create(self, **kw):
    ''' Add new holiday to DB
    '''
    h = Holiday()
    h.name = kw['name']
    h.day = kw['date'].day
    h.month = kw['date'].month
    DBSession.add(h)
    update_extensions()
    flash(u'Nouveau jour férié "%s" créé' % (kw['name']))
    redirect('/holidays/')
开发者ID:sysnux,项目名称:astportal,代码行数:13,代码来源:holidays.py

示例11: create

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

示例12: setup

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

示例13: create

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import add [as 别名]
   def create(self, **kw):
      ''' Add new department to DB
      '''
      if DBSession.query(Department).filter(Department.name==kw['name']).all():
         flash(u'Ce service existe déjà, pas créé', 'error')
         redirect('/departments/')

      d = Department()
      d.name = kw['name']
      d.comment = kw['comment']
      DBSession.add(d)
      flash(u'Nouveau service "%s" créé' % (kw['name']))
      redirect('/departments/')
开发者ID:sysnux,项目名称:astportal,代码行数:15,代码来源:department.py

示例14: process_file

# 需要导入模块: from astportal2.model import DBSession [as 别名]
# 或者: from astportal2.model.DBSession import add [as 别名]
def process_file(csv, cmp_id):

   # Check file
   filename = csv.filename
   filetype = csv.type
   filedata = csv.file
   log.debug('process_file: <%s> <%s> <%s>' % (filename, filetype, filedata))

   if filetype not in ('text/csv', 'application/csv', 'application/vnd.ms-excel'):
      log.warning('process_file: not CSV : <%s> <%s> <%s>' % (
         filename, filetype, filedata))
      return 0, 0, u'Le fichier doit être de type CSV !'

   # Temporarily save uploaded file
   tmpfn = '/tmp/customer-%d-%d.csv' % (cmp_id, int(time()))
   tmp = open(tmpfn, 'w')
   tmp.write(filedata.read())
   tmp.close()

   # Then read it
   tmp = open(tmpfn, 'U')
   lines = errors = 0
   for l in tmp:
      lines += 1
      if lines==1: continue
      data = line2data(l)
      if len(data)!=10:
         log.warning('process_file: invalid data %s' % data)
         errors += 1
         continue
      c = Customer()
      c.cmp_id = cmp_id
      c.active = True
      c.code = data[0]
      c.gender = data[1]
      c.lastname = data[2]
      c.firstname = data[3]
      c.phone1 = data[4]
      c.phone2 = data[5]
      c.phone3 = data[6]
      c.phone4 = data[7]
      c.phone5 = data[8]
      c.email = data[9]
      c.filename = filename
      DBSession.add(c)
   tmp.close()

   # remove uploaded file
#   unlink(tmp)
   return lines, errors, ''
开发者ID:sysnux,项目名称:astportal,代码行数:52,代码来源:cc_campaign.py

示例15: save_scenario

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

        if kw.has_key("scenario[]"):
            scenario = kw["scenario[]"]
        else:
            log.error(u"No scenario to save ???")
            scenario = None
            return dict(result=0)  # XXX ?

        positions = {}
        if type(kw["positions[]"]) != type([]):
            kw["positions[]"] = (kw["positions[]"],)
        for p in kw["positions[]"]:
            log.debug(p)
            (context, top, left) = p.split("::")
            positions[context] = (int(float(top)), int(float(left)))

        log.info("save_scenario %s, type %s" % (id, type(scenario)))
        application = DBSession.query(Application).get(int(id))

        # 1. Delete old entries
        DBSession.query(Scenario).filter(Scenario.app_id == int(id)).delete()

        # 2. Create new ones
        if scenario:
            if type(scenario) != type([]):
                scenario = (scenario,)
            for s in scenario:
                sc = Scenario()
                (c, i, e, p, a, m) = s.split("::", 5)
                p = 1 + int(p)
                (sc.comments, sc.app_id, sc.context, sc.extension, sc.step, sc.action, sc.parameters) = (
                    c,
                    id,
                    i,
                    e,
                    p,
                    a,
                    m,
                )
                if p == 1:
                    i = "context_%s" % i
                    log.debug(u"position %s" % i)
                    if i in positions.keys():
                        sc.top = positions[i][0]
                        sc.left = positions[i][1]
                DBSession.add(sc)

        return dict(result=generate_dialplan())
开发者ID:sysnux,项目名称:astportal,代码行数:51,代码来源:application.py


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