From 375f84e11b19bfac9b7b3d886b39d4ee468d9720 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Wed, 11 Dec 2013 14:04:08 +0100
Subject: [PATCH] Use Jinja2 for batch jobs

---
 mutalyzer/templates/batch.html      | 165 ----------------------------
 mutalyzer/templates/batch_jobs.html | 155 ++++++++++++++++++++++++++
 mutalyzer/website.py                |  21 ++--
 3 files changed, 163 insertions(+), 178 deletions(-)
 delete mode 100644 mutalyzer/templates/batch.html
 create mode 100644 mutalyzer/templates/batch_jobs.html

diff --git a/mutalyzer/templates/batch.html b/mutalyzer/templates/batch.html
deleted file mode 100644
index a8bc2e45..00000000
--- a/mutalyzer/templates/batch.html
+++ /dev/null
@@ -1,165 +0,0 @@
-<html>
-  <head>
-    <title></title>
-  </head>
-  <body >
-<div metal:define-macro="content">
-  <center>
-    <h3 tal:content = "structure string:Batch ${batchType} Interface"></h3>
-  </center>
-
-  <a href="#" onclick="toggle_visibility('help');">Toggle File Format Help</a>
-  <div id='help' style="display:none">
-    <p>The mutalyzer batch checker accepts the following file formats
-      <ul>
-          <li>Tab delimited text file / CSV file</li>
-          <li>Microsoft Excel file</li>
-          <li>OpenOffice ODS file</li>
-      </ul>
-      and the maximum size is <span tal:content = "maxSize"></span> megabytes.
-      </p>
-    <h5>We accept two types of input files, you can download examples below</h5>
-    <h5>New Style <a href="downloads/batchtestnew.txt">Download Example File</a></h5>
-    <div style="padding-left:20px; width:400px">
-        <p>This file format has no header-row. Each row consists of one or
-          more tab delimited fields, where every field contains a single
-          variant description (or dbSNP rs number in case of the SNP Converter).
-          Note that all rows must have the same number of fields.</p>
-        <table>
-            <tr><td>AB026906.1:c.274G&gt;T</td></tr>
-            <tr><td>AL449423.14(CDKN2A_v002):c.5_400del</td></tr>
-        </table>
-    </div>
-    <h5>Old Style:
-        <a href="downloads/batchtestold.txt">Download Example File</a></h5>
-    <div style="padding-left:20px; width:400px">
-        <p >This file format has a header-row, which consists of
-        three tab delimited fields. In each following row the
-        corressponding data is also tab delimited.</p>
-        <table>
-            <tr>
-                <td>AccNo</td><td>Genesymbol</td><td>Mutation</td>
-            </tr>
-            <tr>
-                <td>AB026906.1</td><td>SDHD</td><td>g.7872G>T</td>
-            </tr>
-        </table>
-    </div>
-    <h5>Output Format</h5>
-    <div style="padding-left:20px; width:400px">
-        <p>The output of a Mutalyzer Batch run is a tab delimited CSV file,
-          which has a header-row to clarify the results. We recommend opening
-          the file in a spreadsheet program, such as OpenOffice Calc or
-          Microsoft Excel.<BR />
-          Note that empty lines are removed from the batch input file.</p>
-    </div>
-  </div> <!-- help -->
-  <br /><br />
-
-
-
-      <table id="inputform">
-          <form action = "" method = "post" enctype = "multipart/form-data">
-              <tr id="batchRow">
-                  <td><b>BatchType</b></td>
-                  <td>
-                <select id="batchType" name="batchType" onchange="return changeBatch(this)">
-
-                <option
-                    tal:repeat = "i batchTypes"
-                    tal:content = "structure string:${i}"
-                    tal:attributes = "value i">
-                </option>
-            </select>
-                  </td>
-                </tr>
-              <tr>
-              <tr id="build" style="display:none">
-                  <td><b>Build</b></td>
-                  <td>
-                      <select name="arg1">
-                          <option
-                          selected="selected"
-                          tal:content = "selected_build"
-                          tal:attributes = "value selected_build">
-                          </option>
-                          <option tal:repeat = "i unselected_builds"
-                          tal:content = "i"
-                          tal:attributes = "value i">
-                          </option>
-                      </select>
-                  </td>
-              </tr>
-              <tr>
-                  <td><b>Email</b></td>
-                  <td><input type = "text"
-                             name = "batchEmail"
-                             tal:attributes = "value lastpost"
-                             style = "width:200px"></td>
-              </tr>
-              <tr>
-                  <td><b>File</b></td>
-                  <td><input type = "file"
-                             name = "batchFile"
-                             style = "width:200px"></td>
-              </tr>
-              <tr>
-                  <td colspan="2">
-                    <input type="submit" value="Submit">
-                    <a href="https://humgenprojects.lumc.nl/trac/mutalyzer/wiki/BatchCheckers">Help</a>
-                  </td>
-              </tr>
-          </form>
-      </table> <!-- inputform -->
-<br />
-
-    <script language="javascript">
-        oldload = window.onload
-        initpage = function() {
-            if (oldload)
-              oldload();
-            onloadBatch();
-        }
-    </script>
-
-    <script language="javascript"
-        tal:content="structure string:document.getElementById('batchType').selectedIndex = ${selected}; document.getElementById('batchRow').style.display = '${hideTypes}'; window.onload = initpage;">
-        </script>
-
-      <div tal:condition = "errors" id="errors">
-          <b>Errors:</b><br />
-          <div class="messages">
-            <p tal:repeat = "m errors" tal:content = "m/description"
-               tal:attributes = "class m/class; title string:${m/level} (origin: ${m/origin})"></p>
-          </div>
-     </div>
-
-  <div tal:condition = "messages">
-    <b>Messages</b><br>
-     <div tal:repeat = "i messages"
-         tal:replace = "structure string:${i}<br>">
-    </div>
-    <div tal:condition = "jobID">
-        <div id="percent">Your job is in progress and currently at 0%</div>
-        <input  id = "jobID"
-                type = "hidden"
-                name = "jobID"
-                tal:attributes = "value jobID">
-        <input  id = "totalJobs"
-                type = "hidden"
-                name = "totalJobs"
-                tal:attributes = "value totalJobs">
-    </div>
-  </div>
-
-  <div tal:condition = "debug">
-    <b>Debug output:</b><br>
-    <pre><div tal:repeat = "i debug"
-         tal:replace = "structure string:${i}<br>">
-    </div></pre>
-  </div>
-</div>
-
-
-</body>
-</html>
diff --git a/mutalyzer/templates/batch_jobs.html b/mutalyzer/templates/batch_jobs.html
new file mode 100644
index 00000000..50f771f0
--- /dev/null
+++ b/mutalyzer/templates/batch_jobs.html
@@ -0,0 +1,155 @@
+{% extends "base.html" %}
+
+{% set active_page = "batch-jobs" %}
+{% set page_title = "Batch {{ batchType|e }} Interface" %}
+
+{% block content %}
+
+<p>
+<a href="#" onclick="toggle_visibility('help');">Toggle File Format Help</a>
+</p>
+
+<div id='help' style="display:none">
+  <p>The mutalyzer batch checker accepts the following file formats
+    <ul>
+        <li>Tab delimited text file / CSV file</li>
+        <li>Microsoft Excel file</li>
+        <li>OpenOffice ODS file</li>
+    </ul>
+    and the maximum size is <span tal:content = "maxSize"></span> megabytes.
+    </p>
+  <h5>We accept two types of input files, you can download examples below</h5>
+  <h5>New Style <a href="downloads/batchtestnew.txt">Download Example File</a></h5>
+  <div style="padding-left:20px; width:400px">
+      <p>This file format has no header-row. Each row consists of one or
+        more tab delimited fields, where every field contains a single
+        variant description (or dbSNP rs number in case of the SNP Converter).
+        Note that all rows must have the same number of fields.</p>
+      <table>
+          <tr><td>AB026906.1:c.274G&gt;T</td></tr>
+          <tr><td>AL449423.14(CDKN2A_v002):c.5_400del</td></tr>
+      </table>
+  </div>
+  <h5>Old Style:
+      <a href="downloads/batchtestold.txt">Download Example File</a></h5>
+  <div style="padding-left:20px; width:400px">
+      <p >This file format has a header-row, which consists of
+      three tab delimited fields. In each following row the
+      corressponding data is also tab delimited.</p>
+      <table>
+          <tr>
+              <td>AccNo</td><td>Genesymbol</td><td>Mutation</td>
+          </tr>
+          <tr>
+              <td>AB026906.1</td><td>SDHD</td><td>g.7872G>T</td>
+          </tr>
+      </table>
+  </div>
+  <h5>Output Format</h5>
+  <div style="padding-left:20px; width:400px">
+      <p>The output of a Mutalyzer Batch run is a tab delimited CSV file,
+        which has a header-row to clarify the results. We recommend opening
+        the file in a spreadsheet program, such as OpenOffice Calc or
+        Microsoft Excel.<BR />
+        Note that empty lines are removed from the batch input file.</p>
+  </div>
+</div>
+
+<table id="inputform">
+    <form action = "" method = "post" enctype = "multipart/form-data">
+        <tr id="batchRow">
+            <td><b>BatchType</b></td>
+            <td>
+          <select id="batchType" name="batchType" onchange="return changeBatch(this)">
+            {% for i in batchTypes %}
+              <option value="{{ i|e }}">{{ i|e }}</option>
+            {% endfor %}
+          </select>
+            </td>
+          </tr>
+        <tr>
+        <tr id="build" style="display:none">
+            <td><b>Build</b></td>
+            <td>
+                <select name="arg1">
+                    <option selected="selected" value="{{ selected_build|e
+                    }}">{{ selected_build|e }}</option>
+                    {% for i in unselected_builds %}
+                      <option value="{{ i|e }}">{{ i|e }}</option>
+                    {% endfor %}
+                </select>
+            </td>
+        </tr>
+        <tr>
+            <td><b>Email</b></td>
+            <td><input type = "text"
+                       name = "batchEmail"
+                       value="{{ lastpost|e }}"
+                       style = "width:200px"></td>
+        </tr>
+        <tr>
+            <td><b>File</b></td>
+            <td><input type = "file"
+                       name = "batchFile"
+                       style = "width:200px"></td>
+        </tr>
+        <tr>
+            <td colspan="2">
+              <input type="submit" value="Submit">
+              <a href="https://humgenprojects.lumc.nl/trac/mutalyzer/wiki/BatchCheckers">Help</a>
+            </td>
+        </tr>
+    </form>
+</table>
+
+<script language="javascript">
+oldload = window.onload
+initpage = function() {
+  if (oldload)
+    oldload();
+  onloadBatch();
+}
+</script>
+
+<script language="javascript">
+document.getElementById('batchType').selectedIndex = {{ selected|e }};
+document.getElementById('batchRow').style.display = '{{ hideTypes|e }}';
+window.onload = initpage;
+</script>
+
+{% if errors %}
+  <p>
+  <b>Errors:</b>
+  </p>
+  <div class="messages">
+    {% for m in errors %}
+      <p class="{{ m.class|e }}" title="{{ m.level|e }} (origin: {{ m.origin|e
+      }})">{{ m.description|e }}</p>
+    {% endfor %}
+  </div>
+{% endif %}
+
+{% if messages %}
+  <p>
+  <b>Messages:</b>
+  </p>
+  <div class="messages">
+    {% for m in messages %}
+      <p class="{{ m.class|e }}" title="{{ m.level|e }} (origin: {{ m.origin|e }})">{{ m.description|e }}</p>
+    {% endfor %}
+    <p>{{ summary|e }}</p>
+  </div>
+  {% if jobID %}
+    <div id="percent">Your job is in progress and currently at 0%</div>
+    <input  id = "jobID"
+            type = "hidden"
+            name = "jobID"
+            value = "{{ jobID|e }}">
+    <input  id = "totalJobs"
+            type = "hidden"
+            name = "totalJobs"
+            value = "{{ totalJobs|e }}">
+  {% endif %}
+{% endif %}
+
+{% endblock content %}
diff --git a/mutalyzer/website.py b/mutalyzer/website.py
index a784717d..e765692f 100644
--- a/mutalyzer/website.py
+++ b/mutalyzer/website.py
@@ -1077,9 +1077,7 @@ class BatchProgress:
         Parameters:
         - jobID: ID of the job to return progress for.
         - totalJobs: Total number of entries in this job.
