From eab236935269d9d7a042261cbbed79655fc0b7bf Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Mon, 9 Sep 2024 23:47:09 -0400 Subject: [PATCH] Fix is_public mismatching --- backend/server/adventures/views.py | 13 +++++++++---- frontend/src/routes/worldtravel/+page.svelte | 6 +++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/server/adventures/views.py b/backend/server/adventures/views.py index fb5d220..7d2a136 100644 --- a/backend/server/adventures/views.py +++ b/backend/server/adventures/views.py @@ -204,8 +204,11 @@ class AdventureViewSet(viewsets.ModelViewSet): serializer.is_valid(raise_exception=True) # if the adventure is trying to have is_public changed and its part of a collection return an error - if 'is_public' in serializer.validated_data and instance.collection: - return Response({"error": "Cannot change is_public for adventures in a collection"}, status=400) + if new_collection is not None: + serializer.validated_data['is_public'] = new_collection.is_public + elif instance.collection: + serializer.validated_data['is_public'] = instance.collection.is_public + # Retrieve the collection from the validated data new_collection = serializer.validated_data.get('collection') @@ -243,8 +246,10 @@ class AdventureViewSet(viewsets.ModelViewSet): print(new_collection) # if the adventure is trying to have is_public changed and its part of a collection return an error - if 'is_public' in serializer.validated_data and instance.collection: - return Response({"error": "Cannot change is_public for adventures in a collection"}, status=400) + if new_collection is not None: + serializer.validated_data['is_public'] = new_collection.is_public + elif instance.collection: + serializer.validated_data['is_public'] = instance.collection.is_public if new_collection is not None and new_collection!=instance.collection: # Check if the user is the owner of the new collection diff --git a/frontend/src/routes/worldtravel/+page.svelte b/frontend/src/routes/worldtravel/+page.svelte index 8748a67..48a1b54 100644 --- a/frontend/src/routes/worldtravel/+page.svelte +++ b/frontend/src/routes/worldtravel/+page.svelte @@ -25,7 +25,11 @@ } -

Country List

+

Country List

+ +

+ {filteredCountries.length} countries found +