def save(self, commit=True): instance = super(LayerForm, self).save(commit=False) if instance.parse_file: geojson = json.loads(instance.json_file.read().decode('utf8')) return GeoJSONParser.geojson_to_db(geojson, return_instance=True) else: if commit: instance.save() return instance
def handle(self, *args, **options): # Organization Types print('Creating organization types...') for org_type in OrganizationType.ORG_TYPES: try: OrganizationType.objects.get(org_type=org_type[0]) except OrganizationType.DoesNotExist: obj = OrganizationType(org_type=org_type[0]) obj.save() except OrganizationType.MultipleObjectsReturned: pass # Polygons n Orgs if options['file']: geo_json = get_geojson_file(os.path.join( settings.INIT_GEOJSON_FOLDER, options['file'])) GeoJSONParser.geojson_to_db(geo_json) else: for geo_json_file in os.listdir(settings.INIT_GEOJSON_FOLDER): geo_json = get_geojson_file(os.path.join( settings.INIT_GEOJSON_FOLDER, geo_json_file)) GeoJSONParser.geojson_to_db(geo_json)
def save(self, *args, **kwargs): if self.json_file: from utils.geoparser import GeoJSONParser geojson = json.loads(self.json_file.read().decode('utf8')) GeoJSONParser.geojson_to_db(geojson)