示例#1
0
 def test_bad_file_parsing(self):
     """
     test if the admin page with RelatedFieldRadioFilter filters loads succesfully
     """
     with self.assertRaises(ValidationError):
         with open("tests/test_data/test_bad_file.gpx", "r") as f:
             parse_gpx(f)
示例#2
0
 def test_bad_file_parsing(self):
     """
     test if the admin page with RelatedFieldRadioFilter filters loads succesfully
     """
     with self.assertRaises(ValidationError):
         with open("tests/test_data/test_bad_file.gpx", "r") as f:
             parse_gpx(f)
示例#3
0
 def test_gpx_parsing(self):
     """
     test if the admin page with RelatedFieldRadioFilter filters loads succesfully
     """
     with open("tests/test_data/test_track.gpx", "r") as f:
         multilinestring = parse_gpx(f)
     self.assertEquals(multilinestring.num_geom, 26)
     self.assertEquals(multilinestring.length, 0.31341761110953986)
示例#4
0
 def test_gpx_with_route(self):
     """
     test if the admin page with RelatedFieldRadioFilter filters loads succesfully
     """
     with open("tests/test_data/test_with_route.gpx", "r") as f:
         multilinestring = parse_gpx(f)
     self.assertEquals(multilinestring.num_geom, 1)
     self.assertEquals(multilinestring.length, 0.10557333372775202)
示例#5
0
 def test_gpx_parsing(self):
     """
     test if the admin page with RelatedFieldRadioFilter filters loads succesfully
     """
     with open("tests/test_data/test_track.gpx", "r") as f:
         multilinestring = parse_gpx(f)
     self.assertEquals(multilinestring.num_geom, 26)
     self.assertEquals(multilinestring.length, 0.31341761110953986)
示例#6
0
 def test_gpx_with_route(self):
     """
     test if the admin page with RelatedFieldRadioFilter filters loads succesfully
     """
     with open("tests/test_data/test_with_route.gpx", "r") as f:
         multilinestring = parse_gpx(f)
     self.assertEquals(multilinestring.num_geom, 1)
     self.assertEquals(multilinestring.length, 0.10557333372775202)
示例#7
0
def trip_pre_save(sender, instance, **kwargs):
    if instance.gpx_file and not instance.track:
        if instance.gpx_file.name.endswith(".gz"):
            track_file = gzip.open(instance.gpx_file)
        else:
            track_file = instance.gpx_file
        try:
            track_file = track_file.read().decode("utf-8")
        except UnicodeDecodeError:
            raise ValidationError({'gpx_file': _('Chyba při načítání GPX souboru. Jste si jistí, že jde o GPX soubor?')})
        instance.track = gpx_parse.parse_gpx(track_file)
    track = instance.track
    if not instance.distance and track:
        instance.distance = round(util.get_multilinestring_length(track), 2)
示例#8
0
 def clean(self):
     if self.file:
         if self.file.name.endswith(".gz"):
             track_file = gzip.open(self.file)
         else:
             track_file = self.file
         try:
             track_file = track_file.read().decode("utf-8")
         except UnicodeDecodeError:
             raise ValidationError({
                 "file":
                 _("Chyba při načítání GPX souboru. Jste si jistí, že jde o GPX soubor?"
                   )
             })
         self.track_clean = gpx_parse.parse_gpx(track_file)
示例#9
0
 def clean_parse_and_calculate_track(self):
     if 'gpx_file' in self.changed_data and self.cleaned_data['gpx_file']:
         if self.cleaned_data['gpx_file'].name.endswith(".gz"):
             track_file = gzip.open(self.cleaned_data['gpx_file'])
         else:
             track_file = self.cleaned_data['gpx_file']
         try:
             track_file = track_file.read().decode("utf-8")
         except UnicodeDecodeError:
             raise ValidationError({
                 'gpx_file':
                 _('Chyba při načítání GPX souboru. Jste si jistí, že jde o GPX soubor?'
                   )
             })
         self.cleaned_data['track'] = gpx_parse.parse_gpx(track_file)
         self.changed_data.append('track')
     if self.cleaned_data.get(
             'track', None) and ('track' in self.changed_data
                                 or not self.cleaned_data['distance']):
         self.cleaned_data['distance'] = round(
             util.get_multilinestring_length(self.cleaned_data['track']), 2)
     return self.cleaned_data
示例#10
0
 def clean_parse_and_calculate_track(self):
     if ("gpx_file" in self.changed_data and "gpx_file" in self.cleaned_data
             and self.cleaned_data["gpx_file"]):
         if self.cleaned_data["gpx_file"].name.endswith(".gz"):
             track_file = gzip.open(self.cleaned_data["gpx_file"])
         else:
             track_file = self.cleaned_data["gpx_file"]
         try:
             track_file = track_file.read().decode("utf-8")
         except UnicodeDecodeError:
             raise ValidationError({
                 "gpx_file":
                 _("Chyba při načítání GPX souboru. Jste si jistí, že jde o GPX soubor?"
                   )
             })
         self.cleaned_data["track"] = gpx_parse.parse_gpx(track_file)
         self.changed_data.append("track")
     if self.cleaned_data.get(
             "track", None) and ("track" in self.changed_data
                                 or not self.cleaned_data["distance"]):
         self.cleaned_data["distance"] = round(
             util.get_multilinestring_length(self.cleaned_data["track"]), 2)
     return self.cleaned_data