From da3ddd29487c8bbfcc103cc65fc081d147263022 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Fri, 20 Nov 2020 11:28:54 -0600 Subject: [PATCH] Move error handling into the auth_base template --- src/pgwui_common/templates/auth_base.mak | 71 +++++++++++++++++++++++ src/pgwui_common/templates/base.mak | 73 +----------------------- 2 files changed, 73 insertions(+), 71 deletions(-) diff --git a/src/pgwui_common/templates/auth_base.mak b/src/pgwui_common/templates/auth_base.mak index d22ff3a..7d797b1 100644 --- a/src/pgwui_common/templates/auth_base.mak +++ b/src/pgwui_common/templates/auth_base.mak @@ -23,6 +23,10 @@ Karl O. Pinc 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. @@ -59,6 +63,73 @@ % endif +<%block name="error_report"> + % if e_cnt: +

${e_cnt} errors + % if lines == UNDEFINED or lines == 0: + found. + % else: + found in a file of ${lines} lines. (Including column headings.) + % endif +

+ % 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: +
+ % endif + % endif + +

+ + % if lineno: + % if not loop.first: + CAUTION -- This error may not be real; prior row(s) of the + uploaded file were rejected: +
+ % endif + + Line ${lineno}: + % endif + + ${error.e}${descr} +

+ + ## Messages delivered here are all generated. Allow markup. + % if hasattr(error, 'detail'): + ${error.detail | n} + % endif + % if hasattr(error, 'data') and error.data: +

Line is:

+

${error.data}

+ % endif + + % if not loop.last and lineno: +
+ % endif + + % endfor + <%def name="upload_form(extra_rows=[], upload_nulls=True)">
diff --git a/src/pgwui_common/templates/base.mak b/src/pgwui_common/templates/base.mak index 2a38acb..c5367f2 100644 --- a/src/pgwui_common/templates/base.mak +++ b/src/pgwui_common/templates/base.mak @@ -23,12 +23,7 @@ Karl O. Pinc - 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. @@ -58,71 +53,7 @@ <%block name="summary_info" /> - % if e_cnt: -

${e_cnt} errors - % if lines == UNDEFINED or lines == 0: - found. - % else: - found in a file of ${lines} lines. (Including column headings.) - % endif -

- % 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: -
- % endif - % endif - -

- - % if lineno: - % if not loop.first: - CAUTION -- This error may not be real; prior row(s) of the - uploaded file were rejected: -
- % endif - - Line ${lineno}: - % endif - - ${error.e}${descr} -

- - ## Messages delivered here are all generated. Allow markup. - % if hasattr(error, 'detail'): - ${error.detail | n} - % endif - % if hasattr(error, 'data') and error.data: -

Line is:

-

${error.data}

- % endif - - % if not loop.last and lineno: -
- % endif - - % endfor + <%block name="error_report" /> % if db_changed: <%block name="action_success" /> -- 2.34.1