Ignore:
Timestamp:
Aug 9, 2009, 6:45:36 PM (15 years ago)
Author:
quentin
Message:

Move machine-related pages into a REST-style URL.

File:
1 edited

Legend:

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

    r2412 r2413  
    6666        return d
    6767    index=list
    68 
    69     @cherrypy.expose
    70     @cherrypy.tools.mako(filename="/info.mako")
    71     def info(self, machine_id):
    72         """Handler for info on a single VM."""
    73         machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine
    74         d = infoDict(cherrypy.request.login, cherrypy.request.state, machine)
    75         checkpoint.checkpoint('Got infodict')
    76         return d
    7768
    7869    @cherrypy.expose
     
    159150        return {'request': cherrypy.request, 'kwargs': kwargs}
    160151    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()
    161177
    162178def pathSplit(path):
Note: See TracChangeset for help on using the changeset viewer.