mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 14:29:36 +02:00
Being back /all view for map AdventureLink
This commit is contained in:
parent
f354cd1ffe
commit
ed37ad45e4
4 changed files with 23 additions and 23 deletions
|
@ -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(user_id=request.user.id) & Q(type__in=allowed_types)
|
||||
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)
|
||||
)
|
||||
|
||||
queryset = self.apply_sorting(queryset)
|
||||
serializer = self.get_serializer(queryset, many=True)
|
||||
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -736,11 +736,13 @@ it would also work to just use on:click on the MapLibre component itself. -->
|
|||
timeZone: 'UTC'
|
||||
})}
|
||||
</p>
|
||||
{#if visit.end_date}
|
||||
<p>
|
||||
{new Date(visit.end_date).toLocaleDateString(undefined, {
|
||||
timeZone: 'UTC'
|
||||
})}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
<button
|
||||
|
|
|
@ -8,7 +8,7 @@ export const load = (async (event) => {
|
|||
if (!event.locals.user) {
|
||||
return redirect(302, '/login');
|
||||
} else {
|
||||
let visitedFetch = await fetch(`${endpoint}/api/adventures/`, {
|
||||
let visitedFetch = await fetch(`${endpoint}/api/adventures/all/?include_collections=true`, {
|
||||
headers: {
|
||||
Cookie: `${event.cookies.get('auth')}`
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ export const load = (async (event) => {
|
|||
let visited: Adventure[] = [];
|
||||
try {
|
||||
let api_result = await visitedFetch.json();
|
||||
visited = api_result.results as Adventure[];
|
||||
visited = api_result as Adventure[];
|
||||
if (!Array.isArray(visited) || visited.length === 0 || !visited) {
|
||||
throw new Error('Visited adventures response is not an array');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue