Skip to content

Commit

Permalink
Remove unnecessary user field from geotag
Browse files Browse the repository at this point in the history
  • Loading branch information
alastair committed Jan 31, 2025
1 parent c4ecb19 commit 0405599
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion accounts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def setUp(self):
self.sound.moderation_state = "OK"
self.sound.processing_state = "OK"
self.sound.similarity_state = "OK"
self.sound.geotag = GeoTag.objects.create(user=user, lat=45.8498, lon=-62.6879, zoom=9)
self.sound.geotag = GeoTag.objects.create(lat=45.8498, lon=-62.6879, zoom=9)
self.sound.save()
SoundOfTheDay.objects.create(sound=self.sound, date_display=datetime.date.today())
self.download = Download.objects.create(user=self.user, sound=self.sound, license=self.sound.license,
Expand Down
3 changes: 1 addition & 2 deletions apiv2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,11 +943,10 @@ def post(self, request, *args, **kwargs):
if 'geotag' in serializer.data:
if serializer.data['geotag']:
lat, lon, zoom = serializer.data['geotag'].split(',')
geotag = GeoTag(user=self.user,
geotag = GeoTag.objects.create(
lat=float(lat),
lon=float(lon),
zoom=int(zoom))
geotag.save()
sound.geotag = geotag
if 'pack' in serializer.data:
if serializer.data['pack']:
Expand Down
17 changes: 17 additions & 0 deletions geotags/migrations/0006_remove_geotag_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.23 on 2025-01-30 20:10

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('geotags', '0005_alter_geotag_information'),
]

operations = [
migrations.RemoveField(
model_name='geotag',
name='user',
),
]
9 changes: 4 additions & 5 deletions geotags/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@


class GeoTag(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
lat = models.FloatField(db_index=True)
lon = models.FloatField(db_index=True)
zoom = models.IntegerField()
Expand All @@ -40,14 +39,14 @@ class GeoTag(models.Model):
created = models.DateTimeField(db_index=True, auto_now_add=True)

def __str__(self):
return f"{self.user} ({self.lat:f},{self.lon:f})"
return f"({self.lat:f},{self.lon:f})"

def get_absolute_url(self):
return reverse('geotag', args=[smart_str(self.id)])

def retrieve_location_information(self):
"""Use the mapbox API to retrieve information about the latitude and longitude of this geotag.
If no iformation has been retrieved from mapbox and a mapbox access token is available, retrieve and
If no information has been retrieved from mapbox and a mapbox access token is available, retrieve and
store that information. Then, pre-process that information to save a place name for display purposes.
"""
if settings.MAPBOX_ACCESS_TOKEN and (self.information is None or self.should_update_information):
Expand All @@ -67,11 +66,11 @@ def retrieve_location_information(self):
# Try with "place" feature
self.location_name = [feature for feature in features if 'place' in feature['place_type']][0]['place_name']
except IndexError:
# If "place" feature is not avialable, use "locality" feature
# If "place" feature is not available, use "locality" feature
try:
self.location_name = [feature for feature in features if 'locality' in feature['place_type']][0]['place_name']
except IndexError:
# If "place" nor "locality" features are avialable, use "region"
# If "place" nor "locality" features are available, use "region"
try:
self.location_name = [feature for feature in features if 'region' in feature['place_type']][0]['place_name']
except:
Expand Down
4 changes: 2 additions & 2 deletions geotags/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_browse_geotags_for_user_deleted_user(self):

def test_geotags_infowindow(self):
sound = Sound.objects.first()
gt = GeoTag.objects.create(user=sound.user, lat=45.8498, lon=-62.6879, zoom=9)
gt = GeoTag.objects.create(lat=45.8498, lon=-62.6879, zoom=9)
sound.geotag = gt
sound.save()
resp = self.client.get(reverse('geotags-infowindow', kwargs={'sound_id': sound.id}))
Expand All @@ -82,7 +82,7 @@ def test_browse_geotags_case_insensitive(self):
sounds[1].set_tags([tag])
sounds[0].set_tags([tag.upper()])

gt = GeoTag.objects.create(user=user, lat=45.8498, lon=-62.6879, zoom=9)
gt = GeoTag.objects.create(lat=45.8498, lon=-62.6879, zoom=9)
for sound in sounds:
sound.geotag = gt
sound.save()
Expand Down
2 changes: 1 addition & 1 deletion sounds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def update_edited_sound(sound, data):
sound.geotag.save()
else:
sound.geotag = GeoTag.objects.create(
lat=data["lat"], lon=data["lon"], zoom=data["zoom"], user=request.user)
lat=data["lat"], lon=data["lon"], zoom=data["zoom"])

sound_sources = data["sources"]
if sound_sources != sound.get_sound_sources_as_set():
Expand Down
18 changes: 8 additions & 10 deletions utils/sound_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,21 @@ def create_sound(user,
# Create geotag from lat,lon,zoom text format
if sound_fields['geotag']:
lat, lon, zoom = sound_fields['geotag'].split(',')
geotag = GeoTag(user=user,
lat=float(lat),
lon=float(lon),
zoom=int(zoom))
geotag.save()
geotag = GeoTag.objects.create(
lat=float(lat),
lon=float(lon),
zoom=int(zoom))
sound.geotag = geotag
else:
# Create geotag from lat, lon, zoom separated fields (if available)
lat = sound_fields.get('lat', None)
lon = sound_fields.get('lon', None)
zoom = sound_fields.get('zoom', None)
if lat is not None and lon is not None and zoom is not None:
geotag = GeoTag(user=user,
lat=float(lat),
lon=float(lon),
zoom=int(zoom))
geotag.save()
geotag = GeoTag.objects.create(
lat=float(lat),
lon=float(lon),
zoom=int(zoom))
sound.geotag = geotag

# 6 set description, tags
Expand Down

0 comments on commit 0405599

Please sign in to comment.