Beispiel #1
0
    def document(self, *args, **kwargs):
        """Render the error document"""
        resp = request.environ.get('tg.original_response')
        try:
            # tg.abort exposes the message as .detail in response
            message = resp.detail
        except:  # pragma: no cover
            message = None

        if not message:
            message = ("<p>We're sorry but we weren't able to process "
                       " this request.</p>")

        if request.is_xhr:
            decorators.use_custom_format(self.document, 'xhr')
            try:
                message = kwargs['detail'][:kwargs['detail'].index(kwargs['detail'].split()[30])] + '...'\
                        if len(kwargs['detail'].split()) > 30 else kwargs['detail']
            except KeyError as ex:
                pass
        else:
            decorators.use_custom_format(self.document, 'not_xhr')

        values = dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                      code=request.params.get('code', resp.status_int),
                      message=request.params.get('message', message))
        return values
Beispiel #2
0
 def custom_format(self, format='default'):
     if format != 'default':
         use_custom_format(self.custom_format, format)
         return dict(format=format, status="ok")
     else:
         return 'OK'
Beispiel #3
0
   def gs_screen(self):
      ''' XML idle screen

      Generate custom XML idle screen for GXP phones.
      Reload from phone can be forced with SIP notification, e.g:
         sudo asterisk -rx 'sip notify grandstream-idle-screen-refresh ugeHE96B'
      /etc/asterisk/sip_notify.conf should include:
         [grandstream-idle-screen-refresh]
         Event=>x-gs-screen
      '''

      phone, model = phone_details()
      if model is None:
         log.error(u'Grandstream screen: not a Grandstream phone?')
         return ''

      log.debug('Grandstream screen: model "%s", phone "%s"' % (model, phone))

      if model == '2120':
         use_custom_format(self.gs_screen, 'gxp2120')

      if model == '2000':
         use_custom_format(self.gs_screen, 'gxp2000')

      elif model =='1450':
         use_custom_format(self.gs_screen, 'gxp1450')

      elif model.startswith('116'):
         use_custom_format(self.gs_screen, 'gxp116x')

      else:
         log.error(u'Grandstream screen: unknown model "%s"' % (model))
         return ''

      if phone is not None:
         exten = phone.exten if phone.exten is not None else '?'
         if phone.user is not None:
            ascii_name = phone.user.ascii_name
            display_name = phone.user.display_name
         else:
            ascii_name = display_name = ''
         cfs_out, cfs_in = check_call_forwards(phone)
         if cfs_out:
            log.debug('Call forward out: %s' % cfs_out)
            exten += ' > ' + ', '.join([x[1] for x in cfs_out])
         else:
            cfs_out = u''

         if cfs_in:
            phones_in = DBSession.query(Phone). \
               filter(Phone.sip_id.in_([x[1] for x in cfs_in])).all()
            log.debug('Call forward in: %s' % phones_in)
            cfs_in = u' < '
#            if phones_in.count() > 1:
#               cfs_in = u'Renvoyés : '
#            else:
#               cfs_in = u'Renvoyé : '
            cfs_in += u', '.join([p.exten for p in phones_in])
         else:
            cfs_in = u''

      else:
         exten = name = '?'
         cfs_in = u''
         cfs_out = []

      return dict(
         a=exten, # Compte
         A='$A', # Key labels
         f='$f', T='$T', # Date / time
         b='%s %s%s' % (default_company, exten, cfs_in),
         CFS_IN = cfs_in,
         I = display_name, ascii_name = ascii_name, display_name = display_name,
         exten=exten,
         c='$c', # missed calls
         G='GGG', Stock='SSS', Currency='CCC',
         j='JJJ', v='vvv', L='LLL', S='SSS', g='ggg', w='www', x='xxx' )
Beispiel #4
0
 def custom_format(self, format='default'):
     if format != 'default':
         use_custom_format(self.custom_format, format)
         return dict(format=format, status="ok")
     else:
         return 'OK'
Beispiel #5
0
 def custom_format(self, format="default"):
     if format != "default":
         use_custom_format(self.custom_format, format)
         return dict(format=format, status="ok")
     else:
         return "OK"
Beispiel #6
0
 def custom_format(self, format):
     use_custom_format(self.custom_format, format)
     return dict(format=format, status="ok")
Beispiel #7
0
 def custom_format(self, format):
     use_custom_format(self.custom_format, format)
     return dict(format=format, status="ok")