From ed37ad45e4b9ae68c8688940b372d9f11ca8cf13 Mon Sep 17 00:00:00 2001
From: Sean Morley
Date: Fri, 4 Oct 2024 21:56:43 -0400
Subject: [PATCH] Being back /all view for map AdventureLink
---
backend/server/adventures/views.py | 26 +++++++++----------
.../src/lib/components/AdventureLink.svelte | 4 +--
.../src/lib/components/AdventureModal.svelte | 12 +++++----
frontend/src/routes/map/+page.server.ts | 4 +--
4 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/backend/server/adventures/views.py b/backend/server/adventures/views.py
index 7280c68..8c71ba3 100644
--- a/backend/server/adventures/views.py
+++ b/backend/server/adventures/views.py
@@ -129,23 +129,21 @@ class AdventureViewSet(viewsets.ModelViewSet):
def all(self, request):
if not request.user.is_authenticated:
return Response({"error": "User is not authenticated"}, status=400)
- # include_collections = request.query_params.get('include_collections', 'false')
- # if include_collections not in ['true', 'false']:
- # include_collections = 'false'
+ include_collections = request.query_params.get('include_collections', 'false')
+ if include_collections not in ['true', 'false']:
+ include_collections = 'false'
- # if include_collections == 'true':
- # queryset = Adventure.objects.filter(
- # Q(is_public=True) | Q(user_id=request.user.id)
- # )
- # else:
- # queryset = Adventure.objects.filter(
- # Q(is_public=True) | Q(user_id=request.user.id), collection=None
- # )
- allowed_types = ['visited', 'planned']
+ if include_collections == 'true':
+ queryset = Adventure.objects.filter(
+ Q(is_public=True) | Q(user_id=request.user.id)
+ )
+ else:
+ queryset = Adventure.objects.filter(
+ Q(is_public=True) | Q(user_id=request.user.id), collection=None
+ )
queryset = Adventure.objects.filter(
- Q(user_id=request.user.id) & Q(type__in=allowed_types)
+ Q(user_id=request.user.id)
)
-
queryset = self.apply_sorting(queryset)
serializer = self.get_serializer(queryset, many=True)
diff --git a/frontend/src/lib/components/AdventureLink.svelte b/frontend/src/lib/components/AdventureLink.svelte
index cb4551b..b1bb85f 100644
--- a/frontend/src/lib/components/AdventureLink.svelte
+++ b/frontend/src/lib/components/AdventureLink.svelte
@@ -19,14 +19,14 @@
if (modal) {
modal.showModal();
}
- let res = await fetch(`/api/adventures/?include_collections=false`, {
+ let res = await fetch(`/api/adventures/all/?include_collections=false`, {
method: 'GET'
});
const newAdventures = await res.json();
if (res.ok && adventures) {
- adventures = newAdventures.results;
+ adventures = newAdventures;
}
isLoading = false;
});
diff --git a/frontend/src/lib/components/AdventureModal.svelte b/frontend/src/lib/components/AdventureModal.svelte
index d8889d7..3f39b3e 100644
--- a/frontend/src/lib/components/AdventureModal.svelte
+++ b/frontend/src/lib/components/AdventureModal.svelte
@@ -736,11 +736,13 @@ it would also work to just use on:click on the MapLibre component itself. -->
timeZone: 'UTC'
})}
-
- {new Date(visit.end_date).toLocaleDateString(undefined, {
- timeZone: 'UTC'
- })}
-
+ {#if visit.end_date}
+
+ {new Date(visit.end_date).toLocaleDateString(undefined, {
+ timeZone: 'UTC'
+ })}
+
+ {/if}