Port list to Mako
authorQuentin Smith <quentin@mit.edu>
Sun, 9 Aug 2009 22:45:25 +0000 (18:45 -0400)
committerQuentin Smith <quentin@mit.edu>
Sun, 9 Aug 2009 22:45:25 +0000 (18:45 -0400)
svn path=/package_branches/invirt-web/cherrypy-rebased/; revision=2668

code/main.py
code/templates/list.mako [new file with mode: 0644]
code/templates/list.tmpl [deleted file]

index 0a9342a..c3db122 100755 (executable)
@@ -60,7 +60,7 @@ class InvirtWeb(View):
         checkpoint.checkpoint('Getting list dict')
         d = getListDict(username, state)
         checkpoint.checkpoint('Got list dict')
-        return templates.list(searchList=[d])
+        return d
     index=list
 
     @cherrypy.expose
diff --git a/code/templates/list.mako b/code/templates/list.mako
new file mode 100644 (file)
index 0000000..71a8943
--- /dev/null
@@ -0,0 +1,159 @@
+<%page expression_filter="h"/>
+<%inherit file="skeleton.mako" />
+<%!
+       from invirt.config import structs as config
+       import datetime
+%>
+
+
+<%def name="title()">
+VM List
+</%def>
+
+<%def name="createForm()">
+% if cant_add_vm:
+<p>${cant_add_vm}</p>
+% else:
+<h2>Create a new VM</h2>
+% if err:
+<p class="error">We had a problem with your request:</p>
+% elif new_machine:
+<p>Congratulations! You successfully created a new VM called ${new_machine}.</p>
+% endif
+    <form action="create" method="POST">
+    <input type="hidden" name="back" value="list"/>
+      <table>
+       ${self.fn.errorRow('create', err)}
+       <tr>
+         <td>Name</td>
+         <td><input type="text" name="name" value="${defaults.name}"/>.${config.dns.domains[0]}</td>
+       </tr>
+       ${self.fn.errorRow('name', err)}
+       <tr>
+         <td>Description</td>
+         <td><textarea name="description" rows="4" cols="60">${defaults.description}</textarea></td>
+       </tr>
+       ${self.fn.errorRow('description', err)}
+       <tr>
+         <td>Memory</td>
+         <td><input type="text" name="memory" value="${defaults.memory}" size=3/> MiB (${max_memory} max)</td>
+       </tr>
+       ${self.fn.errorRow('memory', err)}
+       <tr>
+         <td>Disk</td>
+         <td><input type="text" name="disksize" value="${defaults.disk}" size=3/> GiB (${"%0.1f" % (max_disk-0.05)} max)</td>
+       </tr>
+       ${self.fn.errorRow('disk', err)}
+        <tr>
+          <td>HVM/ParaVM${self.fn.helppopup('HVM/ParaVM')}</td>
+          <td>
+         ${self.fn.vmTypeList(defaults.type)}
+         </td>
+        </tr>
+       ${self.fn.errorRow('vmtype', err)}
+       ${self.fn.errorRow('autoinstall', err)}
+       <tr>
+         <td>Autoinstall${self.fn.helppopup('Autoinstalls')}</td>
+         <td><input type="radio" name="cd_or_auto" id="cd_or_auto_auto"
+                 onchange="\$('cdromlist').value = ''; \$('vmtype-linux').checked = true">
+${self.fn.autoList(defaults.cdrom, "$('cd_or_auto_auto').checked = true;$('cdromlist').value = '';$('vmtype-linux').checked = true")}
+             (experimental; 2-3 minutes, and you have a machine with empty root password.)
+         </input>
+       </tr>
+       <tr>
+         <td>Boot CD</td>
+         <td><input type="radio" name="cd_or_auto" id="cd_or_auto_cd" checked="checked"
+                onchange="\$('autoinstalllist').value = ''; \$('vmtype-linux-hvm').checked = true">
+${self.fn.cdromList(defaults.cdrom, "$('cd_or_auto_cd').checked = true;$('autoinstalllist').value = '';$('vmtype-linux-hvm').checked = true")}
+</td>
+         </input>
+       </tr>
+       ${self.fn.errorRow('cdrom', err)}
+       ${self.fn.errorRow('cdrom', err)}
+       <tr>
+         <td>Owner</td>
+         <td><input type="text" name="owner" value="${defaults.owner}"/></td>
+       </tr>
+       ${self.fn.errorRow('owner', err)}
+      </table>
+      <input type="submit" class="button" value="Create it!"/><br />
+      Windows notes: ${self.fn.helppopup('Windows')}
+    </form>
+% endif
+</%def>
+
+<%def name="machineRow(machine)">
+      <tr> 
+       <td rowspan="2">
+         <form action="command" method="post">
+           <input type="hidden" name="back" value="list"/>
+           <input type="hidden" name="machine_id"
+                  value="${machine.machine_id}"/>
+<input type="submit" class="power ${'on' if machine.uptime else 'off'}" name="action" value="${'Power off' if machine.uptime else 'Power on'}"\
+% if machine.uptime:
+ onclick="return confirm('Are you sure you want to power off this VM?');"
+% endif
+/>
+         </form>
+       </td>
+       <td><a href="info?machine_id=${machine.machine_id}">${machine.name}</a></td>
+       <td>${machine.memory}M</td>
+       <td>${machine.owner}</td>
+       <td>${machine.administrator}</td>
+% if machine.nics:
+       <td>${', '.join(map(lambda x: x.ip, machine.nics))}</td>
+% else:
+       <td></td>
+% endif
+<td>\
+% if machine.uptime:
+${datetime.timedelta(seconds=int(machine.uptime))}\
+% endif
+</td>
+       <td>\
+% if has_vnc[machine] == True:
+<a href="vnc?machine_id=${machine.machine_id}">Console</a>\
+% elif has_vnc[machine] != 'Off':
+${has_vnc[machine]}
+% endif
+</td>
+      </tr>
+      <tr>
+        <td colspan="7" style="padding-left: 1em; color: #666">${machine.description}</td>
+      </tr>
+</%def>
+
+<%def name="machineList(machines)">
+    <table cellspacing="0" cellpadding="2">
+      <tr>
+       <th></th>
+       <th>Name</th>
+       <th>Memory</th>
+       <th>Owner${self.fn.helppopup('Owner')}</th>
+        <th>Administrator${self.fn.helppopup('Administrator')}</th>
+       <th>IP</th>
+       <th>Uptime</th>
+       <th>VNC</th>
+      </tr>
+% for machine in machines:
+       ${machineRow(machine)}
+% endfor
+    </table>
+    <script type="text/javascript" src="/static/stripe.js"></script>
+    <script type="text/javascript">
+        document.observe("dom:loaded", function() {
+            stripe(\$('machinelist').getElementsByTagName('table')[0],
+                   'stripedrow');
+        });
+    </script>
+</%def>
+
+<p style="font-size: 125%;"><a href="http://${config.web.hostname}">What is XVM?</a></p>
+% if not machines:
+<p>You don't currently control any VMs.</p>   
+% endif
+    <p><a href="list">refresh</a></p>
+    <div id="machinelist">
+    ${machineList(machines)}
+    </div>
+${createForm()}
diff --git a/code/templates/list.tmpl b/code/templates/list.tmpl
deleted file mode 100644 (file)
index 8a0231e..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-#from skeleton import skeleton
-#from invirt.config import structs as config
-#extends skeleton
-#import datetime
-
-
-#def title
-VM List
-#end def
-
-#def createForm()
-#if $cant_add_vm
-<p>$cant_add_vm</p>
-#else
-<h2>Create a new VM</h2>
-#if $err
-<p class="error">We had a problem with your request:</p>
-#else if $varExists('new_machine')
-<p>Congratulations! You successfully created a new VM called $new_machine.</p>
-#end if
-    <form action="create" method="POST">
-    <input type="hidden" name="back" value="list"/>
-      <table>
-#filter None
-      $errorRow('create', $err)
-#end filter
-       <tr>
-         <td>Name</td>
-         <td><input type="text" name="name" value="$defaults.name"/>.${config.dns.domains[0]}</td>
-       </tr>
-#filter None
-$errorRow('name', $err)
-#end filter
-       <tr>
-         <td>Description</td>
-         <td><textarea name="description" rows="4" cols="60">$defaults.description</textarea></td>
-       </tr>
-#filter None
-$errorRow('description', $err)
-#end filter
-       <tr>
-         <td>Memory</td>
-         <td><input type="text" name="memory" value="$defaults.memory" size=3/> MiB ($max_memory max)</td>
-       </tr>
-#filter None
-$errorRow('memory', $err)
-#end filter
-       <tr>
-         <td>Disk</td>
-         <td><input type="text" name="disksize" value="$defaults.disk" size=3/> GiB (${"%0.1f" % ($max_disk-0.05)} max)</td>
-       </tr>
-#filter None
-$errorRow('disk', $err)
-#end filter
-        <tr>
-          <td>HVM/ParaVM#slurp
-#filter None
-$helppopup('HVM/ParaVM')#slurp
-#end filter
-</td>
-          <td>
-#filter None
-$vmTypeList($defaults.type)
-#end filter
-</td>
-        </tr>
-#filter None
-$errorRow('vmtype', $err)
-#end filter
-#filter None
-$errorRow('autoinstall', $err)
-#end filter
-       <tr>
-         <td>Autoinstall#slurp
-#filter None
-$helppopup('Autoinstalls')#slurp
-#end filter
-</td>
-         <td><input type="radio" name="cd_or_auto" id="cd_or_auto_auto"
-                 onchange="\$('cdromlist').value = ''; \$('vmtype-linux').checked = true">
-#filter None
-$autoList($defaults.cdrom, "$('cd_or_auto_auto').checked = true;$('cdromlist').value = '';$('vmtype-linux').checked = true")
-             (experimental; 2-3 minutes, and you have a machine with empty root password.)
-#end filter
-         </input>
-       </tr>
-       <tr>
-         <td>Boot CD</td>
-         <td><input type="radio" name="cd_or_auto" id="cd_or_auto_cd" checked="checked"
-                onchange="\$('autoinstalllist').value = ''; \$('vmtype-linux-hvm').checked = true">
-#filter None
-$cdromList($defaults.cdrom, "$('cd_or_auto_cd').checked = true;$('autoinstalllist').value = '';$('vmtype-linux-hvm').checked = true")
-#end filter
-</td>
-         </input>
-       </tr>
-$errorRow('cdrom', $err)
-$errorRow('cdrom', $err)
-       <tr>
-         <td>Owner</td>
-         <td><input type="text" name="owner" value="$defaults.owner"/></td>
-       </tr>
-#filter None
-       $errorRow('owner', $err)
-#end filter
-      </table>
-      <input type="submit" class="button" value="Create it!"/><br />
-      Windows notes: #slurp
-#filter None
-$helppopup('Windows')#slurp
-#end filter
-    </form>
-#end if
-#end def
-
-#def machineRow($machine)
-      <tr> 
-       <td rowspan="2">
-         <form action="command" method="post">
-           <input type="hidden" name="back" value="list"/>
-           <input type="hidden" name="machine_id"
-                  value="$machine.machine_id"/>
-<input type="submit" class="power #slurp
-#if $machine.uptime then 'on' else 'off'
-" name="action" value="#slurp
-#if $machine.uptime then 'Power off' else 'Power on'
-"#slurp
-#if $machine.uptime
- onclick="return confirm('Are you sure you want to power off this VM?');"
-#end if
-/>
-         </form>
-       </td>
-       <td><a href="info?machine_id=$machine.machine_id">$machine.name</a></td>
-       <td>${machine.memory}M</td>
-       <td>$machine.owner</td>
-       <td>$machine.administrator</td>
-#if $machine.nics
-#set $nic = $machine.nics[0]
-       <td>$nic.ip</td>
-#else
-       <td></td>
-#end if
-<td>#slurp
-#if $machine.uptime
-${datetime.timedelta(seconds=int(machine.uptime))}#slurp
-#end if
-</td>
-       <td>#slurp
-#if $has_vnc[$machine] == True
-<a href="vnc?machine_id=$machine.machine_id">Console</a>#slurp
-#else if $has_vnc[$machine] != 'Off'
-#filter None
-$has_vnc[$machine]
-#end filter
-#end if
-</td>
-      </tr>
-      <tr>
-        <td colspan="7" style="padding-left: 1em; color: #666">$machine.description</td>
-      </tr>
-#end def
-
-#def machineList($machines)
-    <table cellspacing="0" cellpadding="2">
-      <tr>
-       <th></th>
-       <th>Name</th>
-       <th>Memory</th>
-       <th>Owner#slurp
-#filter None
-$helppopup('Owner')#slurp
-#end filter
-</th>
-        <th>Administrator#slurp
-#filter None
-$helppopup('Administrator')#slurp
-#end filter
-</th>
-       <th>IP</th>
-       <th>Uptime</th>
-       <th>VNC</th>
-      </tr>
-      #for $machine in $machines:
-    #filter None
-       $machineRow($machine)
-    #end filter
-      #end for
-    </table>
-    <script type="text/javascript" src="/static/stripe.js"></script>
-    <script type="text/javascript">
-        document.observe("dom:loaded", function() {
-            stripe(\$('machinelist').getElementsByTagName('table')[0],
-                   'stripedrow');
-        });
-    </script>
-#end def
-
-
-#def body
-<p style="font-size: 125%;"><a href="http://${config.web.hostname}">What is XVM?</a></p>
-#if not $machines
-<p>You don't currently control any VMs.</p>   
-#end if
-    <p><a href="list">refresh</a></p>
-    <div id="machinelist">
-    #filter None
-    $machineList($machines)
-    #end filter
-    </div>
-#filter None
-$createForm()
-#end filter
-#end def