mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 06:19:38 +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):
|
def all(self, request):
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
return Response({"error": "User is not authenticated"}, status=400)
|
return Response({"error": "User is not authenticated"}, status=400)
|
||||||
# include_collections = request.query_params.get('include_collections', 'false')
|
include_collections = request.query_params.get('include_collections', 'false')
|
||||||
# if include_collections not in ['true', 'false']:
|
if include_collections not in ['true', 'false']:
|
||||||
# include_collections = 'false'
|
include_collections = 'false'
|
||||||
|
|
||||||
# if include_collections == 'true':
|
if include_collections == 'true':
|
||||||
# queryset = Adventure.objects.filter(
|
queryset = Adventure.objects.filter(
|
||||||
# Q(is_public=True) | Q(user_id=request.user.id)
|
Q(is_public=True) | Q(user_id=request.user.id)
|
||||||
# )
|
)
|
||||||
# else:
|
else:
|
||||||
# queryset = Adventure.objects.filter(
|
queryset = Adventure.objects.filter(
|
||||||
# Q(is_public=True) | Q(user_id=request.user.id), collection=None
|
Q(is_public=True) | Q(user_id=request.user.id), collection=None
|
||||||
# )
|
)
|
||||||
allowed_types = ['visited', 'planned']
|
|
||||||
queryset = Adventure.objects.filter(
|
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)
|
queryset = self.apply_sorting(queryset)
|
||||||
serializer = self.get_serializer(queryset, many=True)
|
serializer = self.get_serializer(queryset, many=True)
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
if (modal) {
|
if (modal) {
|
||||||
modal.showModal();
|
modal.showModal();
|
||||||
}
|
}
|
||||||
let res = await fetch(`/api/adventures/?include_collections=false`, {
|
let res = await fetch(`/api/adventures/all/?include_collections=false`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
});
|
});
|
||||||
|
|
||||||
const newAdventures = await res.json();
|
const newAdventures = await res.json();
|
||||||
|
|
||||||
if (res.ok && adventures) {
|
if (res.ok && adventures) {
|
||||||
adventures = newAdventures.results;
|
adventures = newAdventures;
|
||||||
}
|
}
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -736,11 +736,13 @@ it would also work to just use on:click on the MapLibre component itself. -->
|
||||||
timeZone: 'UTC'
|
timeZone: 'UTC'
|
||||||
})}
|
})}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
{#if visit.end_date}
|
||||||
{new Date(visit.end_date).toLocaleDateString(undefined, {
|
<p>
|
||||||
timeZone: 'UTC'
|
{new Date(visit.end_date).toLocaleDateString(undefined, {
|
||||||
})}
|
timeZone: 'UTC'
|
||||||
</p>
|
})}
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -8,7 +8,7 @@ export const load = (async (event) => {
|
||||||
if (!event.locals.user) {
|
if (!event.locals.user) {
|
||||||
return redirect(302, '/login');
|
return redirect(302, '/login');
|
||||||
} else {
|
} else {
|
||||||
let visitedFetch = await fetch(`${endpoint}/api/adventures/`, {
|
let visitedFetch = await fetch(`${endpoint}/api/adventures/all/?include_collections=true`, {
|
||||||
headers: {
|
headers: {
|
||||||
Cookie: `${event.cookies.get('auth')}`
|
Cookie: `${event.cookies.get('auth')}`
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ export const load = (async (event) => {
|
||||||
let visited: Adventure[] = [];
|
let visited: Adventure[] = [];
|
||||||
try {
|
try {
|
||||||
let api_result = await visitedFetch.json();
|
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) {
|
if (!Array.isArray(visited) || visited.length === 0 || !visited) {
|
||||||
throw new Error('Visited adventures response is not an array');
|
throw new Error('Visited adventures response is not an array');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue