1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 04:49:37 +02:00

Region check - frontend

This commit is contained in:
Sean Morley 2024-08-23 18:41:59 -04:00
parent c13d6f4f21
commit dab6efbe32
2 changed files with 26 additions and 1 deletions

View file

@ -54,7 +54,7 @@ class CountryViewSet(viewsets.ReadOnlyModelViewSet):
# make a post action that will get all of the users adventures and check if the point is in any of the regions if so make a visited region object for that user if it does not already exist
@action(detail=False, methods=['post'])
def region_check_all_adventures(self, request):
adventures = Adventure.objects.filter(user_id=request.user.id)
adventures = Adventure.objects.filter(user_id=request.user.id, type='visited')
count = 0
for adventure in adventures:
if adventure.latitude is not None and adventure.longitude is not None:

View file

@ -44,6 +44,21 @@
a.click();
URL.revokeObjectURL(url);
}
async function checkVisitedRegions() {
let res = await fetch('/api/countries/region_check_all_adventures/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
});
let data = await res.json();
if (res.ok) {
addToast('success', `${data.regions_visited} regions updated`);
} else {
addToast('error', 'Error updating visited regions');
}
}
</script>
<h1 class="text-center font-extrabold text-4xl mb-6">Settings Page</h1>
@ -157,6 +172,16 @@
<button class="btn btn-neutral mb-4" on:click={exportAdventures}> Export to JSON </button>
<p>This may take a few seconds...</p>
</div>
<div class="flex flex-col items-center">
<h1 class="text-center font-extrabold text-xl mt-4 mb-2">Visited Region Check</h1>
<p>
By selecting this, the server will check all of your visited adventures and mark the regions
they are located in as "visited" in world travel.
</p>
<button class="btn btn-neutral mb-4" on:click={checkVisitedRegions}>Update Visited Regions</button
>
<p>This may take longer depending on the number of adventures you have.</p>
</div>
<small class="text-center"
><b>For Debug Use:</b> Server PK={user.pk} | Date Joined: {user.date_joined