Compare commits
5 Commits
6d53fca910
...
main
Author | SHA1 | Date | |
---|---|---|---|
5cc1652002
|
|||
7cf2180192
|
|||
ad0641f95b
|
|||
abdcfdfe64
|
|||
31daf2efe0
|
@ -1,4 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.db import transaction
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from common.utils import safe_getattr
|
from common.utils import safe_getattr
|
||||||
@ -227,19 +228,30 @@ class PlayEventForm(forms.ModelForm):
|
|||||||
widget=forms.Select(attrs={"autofocus": "autofocus"}),
|
widget=forms.Select(attrs={"autofocus": "autofocus"}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mark_as_finished = forms.BooleanField(
|
||||||
|
required=False,
|
||||||
|
initial={"mark_as_finished": True},
|
||||||
|
label="Set game status to Finished",
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PlayEvent
|
model = PlayEvent
|
||||||
fields = [
|
fields = ["game", "started", "ended", "note", "mark_as_finished"]
|
||||||
"game",
|
|
||||||
"started",
|
|
||||||
"ended",
|
|
||||||
"note",
|
|
||||||
]
|
|
||||||
widgets = {
|
widgets = {
|
||||||
"started": custom_date_widget,
|
"started": custom_date_widget,
|
||||||
"ended": custom_date_widget,
|
"ended": custom_date_widget,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
with transaction.atomic():
|
||||||
|
session = super().save(commit=False)
|
||||||
|
if self.cleaned_data.get("mark_as_finished"):
|
||||||
|
game_instance = session.game
|
||||||
|
game_instance.status = "f"
|
||||||
|
game_instance.save()
|
||||||
|
session.save()
|
||||||
|
return session
|
||||||
|
|
||||||
|
|
||||||
class GameStatusChangeForm(forms.ModelForm):
|
class GameStatusChangeForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -52,7 +52,7 @@ def game_status_changed(sender, instance, **kwargs):
|
|||||||
game=instance,
|
game=instance,
|
||||||
old_status=old_status,
|
old_status=old_status,
|
||||||
new_status=instance.status,
|
new_status=instance.status,
|
||||||
timestamp=instance.updated_at,
|
timestamp=now(),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.info("[game_status_changed]: Status has not changed")
|
logger.info("[game_status_changed]: Status has not changed")
|
||||||
|
@ -167,7 +167,7 @@
|
|||||||
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">
|
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">
|
||||||
<c-gamelink :game_id=game.id :name=game.name />
|
<c-gamelink :game_id=game.id :name=game.name />
|
||||||
</td>
|
</td>
|
||||||
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">{{ game.playtime | format_duration }}</td>
|
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">{{ game.total_playtime | format_duration }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
<span x-text="played"></span> times
|
<span x-text="played"></span> times
|
||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
<button type="button" x-on:click="open = !open" class="relative px-4 py-2 text-sm font-medium text-gray-900 bg-white border-e border-b border-t border-gray-200 rounded-e-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white align-middle">
|
<button type="button" x-on:click="open = !open" @click.outside="open = false" class="relative px-4 py-2 text-sm font-medium text-gray-900 bg-white border-e border-b border-t border-gray-200 rounded-e-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white align-middle">
|
||||||
<svg class="text-white w-3" viewBox="5 8 14 8" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg class="text-white w-3" viewBox="5 8 14 8" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M6 9L12 15L18 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
<path d="M6 9L12 15L18 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
@ -364,9 +364,16 @@ def stats(request: HttpRequest, year: int = 0) -> HttpResponse:
|
|||||||
)
|
)
|
||||||
total_spent = this_year_spendings["total_spent"] or 0
|
total_spent = this_year_spendings["total_spent"] or 0
|
||||||
|
|
||||||
games_with_playtime = Game.objects.filter(
|
games_with_playtime = (
|
||||||
sessions__in=this_year_sessions
|
Game.objects.filter(sessions__timestamp_start__year=year)
|
||||||
).distinct()
|
.annotate(
|
||||||
|
total_playtime=Sum(
|
||||||
|
F("sessions__duration_calculated"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.filter(total_playtime__gt=timedelta(0))
|
||||||
|
)
|
||||||
|
|
||||||
month_playtimes = (
|
month_playtimes = (
|
||||||
this_year_sessions.annotate(month=TruncMonth("timestamp_start"))
|
this_year_sessions.annotate(month=TruncMonth("timestamp_start"))
|
||||||
.values("month")
|
.values("month")
|
||||||
@ -380,7 +387,7 @@ def stats(request: HttpRequest, year: int = 0) -> HttpResponse:
|
|||||||
.order_by("-session_average")
|
.order_by("-session_average")
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
top_10_games_by_playtime = games_with_playtime.order_by("-playtime")
|
top_10_games_by_playtime = games_with_playtime.order_by("-total_playtime")
|
||||||
|
|
||||||
total_playtime_per_platform = (
|
total_playtime_per_platform = (
|
||||||
this_year_sessions.values("game__platform__name")
|
this_year_sessions.values("game__platform__name")
|
||||||
|
@ -26,7 +26,6 @@ from common.time import (
|
|||||||
from common.utils import truncate
|
from common.utils import truncate
|
||||||
from games.forms import SessionForm
|
from games.forms import SessionForm
|
||||||
from games.models import Game, Session
|
from games.models import Game, Session
|
||||||
from games.views.general import use_custom_redirect
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@ -215,7 +214,6 @@ def add_session(request: HttpRequest, game_id: int = 0) -> HttpResponse:
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@use_custom_redirect
|
|
||||||
def edit_session(request: HttpRequest, session_id: int) -> HttpResponse:
|
def edit_session(request: HttpRequest, session_id: int) -> HttpResponse:
|
||||||
context = {}
|
context = {}
|
||||||
session = get_object_or_404(Session, id=session_id)
|
session = get_object_or_404(Session, id=session_id)
|
||||||
|
Reference in New Issue
Block a user