Skip to content

Commit

Permalink
fix: track game load (#1830)
Browse files Browse the repository at this point in the history
* fix: track worksheet usage

* fix: track worksheet badges

* make user nullable

* remove unused args

* Merge branch 'worksheet_usage' into worksheet_badges

* remove unused args

* silence pylint unused arg error

* silence pylint unused arg error

* quick save

* fix: worksheet usage

* merge

* simplify

* merge

* migration

* relock

* Merge branch 'worksheet_usage' into worksheet_badges

* Merge branch 'worksheet_badges' into game_load

* save loaded time

* merge from master

* Merge branch 'master' into game_load
  • Loading branch information
SKairinos committed Nov 14, 2023
1 parent 5572800 commit 166ca93
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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

0 comments on commit 166ca93

Please sign in to comment.