-        - ajax: If set, return plain text result.
 
-        @todo: The 'progress' template does not exist.
         @todo: Actually, signaling 'OK' here only means the last entry was
             taken from the database queue. It might still be processing, in
             which case not all output is yet written to the result file.
@@ -1092,7 +1090,6 @@ class BatchProgress:
         """
         attr = {"percentage": 0}
 
-        i = web.input(ajax = None)
         try:
             jobID = int(i.jobID)
             total = int(i.totalJobs)
@@ -1106,16 +1103,14 @@ class BatchProgress:
             percentage = 0
         elif percentage > 100:
             percentage = 100
-        if i.ajax:
-            if percentage == 100:
-                #download url, check if file still exists
-                ret = "OK"
-            else:
-                ret = percentage
-            web.header('Content-Type', 'text/plain')
-            return ret
 
-        return render_.progress(attr)
+        if percentage == 100:
+            #download url, check if file still exists
+            ret = "OK"
+        else:
+            ret = percentage
+        web.header('Content-Type', 'text/plain')
+        return ret
     #GET
 #BatchProgress
 
@@ -1259,7 +1254,7 @@ class BatchChecker:
 
             attr["errors"].extend(map(util.message_info, O.getMessages()))
 
-        return render_.batch(attr, page=page)
+        return render.batch_jobs(attr, page=page)
     #batch
 #BatchChecker
 
-- 
GitLab