From 821c237dd47427996995112ae72131148c5fd301 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Fri, 16 Nov 2018 22:49:08 -0600 Subject: [PATCH] Import only those constants used --- src/pgwui_core/core.py | 44 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/pgwui_core/core.py b/src/pgwui_core/core.py index 50e951c..f76f6d9 100644 --- a/src/pgwui_core/core.py +++ b/src/pgwui_core/core.py @@ -60,7 +60,14 @@ from wtforms import ( import psycopg2 -from pgwui_core import constants +from pgwui_core.constants import ( + CHECKED, + UNCHECKED, + CSV, + TAB, + CSV_VALUE, + TAB_VALUE, +) # Setup default values for forms. @@ -87,7 +94,7 @@ class UploadFileInitialPost(AuthInitialPost): def __init__(self, settings={}): super().__init__(settings) - upload_fmt = constants.CSV + upload_fmt = CSV datafile = '' trim_upload = True @@ -136,9 +143,8 @@ class UploadFileWTForm(AuthWTForm): # look (and render) like html, but I'll define them anyway # just to keep my hand in. upload_fmt = RadioField('Upload Format:', - choices=[('Upload CSV Data:', constants.CSV), - ('Upload tab delimited Data:', - constants.TAB)]) + choices=[('Upload CSV Data:', CSV), + ('Upload tab delimited Data:', TAB)]) datafile = FileField('File with CSV or Tab delimited Data:') trim_upload = BooleanField('Trim Leading/Trailing Spaces:') @@ -396,23 +402,23 @@ class UploadFileForm(AuthLoadedForm): ''' Produces the dict pyramid will use to render the form. ''' - if self['upload_fmt'] == constants.CSV: - csv_checked = constants.CHECKED - tab_checked = constants.UNCHECKED + if self['upload_fmt'] == CSV: + csv_checked = CHECKED + tab_checked = UNCHECKED else: - tab_checked = constants.CHECKED - csv_checked = constants.UNCHECKED + tab_checked = CHECKED + csv_checked = UNCHECKED if self['trim_upload']: - trim_upload_checked = constants.CHECKED + trim_upload_checked = CHECKED else: - trim_upload_checked = constants.UNCHECKED + trim_upload_checked = UNCHECKED response = super(UploadFileForm, self).write(result, errors) response['filename'] = self['filename'] response['trim_upload'] = trim_upload_checked - response['csv_value'] = constants.CSV_VALUE - response['tab_value'] = constants.TAB_VALUE + response['csv_value'] = CSV_VALUE + response['tab_value'] = TAB_VALUE response['csv_checked'] = csv_checked response['tab_checked'] = tab_checked return response @@ -486,9 +492,9 @@ class UploadNullFileForm(UploadFileForm): Produces the dict pyramid will use to render the form. ''' if self['upload_null']: - upload_null_checked = constants.CHECKED + upload_null_checked = CHECKED else: - upload_null_checked = constants.UNCHECKED + upload_null_checked = UNCHECKED response = super(UploadNullFileForm, self).write(result, errors) response['upload_null'] = upload_null_checked @@ -578,7 +584,7 @@ def textualize(st): def is_checked(val): '''Is the value something a html input entity recognizes as checked?''' - return val == constants.CHECKED + return val == CHECKED # Some functions for logging @@ -1047,7 +1053,7 @@ class UploadData(DBData): # Give up eol = '' - if file_fmt == constants.CSV: + if file_fmt == CSV: def func(st): return next(csv_reader((st,))) else: @@ -1074,7 +1080,7 @@ class UploadData(DBData): self.cols = len(self.headers.tuples) # Create parser to read raw lines into a list - if file_fmt == constants.CSV: + if file_fmt == CSV: self._parser = lambda st: self._extend(st, next(csv_reader((st,)))) else: # Tab delimited format -- 2.34.1