Changeset 2691 for package_branches
- Timestamp:
- Dec 20, 2009, 9:45:42 PM (15 years ago)
- 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 219 219 return d 220 220 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 221 243 222 244 @cherrypy.expose … … 350 372 name = '' 351 373 description = '' 374 administrator = '' 352 375 type = 'linux-hvm' 353 376 … … 481 504 return disk_fields 482 505 483 def modifyDict(username, state, fields):506 def modifyDict(username, state, machine_id, fields): 484 507 """Modify a machine as specified by CGI arguments. 485 508 486 Return a list of local variables for modify.tmpl.509 Return a dict containing the machine that was modified. 487 510 """ 488 511 olddisk = {} 489 512 session.begin() 490 513 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 492 516 validate = validation.Validate(username, state, **kws) 493 517 machine = validate.machine … … 536 560 if hasattr(validate, 'name'): 537 561 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 560 564 561 565 def badOperation(u, s, p, e): … … 634 638 defaults = Defaults() 635 639 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)) 637 642 defaults.type = machine.type.type_id 638 643 defaults.disk = "%0.2f" % (machine.disks[0].size/1024.) … … 656 661 657 662 mapping = dict( 658 modify=modify,659 663 unauth=unauthFront) 660 664 -
package_branches/invirt-web/cherrypy-rebased/code/templates/info.mako
r2684 r2691 60 60 (To edit ram, disk size, or machine name, turn off the machine first.) 61 61 % endif 62 <form action="m odify" method="POST">62 <form action="machine/${machine.machine_id}/modify" method="POST"> 63 63 <input type="hidden" name="machine_id" value="${defaults.machine_id}"/> 64 64 <table>
Note: See TracChangeset
for help on using the changeset viewer.