Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

fix: track game load #1830

Merged
merged 20 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions aimmo/migrations/0037_worksheetusage_loaded_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.23 on 2023-11-10 16:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('aimmo', '0036_worksheetbadge'),
]

operations = [
migrations.AddField(
model_name='worksheetusage',
name='loaded_at',
field=models.DateTimeField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions aimmo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class WorksheetUsage(models.Model):
klass = models.ForeignKey(Class, null=True, blank=True, on_delete=models.SET_NULL)
worksheet_id = models.IntegerField()
created_at = models.DateTimeField(default=timezone.now)
loaded_at = models.DateTimeField(null=True, blank=True)


class WorksheetBadge(models.Model):
Expand Down
14 changes: 14 additions & 0 deletions aimmo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.db import transaction
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, JsonResponse
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django.views.decorators.csrf import ensure_csrf_cookie
from rest_framework import mixins, status, viewsets
from rest_framework.authentication import BasicAuthentication, SessionAuthentication
Expand Down Expand Up @@ -67,6 +68,19 @@ def badges(request, id):
avatar = Avatar.objects.create(game=game, owner=request.user)
avatar_user_profile = UserProfile.objects.get(user=avatar.owner)

worksheet_usage = (
WorksheetUsage.objects.filter(
user=request.user,
klass=game.game_class,
worksheet_id=game.worksheet_id,
)
.order_by("created_at")
.last()
)
if worksheet_usage and not worksheet_usage.loaded_at:
worksheet_usage.loaded_at = timezone.now()
worksheet_usage.save()

if request.method == "POST":
earned_badges = request.POST["badges"]

Expand Down