Compare commits

..

No commits in common. "6d53fca910d49897c1d5637cca978a12db76643a" and "b29e4edd72efb81d4d55af4e0111dbdfbb4dc613" have entirely different histories.

2 changed files with 7 additions and 16 deletions

View File

@ -1,6 +1,3 @@
import logging
from datetime import timedelta
from django.db.models import F, Sum
from django.db.models.signals import m2m_changed, post_delete, post_save, pre_save
from django.dispatch import receiver
@ -8,8 +5,6 @@ from django.utils.timezone import now
from games.models import Game, GameStatusChange, Purchase, Session
logger = logging.getLogger("games")
@receiver(m2m_changed, sender=Purchase.games.through)
def update_num_purchases(sender, instance, **kwargs):
@ -24,7 +19,7 @@ def update_game_playtime(sender, instance, **kwargs):
total_playtime = game.sessions.aggregate(
total_playtime=Sum(F("duration_calculated") + F("duration_manual"))
)["total_playtime"]
game.playtime = total_playtime if total_playtime else timedelta(0)
game.playtime = total_playtime if total_playtime else 0
game.save(update_fields=["playtime"])
@ -36,18 +31,14 @@ def game_status_changed(sender, instance, **kwargs):
try:
old_instance = sender.objects.get(pk=instance.pk)
old_status = old_instance.status
logger.info("[game_status_changed]: Previous status exists.")
print("Got old instance")
except sender.DoesNotExist:
# Handle the case where the instance was deleted before the signal was sent
logger.info("[game_status_changed]: Previous status does not exist.")
print("Instance does not exist")
return
if old_status != instance.status:
logger.info(
"[game_status_changed]: Status changed from {} to {}".format(
old_status, instance.status
)
)
print("Status changed")
GameStatusChange.objects.create(
game=instance,
old_status=old_status,
@ -55,4 +46,6 @@ def game_status_changed(sender, instance, **kwargs):
timestamp=instance.updated_at,
)
else:
logger.info("[game_status_changed]: Status has not changed")
print("Status not changed")
print(f"{old_instance.status}")
print(f"{instance.status}")

View File

@ -115,8 +115,6 @@ def add_playevent(request: HttpRequest, game_id: int = 0) -> HttpResponse:
# coming from add_playevent_for_game url path
game = get_object_or_404(Game, id=game_id)
initial["game"] = game
initial["started"] = game.sessions.earliest().timestamp_start
initial["ended"] = game.sessions.latest().timestamp_start
form = PlayEventForm(request.POST or None, initial=initial)
if form.is_valid():
form.save()