Changeset 2483 for package_branches/invirt-web/cherrypy/code
- Timestamp:
- Sep 28, 2009, 12:58:53 AM (15 years ago)
- Location:
- package_branches/invirt-web/cherrypy/code
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
package_branches/invirt-web/cherrypy/code/main.py
r2482 r2483 225 225 return d 226 226 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 227 249 228 250 @cherrypy.expose … … 405 427 name = '' 406 428 description = '' 429 administrator = '' 407 430 type = 'linux-hvm' 408 431 … … 536 559 return disk_fields 537 560 538 def modifyDict(username, state, fields):561 def modifyDict(username, state, machine_id, fields): 539 562 """Modify a machine as specified by CGI arguments. 540 563 541 Return a list of local variables for modify.tmpl.564 Return a dict containing the machine that was modified. 542 565 """ 543 566 olddisk = {} 544 567 session.begin() 545 568 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 547 571 validate = validation.Validate(username, state, **kws) 548 572 machine = validate.machine … … 591 615 if hasattr(validate, 'name'): 592 616 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 615 619 616 620 def badOperation(u, s, p, e): … … 689 693 defaults = Defaults() 690 694 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)) 692 697 defaults.type = machine.type.type_id 693 698 defaults.disk = "%0.2f" % (machine.disks[0].size/1024.) … … 711 716 712 717 mapping = dict( 713 modify=modify,714 718 unauth=unauthFront) 715 719 -
package_branches/invirt-web/cherrypy/code/templates/info.mako
r2432 r2483 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.