From 34cb91c7bb4f49156e60d3b67318834c10f8d0f0 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 20 Feb 2014 15:07:55 -0600 Subject: Committer: root On branch master --- wqflask/maintenance/dataset/utilities.py | 36 ++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/wqflask/maintenance/dataset/utilities.py b/wqflask/maintenance/dataset/utilities.py index fac24943..d389e672 100644 --- a/wqflask/maintenance/dataset/utilities.py +++ b/wqflask/maintenance/dataset/utilities.py @@ -41,29 +41,47 @@ def overlap(dic1, dic2): values2.append(value2) return keys, values1, values2 -def to_db_string_null(s): +def to_db_string(s, default): if s: s = s.strip() if len(s) == 0: - return None + return default elif s == 'x': - return None + return default else: return s else: - return None + return default -def to_db_string_empty(s): +def to_db_float(s, default): if s: s = s.strip() if len(s) == 0: - return '' + return default elif s == 'x': - return '' + return default else: - return s + try: + return float(s) + except: + return default else: - return '' + return default + +def to_db_int(s, default): + if s: + s = s.strip() + if len(s) == 0: + return default + elif s == 'x': + return default + else: + try: + return int(s) + except: + return default + else: + return default def get_config(configfile): config = ConfigParser.ConfigParser() -- cgit v1.2.3