Move error handling into the auth_base template
authorKarl O. Pinc <kop@karlpinc.com>
Fri, 20 Nov 2020 17:28:54 +0000 (11:28 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Fri, 20 Nov 2020 17:28:54 +0000 (11:28 -0600)
src/pgwui_common/templates/auth_base.mak
src/pgwui_common/templates/base.mak

index d22ff3a85457a92a3e083fe4fb12cc6558a232c4..7d797b103499062f26439b2dc2e60b0dc9de6444 100644 (file)
   Karl O. Pinc <kop@karlpinc.com>
 
   This template uses the following variables in it's context:
+    errors      A list of UploadError exceptions.
+    e_cnt       (Optional) Number of errors to display.
+    lines       (Optional) Number of lines in an uploaded file.
+    db_changed  (Optional) Boolean. Whether the db was changed.
 
     csrf_token  Token for detecting CSRF.
     last_key     Token to detect duplicate uploads.
   % endif
 </%block>
 
+<%block name="error_report">
+  % if e_cnt:
+      <p><em class="error">${e_cnt} errors</em>
+      % if lines == UNDEFINED or lines == 0:
+          found.
+      % else:
+          found in a file of ${lines} lines.  (Including column headings.)
+      % endif
+      </p>
+  % endif
+
+  % for error in errors:
+
+      ## Get error attributes
+      <%
+      if hasattr(error, 'lineno'):
+          lineno = error.lineno
+      else:
+          lineno = False
+
+      if hasattr(error, 'descr') and error.descr:
+          # We really do want to do this formatting here instead of in
+          # the error handler.
+          if error.e[-1] == ':':
+              descr = ' ' + error.descr
+          else:
+              descr = ': ' + error.descr
+      else:
+          descr = ''
+      %>
+
+      % if lineno:
+          % if loop.first:
+              <hr class="errorsep"></hr>
+          % endif
+      % endif
+
+      <p>
+
+      % if lineno:
+          % if not loop.first:
+              CAUTION -- This error may not be real; prior row(s) of the
+              uploaded file were rejected:
+             <br />
+          % endif
+
+          Line ${lineno}:
+      % endif
+
+      <em class="error">${error.e}</em>${descr}
+      </p>
+
+      ## Messages delivered here are all generated.  Allow markup.
+      % if hasattr(error, 'detail'):
+          ${error.detail | n}
+      % endif
+      % if hasattr(error, 'data') and error.data:
+          <p>Line is:</p>
+          <blockquote><p>${error.data}</p></blockquote>
+      % endif       
+
+      % if not loop.last and lineno:
+          <hr class="errorsep"></hr>
+      % endif
+
+  % endfor
+</%block>
 
 <%def name="upload_form(extra_rows=[], upload_nulls=True)">
   <form action="" enctype="multipart/form-data" method="post">
index 2a38acbd41c62932989a893761d6cb00fd1ff0a3..c5367f254f13270edb95f80ed5bbfc70aacec57a 100644 (file)
  
   Karl O. Pinc <kop@meme.com>
 
-  This template uses the following variables in it's context:
-
-    errors      A list of UploadError exceptions.
-    e_cnt       (Optional) Number of errors to display.
-    lines       (Optional) Number of lines in an uploaded file.
-    db_changed  (Optional) Boolean. Whether the db was changed.
+  This template uses no variables in it's context.
 
 </%doc>
 
 
   <%block name="summary_info" />
 
-  % if e_cnt:
-      <p><em class="error">${e_cnt} errors</em>
-      % if lines == UNDEFINED or lines == 0:
-          found.
-      % else:
-          found in a file of ${lines} lines.  (Including column headings.)
-      % endif
-      </p>
-  % endif
-
-  % for error in errors:
-
-      ## Get error attributes
-      <%
-      if hasattr(error, 'lineno'):
-          lineno = error.lineno
-      else:
-          lineno = False
-
-      if hasattr(error, 'descr') and error.descr:
-          # We really do want to do this formatting here instead of in
-          # the error handler.
-          if error.e[-1] == ':':
-              descr = ' ' + error.descr
-          else:
-              descr = ': ' + error.descr
-      else:
-          descr = ''
-      %>
-
-      % if lineno:
-          % if loop.first:
-              <hr class="errorsep"></hr>
-          % endif
-      % endif
-
-      <p>
-
-      % if lineno:
-          % if not loop.first:
-              CAUTION -- This error may not be real; prior row(s) of the
-              uploaded file were rejected:
-             <br />
-          % endif
-
-          Line ${lineno}:
-      % endif
-
-      <em class="error">${error.e}</em>${descr}
-      </p>
-
-      ## Messages delivered here are all generated.  Allow markup.
-      % if hasattr(error, 'detail'):
-          ${error.detail | n}
-      % endif
-      % if hasattr(error, 'data') and error.data:
-          <p>Line is:</p>
-          <blockquote><p>${error.data}</p></blockquote>
-      % endif       
-
-      % if not loop.last and lineno:
-          <hr class="errorsep"></hr>
-      % endif
-
-  % endfor
+  <%block name="error_report" />
 
   % if db_changed:
     <%block name="action_success" />