Exemple #1
0
 def render_GET(self, request):
     (session, state) = self.prepare(request)
     doc = html.HTMLDocument(
         html.Head(title=self.title, icon='/static/favicon.ico'),
         html.Body(
             html.Div('sdss3archiver', html.Span(id='menu'), id='header'),
             html.Div(id='content')))
     doc.head.css = [
         '/static/jquery-ui-1.7.2.custom.css', '/static/styles.css'
     ]
     doc.head.js = [
         '/static/jquery-1.3.2.min.js',
         '/static/jquery-ui-1.7.2.custom.min.js',
         '/static/jquery.flot.pack.js'
     ]
     # IE does not yet support the canvas tag that flot needs so the
     # following HTML hack only loads the excanvas library on IE
     doc.head.raw = [
         '<!--[if IE]><script language="javascript" type="text/javascript" '
         + 'src="/static/excanvas.pack.js"></script><![endif]-->'
     ]
     for separator, service in enumerate(WebQuery.services):
         if separator:
             doc['menu'].append(' | ')
         if service == self.serviceName:
             doc['menu'].append(service)
         else:
             doc['menu'].append(
                 html.A(service, href='/archiver/%s' % service))
     self.GET(request, session, state, doc['content'])
     return str(doc)
Exemple #2
0
 def describeAsHTML(self):
     """
     Generates HTML describing all of our keys in alphabetical order
     """
     content = utilHtml.Div(utilHtml.Div(
         utilHtml.Span(self.name, className='actorName'),
         utilHtml.Span('%d.%d' % self.version, className='actorVersion'),
         className='actorHeader'),
                            className='actor')
     for name in sorted(self.keys):
         content.append(self.keys[name].describeAsHTML())
     return content
Exemple #3
0
 def describeAsHTML(self):
     content = utilHtml.Div(utilHtml.Div(self.name, className='keyname'),
                            className='key')
     desc = utilHtml.Div(className='keydesc')
     content.append(desc)
     if self.help:
         desc.append(
             utilHtml.Div(utilHtml.Span('Description', className='label'),
                          utilHtml.Span(self.help, className='value'),
                          className='key descriptor'))
     desc.extend(self.typedValues.describeAsHTML().children)
     return content
Exemple #4
0
 def describeAsHTML(self):
     content = utilHtml.Div(utilHtml.Div(utilHtml.Span('Values',
                                                       className='label'),
                                         utilHtml.Span(self.descriptor,
                                                       className='value'),
                                         className='key descriptor'),
                            className='vtypes')
     for vtype in self.vtypes:
         content.append(
             utilHtml.Div(utilHtml.Entity('nbsp'), className='separator'))
         content.extend(vtype.describeAsHTML().children)
     return content
Exemple #5
0
 def GET(self,request,session,state,content):
     # use our javascript library
     content.root.head.js.append('/static/browse.js')
     # render the text inputs for actor.keyword
     inputs = html.Div(
         html.Input(value='actor',type='text',id='actor'),'.',
         html.Input(value='keyword',type='text',id='keyword'),
         id='inputs'
     )
     # display a message area
     choiceHead = html.Div('Javascript must be enabled to use this page',id='messages')
     # display a list of actor choices
     actorChoices = html.Div(id='actor-choices')
     for actorName in actors.Actor.allNames():
         # only generate a link for actors with a dictionary available
         actor = None
         try:
             actor = actors.Actor.attach(actorName.lower(),dictionaryRequired=True)
         except actors.ActorException as e:
             print(str(e))
         if actor:
             node = html.A(actorName,href='?actor=%s'%actorName,
                 title='Using %s dictionary version %d.%d' %
                 (actorName,actor.kdict.version[0],actor.kdict.version[1]))
         else:
             node = html.Span(actorName,
                 title='No dictionary available for the %s actor' % actorName)
         # separate choices by a (breaking) space
         actorChoices.extend([node,' '])
     choiceFoot = html.Div(html.A('',href='#',title='A direct link to this view'),
         className='footer')
     choices = html.Div(choiceHead,actorChoices,choiceFoot,id='choices')
     # append an empty browser div that will display browsed data
     browser = html.Div(
         html.Ul(
             html.Li(html.A(html.Span('Recent'),href='#recent')),
             html.Li(html.A(html.Span('By Date'),href='#bydate')),
             html.Li(html.A(html.Span('Documentation'),href='#doc'))
         ),
         html.Div(
             html.Div('Displaying the ',
                 html.Input(id='nrecent',type='text',className='med-text'),
                 ' most recent updates.',
                 html.Button('UPDATE',type='button',id='recent-update'),
                 id='recent-msg'),
             html.Div('',id='recent-content'),
             html.Div(
                 html.Div('No data received yet'),
                 html.Div(html.A('',href='#',title='A direct link to this view')),
                 className='footer'),
             id='recent'),
         html.Div(
             html.Div(
                 'Displaying ',
                 html.Input(id='nduration',type='text',className='med-text'),
                 html.Select(
                     html.Option('second(s)',value='s'),
                     html.Option('minute(s)',value='m'),
                     html.Option('hour(s)',value='h',selected='yes'),
                     html.Option('day(s)',value='d'),
                     html.Option('week(s)',value='w'),
                     id='duration-unit'),
                 ' ending ',
                 html.Select(
                     html.Option('now',value='now',selected='yes'),
                     html.Option('on...',value='on'),
                     id='on-type'),
                 html.Span(
                     html.Input(type='text',id='from-date',className='long-text'),
                     ' at TAI ',
                     html.Input(type='text',id='from-hour',className='short-text'),
                     ':',
                     html.Input(type='text',id='from-min',className='short-text'),
                     ':',
                     html.Input(type='text',id='from-sec',className='short-text'),
                     id='on-input'),
                 html.Button('UPDATE',type='button',id='bydate-update'),
                 id='bydate-msg'),
             html.Div('',id='bydate-content'),
             html.Div(
                 html.Div('No data received yet'),
                 html.Div(html.A('',href='#',title='A direct link to this view')),
                 className='footer'),
             id='bydate'),
         html.Div(
             html.Div(html.A('',href='#',title='A direct link to this view'),
                 className='footer'),
             id='doc'),
         id='browser')
     # append an empty error container
     errors = html.Div(html.Span(''),id='errors')
     # center everything
     centered = html.Div(inputs,choices,browser,errors,className='centered')
     content.append(centered)
Exemple #6
0
 def POST(self,request,session,state):
     actorName = request.args.get('actor',[None])[-1]
     keyName = request.args.get('key',[None])[-1]
     nRecent = request.args.get('recent',[None])[-1]
     interval = request.args.get('ival',[None])[-1]
     endAt = request.args.get('end',[None])[-1]
     if actorName:
         if (actorName not in actors.Actor.existing and
             actorName not in actors.Actor.registry):
             return self.error('Uknown actor: %s' % actorName)
         else:
             try:
                 actor = actors.Actor.attach(actorName.lower(),dictionaryRequired=True)
             except actors.ActorException as e:
                 return self.error('Unable to load dictionary for %s' % actorName)
             if keyName:
                 if keyName.lower() not in actor.kdict:
                     return self.error('Unknown keyword %s.%s' % (actorName,keyName))
                 else:
                     key = actor.kdict[keyName.lower()]
                     # is this a documentation request?
                     if 'doc' in request.args:
                         return key.describeAsHTML()
                     # otherwise, the keyword must already have a db table
                     if not database.KeyTable.exists(actorName,keyName):
                         return self.error('No data recorded for %s.%s'
                             % (actorName,keyName))
                     try:
                         keyTable = database.KeyTable.attach(actor,key)
                     except Exception as e:
                         errmsg = ('Unable to read %s.%s: %s'
                             % (actorName,keyName,e.__class__.__name__))
                         return self.error(errmsg)
                         log.err(errmsg)
                         log.err(str(e))
                     if nRecent:
                         try:
                             nRecent = int(nRecent)
                         except ValueError:
                             return self.error("Invalid value for parameter 'recent'")
                     if interval:
                         unit = interval[-1]
                         duration = None
                         try:
                             duration = int(interval[:-1])
                         except ValueError:
                             pass
                         if unit not in self.ivalMultipliers or not duration:
                             return self.error("Invalid value for parameter 'ival'")
                         interval = duration*self.ivalMultipliers[unit]
                     if endAt:
                         if endAt != 'now':
                             try:
                                 endAt = int(endAt)
                             except ValueError:
                                 return self.error("Invalid value for parameter 'end'")
                     # if we get this far we have a valid query so prepare a table
                     table = html.Table()
                     # The first header row lists the column names and the first
                     # column is always a timestamp
                     hdr = html.Tr(html.Th('timestamp',title='When this row was recorded'))
                     for alias,vType in zip(
                         keyTable.aliases[1:],keyTable.columnFinalTypes[1:]):
                         hdr.append(html.Th(alias,
                             title=vType.help or 'No help available for this value'))
                     table.append(hdr)
                     # The second header row lists the column value units
                     hdr = html.Tr(html.Th('TAI'))
                     for vType in keyTable.columnFinalTypes[1:]:
                         hdr.append(html.Th(vType.units or ''))
                     table.append(hdr)
                     if nRecent:
                         # display the most recent rows recorded
                         return keyTable.recent(nRecent).addCallback(
                             appendToHTMLTable,table)
                     elif interval and endAt:
                         # display rows recorded during the specified period
                         return keyTable.byDate(interval,endAt).addCallback(
                             appendToHTMLTable,table)
                     else:
                         # this should never happen for an AJAX post
                         return self.error('Invalid request parameters')
             else:
                 # return a list of valid keywords for this actor
                 names = html.Div()
                 for keyName in sorted(actor.kdict.keys):
                     key = actor.kdict[keyName]
                     # display the keyword name with its original case
                     cased = key.name
                     # only provide links to keywords that have a corresponding
                     # database table (so at least one row of keyword data is available)
                     if database.KeyTable.exists(actorName,keyName):
                         node = html.A(cased,href='?actor=%s&key=%s' % (actorName,cased))
                     else:
                         node = html.Span(cased)
                     # use this keyword's help as a tooltip
                     node['title'] = (key.help or
                         'No help available for the %s.%s keyword' % (actorName,keyName))
                     # separate each keyword with a (breaking) space
                     names.extend([node,' '])
                 return names
     else:
         return 'No actor specified'
Exemple #7
0
 def error(self,msg):
     return html.Div(msg,className='error')