Ejemplo n.º 1
0
 def api(self, system, name):
     """
     Return DAS mapping record about provided API.
     """
     record = self.dasmgr.mapping.api_info(system, name)
     page   = "<b>DAS mapping record</b>"
     page  += das_json_full(record)
     return self.page(page, response_div=False)
Ejemplo n.º 2
0
 def listview(self, head, data):
     """
     Represent data in list view.
     """
     kwargs  = head.get('args')
     total   = head.get('nresults', 0)
     apilist = head.get('apilist')
     main    = self.pagination(head)
     style   = 'white'
     page    = ''
     pad     = ''
     tstamp  = None
     status  = head.get('status', None)
     if  status == 'fail':
         reason = head.get('reason', '')
         if  reason:
             page += '<br/><span class="box_red">%s</span>' % reason
     for row in data:
         if  not row:
             continue
         if  style == 'white':
             style = 'gray'
         else:
             style = 'white'
         try:
             mongo_id = row['_id']
         except Exception as exc:
             msg  = str(exc)
             msg += '\nFail to process row\n%s' % str(row)
             raise Exception(msg)
         if  not tstamp:
             try:
                 oid = ObjectId(mongo_id)
                 tstamp = time.mktime(oid.generation_time.timetuple())
             except:
                 pass
         page += '<div class="%s"><hr class="line" />' % style
         jsonhtml = das_json_full(row, pad)
         if  'das' in row and 'conflict' in row['das']:
             conflict = ', '.join(row['das']['conflict'])
         else:
             conflict = ''
         page += self.templatepage('das_row', systems='', \
                 sanitized_data=jsonhtml, id=mongo_id, rec_id=mongo_id,
                 conflict=conflict)
         page += '</div>'
     main += page
     msg   = ''
     if  tstamp:
         try:
             msg += 'request time: %s sec, ' \
                     % (time.mktime(time.gmtime())-tstamp)
         except:
             pass
     msg  += 'cache server time: %5.3f sec' % head['ctime']
     main += '<div align="right">%s</div>' % msg
     return main
Ejemplo n.º 3
0
 def listview(self, head, data):
     """
     Represent data in list view.
     """
     kwargs = head.get('args')
     total = head.get('nresults', 0)
     apilist = head.get('apilist')
     main = self.pagination(head)
     style = 'white'
     page = ''
     pad = ''
     tstamp = None
     status = head.get('status', None)
     if status == 'fail':
         reason = head.get('reason', '')
         if reason:
             page += '<br/><span class="box_red">%s</span>' % reason
     for row in data:
         if not row:
             continue
         if style == 'white':
             style = 'gray'
         else:
             style = 'white'
         try:
             mongo_id = row['_id']
         except Exception as exc:
             msg = str(exc)
             msg += '\nFail to process row\n%s' % str(row)
             raise Exception(msg)
         if not tstamp:
             try:
                 oid = ObjectId(mongo_id)
                 tstamp = time.mktime(oid.generation_time.timetuple())
             except:
                 pass
         page += '<div class="%s"><hr class="line" />' % style
         jsonhtml = das_json_full(row, pad)
         if 'das' in row and 'conflict' in row['das']:
             conflict = ', '.join(row['das']['conflict'])
         else:
             conflict = ''
         page += self.templatepage('das_row', systems='', \
                 sanitized_data=jsonhtml, id=mongo_id, rec_id=mongo_id,
                 conflict=conflict)
         page += '</div>'
     main += page
     msg = ''
     if tstamp:
         try:
             msg += 'request time: %s sec, ' \
                     % (time.mktime(time.gmtime())-tstamp)
         except:
             pass
     msg += 'cache server time: %5.3f sec' % head['ctime']
     main += '<div align="right">%s</div>' % msg
     return main