Ejemplo n.º 1
0
   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)
Ejemplo n.º 2
0
   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/')
Ejemplo n.º 3
0
   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/')
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
   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/')
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
   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/')
Ejemplo n.º 8
0
    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/")
Ejemplo n.º 9
0
      order_by(CDR.calldate):

   nouveau += 1

   user, dept = c2ud.get(cdr.src, (None, None))

   typ = u'Optimum bâtiment'
   ttc, ht = optimum_soc(cdr)

   if ht is None:
      erreur += 1
      continue

   if verbose:
      sys.stderr.write('%s, typ=%s, ht=%d, uid=%s, did=%s\n' % \
         (cdr, typ, ht, user, dept))

   # Mise à jour coût
   cdr.ht = ht
   cdr.ttc = ttc
   cdr.user = user
   cdr.department = dept
   DBSession.flush()

import transaction
transaction.commit()

print u'Traitement terminé : %d nouveaux appels sortants, %d non traités.' % \
   (nouveau, erreur)