Skip to content

Commit

Permalink
Move XP signal now that observations are updated directly
Browse files Browse the repository at this point in the history
  • Loading branch information
eleurent committed Oct 15, 2023
1 parent 4368d0c commit 7e425fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 0 additions & 6 deletions backend/nature_go/observation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.contrib.staticfiles import finders

from observation.models import Observation, Species
from user_profile.signals import xp_gained

class ObservationSerializer(serializers.ModelSerializer):
user = serializers.ReadOnlyField(source='user.username')
Expand All @@ -14,11 +13,6 @@ class Meta:
model = Observation
fields = ['id', 'user', 'image', 'organ', 'species', 'location', 'datetime', 'identification_response', 'xp']

def update(self, instance, validated_data):
super().update(instance, validated_data)
if not instance.xp and instance.species:
xp_gained.send(sender=instance.__class__, instance=instance)
return instance

class SpeciesSerializer(serializers.ModelSerializer):
illustration = Base64ImageField()
Expand Down
4 changes: 4 additions & 0 deletions backend/nature_go/observation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from observation.serializers import ObservationSerializer, SpeciesSerializer
from observation.permissions import IsOwner, IsAdminOrReadOnly
from observation import identification
from user_profile.signals import xp_gained

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -151,4 +152,7 @@ def update(self, request, *args, **kwargs):
defaults=species_data)
instance.species = species
instance.save()
if not instance.xp and instance.species:
xp_gained.send(sender=instance.__class__, instance=instance)

return Response(ObservationSerializer(instance).data)

0 comments on commit 7e425fc

Please sign in to comment.