소스 검색

添加默认值

gushoubang 9 달 전
부모
커밋
e39ab443ae
1개의 변경된 파일15개의 추가작업 그리고 8개의 파일을 삭제
  1. 15 8
      app.py

+ 15 - 8
app.py

@@ -21,8 +21,8 @@ conn = psycopg2.connect(
     dbname="real3d",
     user="postgres",
     password="postgis",
-    # host="192.168.100.30",
-    host="192.168.60.2",
+    host="192.168.100.30",
+    # host="192.168.60.2",
     port="5432"
 )
 
@@ -33,6 +33,8 @@ def home():
     return render_template('index.html')
 
 # 后台接口
+
+
 @app.route("/hello")
 def hello():
     return "Hello, World!"
@@ -220,6 +222,10 @@ def jsonResToDict(json_res):
         conditionInfo = factorInfo["condition_info"]
         conditionObj = json.loads(conditionInfo)
 
+        defaultValue = str(factor["value"])
+        if defaultValue == '':
+            defaultValue = '0'
+
         factor_info = {
             "id": factorId,
             "name": factor["type"],
@@ -228,7 +234,7 @@ def jsonResToDict(json_res):
                 "spatial_type": conditionObj["spatial_type"],
                 "default": factor["condition"],
                 "hasValue": conditionObj["hasValue"],
-                "defaultValue": str(factor["value"]),
+                "defaultValue": defaultValue,
                 "unit": conditionObj["unit"],
                 "clip": conditionObj["clip"]
             }
@@ -240,12 +246,13 @@ def jsonResToDict(json_res):
         if factorId in input_factors:
             res["yxyz"].append(input_factors[factorId])
         else:
-            factorTemplate["conditionInfo"]=json.loads(factorTemplate["conditionInfo"])
+            factorTemplate["conditionInfo"] = json.loads(
+                factorTemplate["conditionInfo"])
             res["yxyz"].append(factorTemplate)
-    resObj={}
-    resObj["data"]=res
-    resObj["code"]=200
-    resObj["type"]="selectLand"
+    resObj = {}
+    resObj["data"] = res
+    resObj["code"] = 200
+    resObj["type"] = "selectLand"
     return resObj
 
 # 获取因子信息