def save(self, *args, **kwargs): suffix = os.path.splitext(self.track.path)[1] track_string = self.track.read() if suffix in ['.json', '.geojson']: timestamp, geojson = None, track_string elif suffix == '.tcx': timestamp, geojson = convert_tcx(track_string) elif suffix == '.gpx': timestamp, geojson = convert_gpx(track_string) else: raise Exception('Unknown format') if not self.geojson_id: geojson = GeoJson(pk=self.pk, geojson=geojson) geojson.save() self.geojson = geojson else: self.geojson.geojson = geojson self.geojson.save() # save track object if timestamp: self.timestamp = timestamp super(Track, self).save(*args, **kwargs)
def handle(self, *args, **options): suffix = os.path.splitext(options['trackfile'])[1] trackfile_handler = open(options['trackfile']).read() if suffix == '.tcx': timestamp, geojson = convert_tcx(trackfile_handler) elif suffix == '.gpx': timestamp, geojson = convert_gpx(trackfile_handler) else: raise Exception('Unknown format') print geojson