Ignore:
Timestamp:
Dec 20, 2009, 9:44:49 PM (15 years ago)
Author:
broder
Message:

Upgrade info page to Mako, and use REST-style URLs.

Location:
package_branches/invirt-web/cherrypy-rebased/code
Files:
1 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • package_branches/invirt-web/cherrypy-rebased/code/main.py

    r2677 r2678  
    150150        return {'request': cherrypy.request, 'kwargs': kwargs}
    151151    helloworld._cp_config['tools.require_login.on'] = False
     152
     153    class MachineView(View):
     154        # This is hairy. Fix when CherryPy 3.2 is out. (rename to
     155        # _cp_dispatch, and parse the argument as a list instead of
     156        # string
     157
     158        def __getattr__(self, name):
     159            try:
     160                machine_id = int(name)
     161                cherrypy.request.params['machine_id'] = machine_id
     162                return self
     163            except ValueError:
     164                return None
     165
     166        @cherrypy.expose
     167        @cherrypy.tools.mako(filename="/info.mako")
     168        def info(self, machine_id):
     169            """Handler for info on a single VM."""
     170            machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine
     171            d = infoDict(cherrypy.request.login, cherrypy.request.state, machine)
     172            checkpoint.checkpoint('Got infodict')
     173            return d
     174        index = info
     175
     176    machine = MachineView()
    152177
    153178def pathSplit(path):
     
    606631    return d
    607632
    608 def info(username, state, path, fields):
    609     """Handler for info on a single VM."""
    610     machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine
    611     d = infoDict(username, state, machine)
    612     checkpoint.checkpoint('Got infodict')
    613     return templates.info(searchList=[d])
    614 
    615633def unauthFront(_, _2, _3, fields):
    616634    """Information for unauth'd users."""
     
    637655               command=command,
    638656               modify=modify,
    639                info=info,
    640657               create=create,
    641658               unauth=unauthFront,
  • package_branches/invirt-web/cherrypy-rebased/code/templates/list.mako

    r2674 r2678  
    9696          </form>
    9797        </td>
    98         <td><a href="info?machine_id=${machine.machine_id}">${machine.name}</a></td>
     98        <td><a href="machine/${machine.machine_id}">${machine.name}</a></td>
    9999        <td>${machine.memory}M</td>
    100100        <td>${machine.owner}</td>
     
    112112        <td>\
    113113% if has_vnc[machine] == True:
    114 <a href="vnc?machine_id=${machine.machine_id}">Console</a>\
     114<a href="machine/${machine.machine_id}/vnc">Console</a>\
     115% elif has_vnc[machine] == 'ParaVM':
     116ParaVM${self.fn.helppopup("ParaVM Console")}
    115117% elif has_vnc[machine] != 'Off':
    116118${has_vnc[machine]}
  • package_branches/invirt-web/cherrypy-rebased/code/templates/skeleton.mako

    r2677 r2678  
    66<html>
    77<head><title>${self.title()} &mdash; XVM</title>
     8  <base href="${cherrypy.request.base}" />
    89  <link href="static/favicon.ico" type="image/x-icon" rel="shortcut icon">
    910  <link rel="stylesheet" href="static/style.css" type="text/css" />
     
    5455<li><a href="list">List</a></li>
    5556% if machine:
    56 <li><a href="info?machine_id=${machine.machine_id}">Info</a></li>
    57 <li><a href="vnc?machine_id=${machine.machine_id}">Console</a></li>
     57<li><a href="machine/${machine.machine_id}">Info</a></li>
     58<li><a href="machine/${machine.machine_id}/vnc">Console</a></li>
    5859% endif
    5960<li><a href="help">Help</a></li>
Note: See TracChangeset for help on using the changeset viewer.