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

Make modify form work

Location:
package_branches/invirt-web/cherrypy-rebased/code
Files:
2 edited

Legend:

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

    r2690 r2691  
    219219            return d
    220220        index = info
     221
     222        @cherrypy.expose
     223        @cherrypy.tools.mako(filename="/info.mako")
     224        @cherrypy.tools.require_POST()
     225        def modify(self, machine_id, **fields):
     226            """Handler for modifying attributes of a machine."""
     227            try:
     228                modify_dict = modifyDict(cherrypy.request.login, cherrypy.request.state, machine_id, fields)
     229            except InvalidInput, err:
     230                result = None
     231                machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine
     232            else:
     233                machine = modify_dict['machine']
     234                result = 'Success!'
     235                err = None
     236            info_dict = infoDict(cherrypy.request.login, cherrypy.request.state, machine)
     237            info_dict['err'] = err
     238            if err:
     239                for field in fields.keys():
     240                    setattr(info_dict['defaults'], field, fields.get(field))
     241            info_dict['result'] = result
     242            return info_dict
    221243
    222244        @cherrypy.expose
     
    350372    name = ''
    351373    description = ''
     374    administrator = ''
    352375    type = 'linux-hvm'
    353376
     
    481504    return disk_fields
    482505
    483 def modifyDict(username, state, fields):
     506def modifyDict(username, state, machine_id, fields):
    484507    """Modify a machine as specified by CGI arguments.
    485508
    486     Return a list of local variables for modify.tmpl.
     509    Return a dict containing the machine that was modified.
    487510    """
    488511    olddisk = {}
    489512    session.begin()
    490513    try:
    491         kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name description memory vmtype disksize'.split()])
     514        kws = dict([(kw, fields.get(kw)) for kw in 'owner admin contact name description memory vmtype disksize'.split() if fields.get(kw)])
     515        kws['machine_id'] = machine_id
    492516        validate = validation.Validate(username, state, **kws)
    493517        machine = validate.machine
     
    536560    if hasattr(validate, 'name'):
    537561        controls.renameMachine(machine, oldname, validate.name)
    538     return dict(user=username,
    539                 command="modify",
    540                 machine=machine)
    541 
    542 def modify(username, state, path, fields):
    543     """Handler for modifying attributes of a machine."""
    544     try:
    545         modify_dict = modifyDict(username, state, fields)
    546     except InvalidInput, err:
    547         result = None
    548         machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine
    549     else:
    550         machine = modify_dict['machine']
    551         result = 'Success!'
    552         err = None
    553     info_dict = infoDict(username, state, machine)
    554     info_dict['err'] = err
    555     if err:
    556         for field in fields.keys():
    557             setattr(info_dict['defaults'], field, fields.getfirst(field))
    558     info_dict['result'] = result
    559     return templates.info(searchList=[info_dict])
     562    return dict(machine=machine)
     563
    560564
    561565def badOperation(u, s, p, e):
     
    634638    defaults = Defaults()
    635639    for name in 'machine_id name description administrator owner memory contact'.split():
    636         setattr(defaults, name, getattr(machine, name))
     640        if getattr(machine, name):
     641            setattr(defaults, name, getattr(machine, name))
    637642    defaults.type = machine.type.type_id
    638643    defaults.disk = "%0.2f" % (machine.disks[0].size/1024.)
     
    656661
    657662mapping = dict(
    658                modify=modify,
    659663               unauth=unauthFront)
    660664
  • package_branches/invirt-web/cherrypy-rebased/code/templates/info.mako

    r2684 r2691  
    6060(To edit ram, disk size, or machine name, turn off the machine first.)
    6161% endif
    62 <form action="modify" method="POST">
     62<form action="machine/${machine.machine_id}/modify" method="POST">
    6363  <input type="hidden" name="machine_id" value="${defaults.machine_id}"/>
    6464  <table>
Note: See TracChangeset for help on using the changeset viewer.