Browse Source

backend.py: integrate license to public JSON file

Signed-off-by: KheOps <kheops@ceops.eu>
KheOps 9 years ago
parent
commit
e8be50bbca
1 changed files with 22 additions and 7 deletions
  1. 22 7
      backend.py

+ 22 - 7
backend.py

@@ -69,6 +69,8 @@ DB_COLS = (
 )
 
 GEOJSON_NAME = 'public.json'
+GEOJSON_LICENSE_TYPE = 'ODC-BY'
+GEOJSON_LICENSE_URL = 'http://opendatacommons.org/licenses/by/1.0/'
 
 ANTISPAM_FIELD = 'url'
 
@@ -277,13 +279,22 @@ def orientations_to_angle(orientations):
      return merge_intervals(angles)
 
 # Save feature collection to a json file
-def save_featurecollection_json(id, features):
+def save_featurecollection_json(id, features, licenses = None):
     with open('json/' + id + '.json', 'w') as outfile:
-        json.dump({
-            "type" : "FeatureCollection",
-            "features" : features,
-            "id" : id,
-        }, outfile)
+        if licenses == None:
+            json.dump({
+                "type" : "FeatureCollection",
+                "features" : features,
+                "id" : id,
+            }, outfile)
+        else:
+             json.dump({
+                "type" : "FeatureCollection",
+                "features" : features,
+                "id" : id,
+                "licenses" : licenses,
+            }, outfile)
+           
 
 # Build GeoJSON files from DB
 def build_geojson():
@@ -363,7 +374,11 @@ def build_geojson():
 
     # Build GeoJSON Feature Collection
     save_featurecollection_json('private', private_features)
-    save_featurecollection_json('public', public_features)
+    public_json_licenses = {
+        "type" : GEOJSON_LICENSE_TYPE,
+        "url" : GEOJSON_LICENSE_URL
+    }
+    save_featurecollection_json('public', public_features, public_json_licenses)