Exemplo n.º 1
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/')
Exemplo n.º 2
0
try:
   p = DBSession.query(Phone).filter(Phone.exten==dst[-3:]).one()
except:
   log.write('Error: extension <%s> not found\n' % dst)
   p = None
log.write('Phone : %s\n' % (p))

if p is not None and p.user is not None:
   email = p.user.email_address
   uid = p.user.user_id
else:
   email = uid = None
log.write('uid=%s, email=%s\n' % (uid, email))


f = Fax()
f.type = 1 #  => received fax
f.hyla_id = hyla_id
f.user_id = uid
f.src = src
f.dest = dst
f.filename = pdf
if pdf is not None:
   try:
      fpdf = open('/var/spool/hylafax/astportal/' + pdf)
      f.pdf = fpdf.read()
      fpdf.close
      log.write('PDF imported from file /var/spool/hylafax/astportal/%s\n' % pdf)
   except:
      log.write('ERROR: PDF file /var/spool/hylafax/astportal/%s\n' % pdf)
DBSession.add(f)