Changeset 2483


Ignore:
Timestamp:
Sep 28, 2009, 12:58:53 AM (15 years ago)
Author:
quentin
Message:

Make modify form work

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

Legend:

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

    r2482 r2483  
    225225            return d
    226226        index = info
     227
     228        @cherrypy.expose
     229        @cherrypy.tools.mako(filename="/info.mako")
     230        @cherrypy.tools.require_POST()
     231        def modify(self, machine_id, **fields):
     232            """Handler for modifying attributes of a machine."""
     233            try:
     234                modify_dict = modifyDict(cherrypy.request.login, cherrypy.request.state, machine_id, fields)
     235            except InvalidInput, err:
     236                result = None
     237                machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine
     238            else:
     239                machine = modify_dict['machine']
     240                result = 'Success!'
     241                err = None
     242            info_dict = infoDict(cherrypy.request.login, cherrypy.request.state, machine)
     243            info_dict['err'] = err
     244            if err:
     245                for field in fields.keys():
     246                    setattr(info_dict['defaults'], field, fields.get(field))
     247            info_dict['result'] = result
     248            return info_dict
    227249
    228250        @cherrypy.expose
     
    405427    name = ''
    406428    description = ''
     429    administrator = ''
    407430    type = 'linux-hvm'
    408431
     
    536559    return disk_fields
    537560
    538 def modifyDict(username, state, fields):
     561def modifyDict(username, state, machine_id, fields):
    539562    """Modify a machine as specified by CGI arguments.
    540563
    541     Return a list of local variables for modify.tmpl.
     564    Return a dict containing the machine that was modified.
    542565    """
    543566    olddisk = {}
    544567    session.begin()
    545568    try:
    546         kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name description memory vmtype disksize'.split()])
     569        kws = dict([(kw, fields.get(kw)) for kw in 'owner admin contact name description memory vmtype disksize'.split() if fields.get(kw)])
     570        kws['machine_id'] = machine_id
    547571        validate = validation.Validate(username, state, **kws)
    548572        machine = validate.machine
     
    591615    if hasattr(validate, 'name'):
    592616        controls.renameMachine(machine, oldname, validate.name)
    593     return dict(user=username,
    594                 command="modify",
    595                 machine=machine)
    596 
    597 def modify(username, state, path, fields):
    598     """Handler for modifying attributes of a machine."""
    599     try:
    600         modify_dict = modifyDict(username, state, fields)
    601     except InvalidInput, err:
    602         result = None
    603         machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine
    604     else:
    605         machine = modify_dict['machine']
    606         result = 'Success!'
    607         err = None
    608     info_dict = infoDict(username, state, machine)
    609     info_dict['err'] = err
    610     if err:
    611         for field in fields.keys():
    612             setattr(info_dict['defaults'], field, fields.getfirst(field))
    613     info_dict['result'] = result
    614     return templates.info(searchList=[info_dict])
     617    return dict(machine=machine)
     618
    615619
    616620def badOperation(u, s, p, e):
     
    689693    defaults = Defaults()
    690694    for name in 'machine_id name description administrator owner memory contact'.split():
    691         setattr(defaults, name, getattr(machine, name))
     695        if getattr(machine, name):
     696            setattr(defaults, name, getattr(machine, name))
    692697    defaults.type = machine.type.type_id
    693698    defaults.disk = "%0.2f" % (machine.disks[0].size/1024.)
     
    711716
    712717mapping = dict(
    713                modify=modify,
    714718               unauth=unauthFront)
    715719
  • package_branches/invirt-web/cherrypy/code/templates/info.mako

    r2432 r2483  
    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.