From 05b32e8642bb44037800673a3b65b810542ef5c2 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Wed, 11 Dec 2013 11:59:59 +0100
Subject: [PATCH] Use Jinja2 for reference loader

---
 mutalyzer/templates/gbupload.html         | 193 ---------------------
 mutalyzer/templates/reference_loader.html | 200 ++++++++++++++++++++++
 mutalyzer/website.py                      |   4 +-
 3 files changed, 202 insertions(+), 195 deletions(-)
 delete mode 100644 mutalyzer/templates/gbupload.html
 create mode 100644 mutalyzer/templates/reference_loader.html

diff --git a/mutalyzer/templates/gbupload.html b/mutalyzer/templates/gbupload.html
deleted file mode 100644
index f47270af..00000000
--- a/mutalyzer/templates/gbupload.html
+++ /dev/null
@@ -1,193 +0,0 @@
-<html>
-  <head>
-    <title></title>
-  </head>
-  <body>
-    <div metal:define-macro="content">
-      <script>
-        var oldLoad = window.onload;
-        window.onload=function(){
-              if (oldLoad) oldLoad();
-              updateVisibility();
-        }
-      </script>
-    <center><h3>Reference File Loader</h3></center>
-    The Reference File Loader allows you to use your own reference
-    sequence when no appropriate RefSeq, GenBank or LRG file is available.
-    <br>
-    Please select one of the options below to upload or retrieve your reference
-    sequence (maximum size is <span tal:content = "maxSize"></span> megabytes):
-    <br>
-    <br>
-    <form name='invoer' enctype="multipart/form-data"
-          action="" method="post">
-      <table border="0" cellpadding="0" cellspacing="0">
-        <tr valign="top">
-          <th width="100" style="text-align: left; padding-left : 70px">Options</th>
-          <td>
-            <input type="radio" name="invoermethode" value='file' checked
-                   onClick="updateVisibility();">
-            The reference sequence file is a local file<br>
-            <input type="radio" name="invoermethode" value='url'
-                   onClick="updateVisibility();">
-            The reference sequence file can be found at the following URL<br>
-            <input type="radio" name="invoermethode" value='gene'
-                   onClick="updateVisibility();">
-            Retrieve part of the reference genome for a (HGNC) gene symbol<br>
-            <input type="radio" name="invoermethode" value='chr'
-                   onClick="updateVisibility();">
-            Retrieve a range of a chromosome by accession number<br>
-            <input type="radio" name="invoermethode" value='chrname'
-                   onClick="updateVisibility();">
-            Retrieve a range of a chromosome by name<br>
-          </td>
-        </tr>
-        <tr height="20px"></tr>
-        <tr valign="top">
-          <th width="100" style="text-align : left; padding-left : 70px">Input
-          </th>
-          <td>
-            <span id="file_label">
-              <i>Please select the GenBank file in plain text format</i><br>
-              <input type='file' name="bestandsveld"><br>
-            </span>
-            <span id="url_label">
-              <i>Please enter the URL of the GenBank file in plain text
-                 (including http://)</i>
-              <br>
-              <input type='text' name="urlveld"><br>
-            </span>
-            <span id="gene_label">
-              <i>Please enter the Gene symbol and organism name without spaces
-              and specify the length of the flanking sequences</i>
-              <br>
-              <b>Note:</b> This uses
-              the <a href="http://www.ncbi.nlm.nih.gov/sites/gquery">NCBI
-              Entrez</a> search engine and is therefore based on the current
-              Entrez assembly for the given organism (GRCh37/hg19 for human).
-            	<table>
-             		<tr>
-                  <td>Gene symbol</td>
-                  <td><input type='text' name="genesymbol"></td>
-                </tr>
-              	<tr>
-                  <td>Organism name</td>
-                  <td><input type='text' name="organism"></td>
-                </tr>
-              	<tr>
-                  <td>Number of 5' flanking nucleotides</td>
-                  <td><input type='text' name="fiveutr" value="5000"></td>
-                </tr>
-                	<tr><td>Number of 3' flanking nucleotides</td>
-                  <td><input type='text' name="threeutr" value="2000"></td>
-                </tr>
-             	</table>
-            </span>
-            <span id="range_label">
-              <i>Please enter the accession number of the chromosome or contig
-              and specify the range</i><br>
-              <table>
-                <tr>
-                  <td>Chromosome accession number</td>
-                  <td><input type='text' name="chracc"></td>
-                </tr>
-                <tr>
-                  <td>Start position</td>
-                  <td><input type='text' name="start"></td>
-                </tr>
-                <tr>
-                  <td>Stop position</td>
-                  <td><input type='text' name="stop"></td>
-                </tr>
-                <tr>
-                  <td>Orientation</td>
-                  <td>
-                    <select name="orientation">
-                      <option value="1">Forward</option>
-                      <option value="2">Reverse</option>
-                    </select>
-                  </td>
-                </tr>
-              </table>
-            </span>
-            <span id="chrname_label">
-              <i>Please enter the name of the chromosome
-              and specify the range</i><br>
-              <table>
-                <tr>
-                  <td>Assembly</td>
-                  <td>
-                    <select name="chrnameassembly">
-                          <option
-                          selected="selected"
-                          tal:content = "selected_assembly"
-                          tal:attributes = "value selected_assembly">
-                          </option>
-                          <option tal:repeat = "i unselected_assemblies"
-                          tal:content = "i"
-                          tal:attributes = "value i">
-                          </option>
-                    </select>
-                  </td>
-                </tr>
-                <tr>
-                  <td>Chromosome name</td>
-                  <td><input type='text' name="chrname"></td>
-                </tr>
-                <tr>
-                  <td>Start position</td>
-                  <td><input type='text' name="chrnamestart"></td>
-                </tr>
-                <tr>
-                  <td>Stop position</td>
-                  <td><input type='text' name="chrnamestop"></td>
-                </tr>
-                <tr>
-                  <td>Orientation</td>
-                  <td>
-                    <select name="chrnameorientation">
-                      <option value="1">Forward</option>
-                      <option value="2">Reverse</option>
-                    </select>
-                  </td>
-                </tr>
-              </table>
-            </span>
-            <input type='hidden' name="method" value="gbupload">
-            <input type='hidden' name="client" value="human">
-            <input type='hidden' name="location" value="file">
-            <input type='hidden' name="bestandsnaam"
-                   value="">
-          </td>
-        </tr>
-        <tr height="20px"></tr>
-        <tr>
-          <td></td>
-          <td>
-            <input type="submit" value="Submit">
-            <a href="https://humgenprojects.lumc.nl/trac/mutalyzer/wiki/ReferenceLoader">Help</a>
-          </td>
-        </tr>
-      </table>
-    </form><br>
-
-  <div tal:condition = "errors">
-    <b>Error output:</b><br>
-    <pre><div tal:repeat = "i errors"
-         tal:replace = "structure string:${i}<br>">
-    </div></pre>
-  </div>
-    <div tal:condition = "UD">
-      <b>Output:</b><br>
-      <br>
-      Your reference sequence was loaded successfully.<br>
-      You now can use mutalyzer with the following accession number as
-      reference: <b tal:content = "UD"></b><br>
-      <a tal:attributes = "href string:Reference/${UD}.gb">
-        Download this reference sequence.
-      </a>
-    </div>
-    <br>
-    </div>
-  </body>
-</html>
diff --git a/mutalyzer/templates/reference_loader.html b/mutalyzer/templates/reference_loader.html
new file mode 100644
index 00000000..21565761
--- /dev/null
+++ b/mutalyzer/templates/reference_loader.html
@@ -0,0 +1,200 @@
+{% extends "base.html" %}
+
+{% set active_page = "reference-loader" %}
+{% set page_title = "Reference File Loader" %}
+
+{% block content %}
+
+<script>
+var oldLoad = window.onload;
+window.onload=function(){
+  if (oldLoad) oldLoad();
+    updateVisibility();
+}
+</script>
+
+<p>
+The Reference File Loader allows you to use your own reference
+sequence when no appropriate RefSeq, GenBank or LRG file is available.
+</p>
+<p>
+Please select one of the options below to upload or retrieve your reference
+sequence (maximum size is {{ maxSize|e }} megabytes):
+</p>
+
+<form name='invoer' enctype="multipart/form-data"
+      action="" method="post">
+  <table border="0" cellpadding="0" cellspacing="0">
+    <tr valign="top">
+      <th width="100" style="text-align: left; padding-left : 70px">Options</th>
+      <td>
+        <input type="radio" name="invoermethode" value='file' checked
+               onClick="updateVisibility();">
+        The reference sequence file is a local file<br>
+        <input type="radio" name="invoermethode" value='url'
+               onClick="updateVisibility();">
+        The reference sequence file can be found at the following URL<br>
+        <input type="radio" name="invoermethode" value='gene'
+               onClick="updateVisibility();">
+        Retrieve part of the reference genome for a (HGNC) gene symbol<br>
+        <input type="radio" name="invoermethode" value='chr'
+               onClick="updateVisibility();">
+        Retrieve a range of a chromosome by accession number<br>
+        <input type="radio" name="invoermethode" value='chrname'
+               onClick="updateVisibility();">
+        Retrieve a range of a chromosome by name<br>
+      </td>
+    </tr>
+    <tr height="20px"></tr>
+    <tr valign="top">
+      <th width="100" style="text-align : left; padding-left : 70px">Input
+      </th>
+      <td>
+        <span id="file_label">
+          <i>Please select the GenBank file in plain text format</i><br>
+          <input type='file' name="bestandsveld"><br>
+        </span>
+        <span id="url_label">
+          <i>Please enter the URL of the GenBank file in plain text
+             (including http://)</i>
+          <br>
+          <input type='text' name="urlveld"><br>
+        </span>
+        <span id="gene_label">
+          <i>Please enter the Gene symbol and organism name without spaces
+          and specify the length of the flanking sequences</i>
+          <br>
+          <b>Note:</b> This uses
+          the <a href="http://www.ncbi.nlm.nih.gov/sites/gquery">NCBI
+          Entrez</a> search engine and is therefore based on the current
+          Entrez assembly for the given organism (GRCh37/hg19 for human).
+            <table>
+                <tr>
+              <td>Gene symbol</td>
+              <td><input type='text' name="genesymbol"></td>
+            </tr>
+            <tr>
+              <td>Organism name</td>
+              <td><input type='text' name="organism"></td>
+            </tr>
+            <tr>
+              <td>Number of 5' flanking nucleotides</td>
+              <td><input type='text' name="fiveutr" value="5000"></td>
+            </tr>
+                <tr><td>Number of 3' flanking nucleotides</td>
+              <td><input type='text' name="threeutr" value="2000"></td>
+            </tr>
+            </table>
+        </span>
+        <span id="range_label">
+          <i>Please enter the accession number of the chromosome or contig
+          and specify the range</i><br>
+          <table>
+            <tr>
+              <td>Chromosome accession number</td>
+              <td><input type='text' name="chracc"></td>
+            </tr>
+            <tr>
+              <td>Start position</td>
+              <td><input type='text' name="start"></td>
+            </tr>
+            <tr>
+              <td>Stop position</td>
+              <td><input type='text' name="stop"></td>
+            </tr>
+            <tr>
+              <td>Orientation</td>
+              <td>
+                <select name="orientation">
+                  <option value="1">Forward</option>
+                  <option value="2">Reverse</option>
+                </select>
+              </td>
+            </tr>
+          </table>
+        </span>
+        <span id="chrname_label">
+          <i>Please enter the name of the chromosome
+          and specify the range</i><br>
+          <table>
+            <tr>
+              <td>Assembly</td>
+              <td>
+                <select name="chrnameassembly">
+                      <option
+                      selected="selected"
+                      value="{{ selected_assembly|e }}">{{ selected_assembly|e }}</option>
+                      {% for i in unselected_assemblies %}
+                        <option value="{{ i|e }}">{{ i|e }}</option>
+                      {% endfor %}
+                </select>
+              </td>
+            </tr>
+            <tr>
+              <td>Chromosome name</td>
+              <td><input type='text' name="chrname"></td>
+            </tr>
+            <tr>
+              <td>Start position</td>
+              <td><input type='text' name="chrnamestart"></td>
+            </tr>
+            <tr>
+              <td>Stop position</td>
+              <td><input type='text' name="chrnamestop"></td>
+            </tr>
+            <tr>
+              <td>Orientation</td>
+              <td>
+                <select name="chrnameorientation">
+                  <option value="1">Forward</option>
+                  <option value="2">Reverse</option>
+                </select>
+              </td>
+            </tr>
+          </table>
+        </span>
+        <input type='hidden' name="method" value="gbupload">
+        <input type='hidden' name="client" value="human">
+        <input type='hidden' name="location" value="file">
+        <input type='hidden' name="bestandsnaam"
+               value="">
+      </td>
+    </tr>
+    <tr height="20px"></tr>
+    <tr>
+      <td></td>
+      <td>
+        <input type="submit" value="Submit">
+        <a href="https://humgenprojects.lumc.nl/trac/mutalyzer/wiki/ReferenceLoader">Help</a>
+      </td>
+    </tr>
+  </table>
+</form>
+
+{% if errors %}
+  <p>
+  <b>Error output:</b>
+  </p>
+
+  <pre>
+  {% for i in errors %}
+    {{ i|e }}<br>
+  {% endfor %}
+  </pre>
+{% endif %}
+
+{% if UD %}
+  <p>
+  <b>Output:</b>
+  </p>
+  <p>
+  Your reference sequence was loaded successfully.<br>
+  You now can use mutalyzer with the following accession number as
+  reference: <b>{{ UD|e }}</b>
+  </p>
+  <p>
+  <a href="Reference/{{ UD|e }}.gb">Download this reference sequence.</a>
+  </p>
+{% endif %}
+
+{% endblock content %}
diff --git a/mutalyzer/website.py b/mutalyzer/website.py
index c58f979d..a784717d 100644
--- a/mutalyzer/website.py
+++ b/mutalyzer/website.py
@@ -1355,7 +1355,7 @@ class Uploader:
             'maxSize'              : float(maxUploadSize) / 1048576,
             'errors'               : errors
         }
-        return render_.gbupload(args)
+        return render.reference_loader(args)
     #GET
 
     def POST(self):
@@ -1522,7 +1522,7 @@ class Uploader:
                i.fiveutr, i.threeutr, i.chracc, i.start, i.stop, i.orientation,
                i.chrnameassembly, i.chrname, i.chrnamestart, i.chrnamestop, i.chrnameorientation))
 
-        return render_.gbupload(args)
+        return render.reference_loader(args)
     #POST
 #Uploader
 
-- 
GitLab