@@ -286,7 +286,6 @@ def get_serializer_class(self):
286
286
return HDXExportRegionSerializer
287
287
288
288
def perform_create (self , serializer ):
289
-
290
289
serializer .save ()
291
290
if settings .SYNC_TO_HDX :
292
291
sync_region (serializer .instance )
@@ -617,96 +616,114 @@ def request_geonames(request):
617
616
618
617
if geonames_url :
619
618
keyword = request .GET .get ("q" )
620
- response = {'totalResultsCount' : 0 , 'geonames' : []}
621
- if not (str (keyword ).lower ().startswith ('boundary' ) or str (keyword ).lower ().startswith ('osm' ) or str (keyword ).lower ().startswith ('tm' )):
619
+ response = {"totalResultsCount" : 0 , "geonames" : []}
620
+ if not (
621
+ str (keyword ).lower ().startswith ("boundary" )
622
+ or str (keyword ).lower ().startswith ("osm" )
623
+ or str (keyword ).lower ().startswith ("tm" )
624
+ ):
622
625
response = requests .get (geonames_url , params = payload ).json ()
623
626
print (response )
624
627
assert isinstance (response , dict )
625
628
if RAW_DATA_API_URL :
626
- if str (keyword ).lower ().startswith (' boundary' ):
627
- lst = keyword .split (" " )
628
- if len (lst )> 1 :
629
- keyword = lst [1 ]
629
+ if str (keyword ).lower ().startswith (" boundary" ):
630
+ lst = keyword .split (" " )
631
+ if len (lst ) > 1 :
632
+ keyword = lst [1 ]
630
633
res = requests .get (f"{ RAW_DATA_API_URL } v1/countries/?q={ keyword } " )
631
634
if res .ok :
632
635
if len (res .json ()["features" ]) >= 1 :
633
636
for feature in res .json ()["features" ]:
634
637
geojson = {
635
- "type" : "FeatureCollection" ,
636
- "features" : [
637
- {"type" : "Feature" , "properties" : {}, "geometry" :feature ["geometry" ]}
638
- ],
639
- }
638
+ "type" : "FeatureCollection" ,
639
+ "features" : [
640
+ {
641
+ "type" : "Feature" ,
642
+ "properties" : {},
643
+ "geometry" : feature ["geometry" ],
644
+ }
645
+ ],
646
+ }
640
647
add_resp = {
641
648
"bbox" : geojson ,
642
- "adminName2" : feature ["properties" ]["description" ],
643
- "name" : f'{ request .GET .get ("q" )} -> { feature ["properties" ]["name" ]} ' ,
644
- "countryName" : feature ["properties" ]["dataset_name" ],
645
- "adminName1" : feature ["properties" ]["id" ],
649
+ "adminName2" : feature ["properties" ]["iso_3" ],
650
+ "name" : f'{ request .GET .get ("q" )} -> { feature ["properties" ]["description" ]} ' ,
651
+ "countryName" : feature ["properties" ][
652
+ "dataset_name"
653
+ ],
654
+ "adminName1" : feature ["properties" ]["cid" ],
646
655
}
647
-
656
+
648
657
if "geonames" in response :
649
658
response ["geonames" ].append (add_resp )
650
659
651
- if str (keyword ).lower ().startswith ('osm' ):
652
- lst = keyword .split (" " )
653
- if len (lst )>= 1 :
654
- keyword = lst [1 ]
655
- try :
656
- osm_id = int (keyword )
657
- res = requests .get (f"{ RAW_DATA_API_URL } v1/osm_id/?osm_id={ osm_id } " )
660
+ if str (keyword ).lower ().startswith ("osm" ):
661
+ lst = keyword .split (" " )
662
+ if len (lst ) >= 1 :
663
+ keyword = lst [1 ]
664
+ try :
665
+ osm_id = int (keyword )
666
+ res = requests .get (
667
+ f"{ RAW_DATA_API_URL } v1/osm_id/?osm_id={ osm_id } "
668
+ )
658
669
if res .ok :
659
670
if len (res .json ()["features" ]) >= 1 :
660
671
for feature in res .json ()["features" ]:
661
672
geojson = {
662
- "type" : "FeatureCollection" ,
663
- "features" : [
664
- {"type" : "Feature" , "properties" : {}, "geometry" : feature ["geometry" ]}
665
- ],
666
- }
673
+ "type" : "FeatureCollection" ,
674
+ "features" : [
675
+ {
676
+ "type" : "Feature" ,
677
+ "properties" : {},
678
+ "geometry" : feature ["geometry" ],
679
+ }
680
+ ],
681
+ }
667
682
add_resp = {
668
683
"bbox" : geojson ,
669
684
"adminName2" : "OSM" ,
670
685
"name" : request .GET .get ("q" ),
671
686
"countryName" : osm_id ,
672
687
"adminName1" : "Element" ,
673
688
}
674
-
689
+
675
690
if "geonames" in response :
676
691
response ["geonames" ].append (add_resp )
677
- except :
692
+ except :
678
693
pass
679
694
680
-
681
- if str (keyword ).lower ().startswith ('tm' ):
682
- lst = keyword .split (" " )
683
- if len (lst )>= 1 :
684
-
685
- keyword = lst [1 ]
686
- if tm_url :
687
- tm_res = requests .get (f"{ tm_url } /{ int (keyword )} /" )
688
- if tm_res .ok :
689
- tm_res = tm_res .json ()
690
- if "areaOfInterest" in tm_res :
691
- print ("TM Project found" )
692
- geom = tm_res ["areaOfInterest" ]
693
- geojson = {
694
- "type" : "FeatureCollection" ,
695
- "features" : [
696
- {"type" : "Feature" , "properties" : {}, "geometry" : geom }
697
- ],
698
- }
699
-
700
- add_resp = {
701
- "bbox" : geojson ,
702
- "adminName2" : "TM" ,
703
- "name" : request .GET .get ("q" ),
704
- "countryName" : "Boundary" ,
705
- "adminName1" : "Project" ,
706
- }
707
- # print(add_resp)
708
- if "geonames" in response :
709
- response ["geonames" ].append (add_resp )
695
+ if str (keyword ).lower ().startswith ("tm" ):
696
+ lst = keyword .split (" " )
697
+ if len (lst ) >= 1 :
698
+ keyword = lst [1 ]
699
+ if tm_url :
700
+ tm_res = requests .get (f"{ tm_url } /{ int (keyword )} /" )
701
+ if tm_res .ok :
702
+ tm_res = tm_res .json ()
703
+ if "areaOfInterest" in tm_res :
704
+ print ("TM Project found" )
705
+ geom = tm_res ["areaOfInterest" ]
706
+ geojson = {
707
+ "type" : "FeatureCollection" ,
708
+ "features" : [
709
+ {
710
+ "type" : "Feature" ,
711
+ "properties" : {},
712
+ "geometry" : geom ,
713
+ }
714
+ ],
715
+ }
716
+
717
+ add_resp = {
718
+ "bbox" : geojson ,
719
+ "adminName2" : "TM" ,
720
+ "name" : request .GET .get ("q" ),
721
+ "countryName" : "Boundary" ,
722
+ "adminName1" : "Project" ,
723
+ }
724
+ # print(add_resp)
725
+ if "geonames" in response :
726
+ response ["geonames" ].append (add_resp )
710
727
711
728
return JsonResponse (response )
712
729
else :
0 commit comments