-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add form to import data #97
Labels
Comments
Bout de code que j'ai écrit pour un autre projet dont on peut éventuellement s'inspirer: def from_native(self, data, files=None):
"""Read a zip file containing a shapefile"""
if files is None:
return None
try:
unzipped = zipfile.ZipFile(files['file'])
except zipfile.BadZipFile:
self._errors = "Should be a .zip file."
return
tmpdir = tempfile.mkdtemp()
try:
unzipped.extractall(tmpdir)
srs = SpatialReference(settings.COMPASS_DEFAULT_SRID)
shp_name = None
for name in unzipped.namelist():
fullname = os.path.join(tmpdir, name)
if os.path.splitext(name)[1].lower() == '.shp':
shp_name = fullname
if os.path.splitext(name)[1].lower() == '.prj':
srs = None
if shp_name is None:
self._errors = "The .zip file should contain a .shp file."
return
points = []
try:
lm = LayerMapping(Point, shp_name,
{'name': 'name', 'point': 'POINT'},
source_srs=srs)
except LayerMapError:
lm = LayerMapping(Point, shp_name, {'point': 'POINT'},
source_srs=srs)
def faked_save(point, **kwargs):
point.user = self.context['request'].user
points.append(point)
with patch.object(Point, 'save', faked_save):
lm.save()
finally:
shutil.rmtree(tmpdir)
return points |
Je retombe sur ça et je me pose une question du coup. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Besoins :
Specs :
Notes :
The text was updated successfully, but these errors were encountered: