Compare commits

..

No commits in common. "beec919b2e9dfd1992f3764e6098f99d1b228997" and "2553d6f9e606a1b292a20937e9205800dbe4725e" have entirely different histories.

5 changed files with 3 additions and 29 deletions

View File

@ -1,9 +1,3 @@
## Unreleased
* New
* When adding session, pre-select game with the last session
* Date and time input fields now have proper pickers
## 0.2.4 / 2023-01-16 19:39+01:00 ## 0.2.4 / 2023-01-16 19:39+01:00
* Fixed * Fixed

View File

@ -13,26 +13,12 @@ class SessionForm(forms.ModelForm):
"duration_manual", "duration_manual",
"note", "note",
] ]
custom_datetime_widget = forms.SplitDateTimeWidget(
date_attrs={"type": "date"}, time_attrs={"type": "time"}
)
widgets = {
"timestamp_start": custom_datetime_widget,
"timestamp_end": custom_datetime_widget,
}
class PurchaseForm(forms.ModelForm): class PurchaseForm(forms.ModelForm):
class Meta: class Meta:
model = Purchase model = Purchase
fields = ["game", "platform", "date_purchased", "date_refunded"] fields = ["game", "platform", "date_purchased", "date_refunded"]
custom_date_widget = forms.DateInput(
format=("%d-%m-%Y"), attrs={"type": "date"}
)
widgets = {
"date_purchased": custom_date_widget,
"date_refunded": custom_date_widget,
}
class GameForm(forms.ModelForm): class GameForm(forms.ModelForm):
@ -45,7 +31,3 @@ class PlatformForm(forms.ModelForm):
class Meta: class Meta:
model = Platform model = Platform
fields = ["name", "group"] fields = ["name", "group"]
class UnifiedGameForm(forms.ModelForm):
GameFormSet = forms.inlineformset_factory(Game, Purchase)

View File

@ -81,7 +81,7 @@ class Session(models.Model):
@property @property
def last(self) -> Manager[Any]: def last(self) -> Manager[Any]:
return Session.objects.all().order_by("timestamp_start")[0] return Session.objects.all().order_by("timestamp_start")[:-1]
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if self.timestamp_start != None and self.timestamp_end != None: if self.timestamp_start != None and self.timestamp_end != None:

View File

@ -23,7 +23,7 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="self-center w-6 h-6 inline"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="self-center w-6 h-6 inline">
<path stroke-linecap="round" stroke-linejoin="round" d="M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.348a1.125 1.125 0 010 1.971l-11.54 6.347a1.125 1.125 0 01-1.667-.985V5.653z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.348a1.125 1.125 0 010 1.971l-11.54 6.347a1.125 1.125 0 01-1.667-.985V5.653z" />
</svg> </svg>
{{ last.purchase }} {{ dataset.last.purchase }}
</button> </button>
</a> </a>
{% endif %} {% endif %}

View File

@ -22,8 +22,7 @@ def model_counts(request):
def add_session(request): def add_session(request):
context = {} context = {}
now = now_with_tz() now = now_with_tz()
last = Session.objects.all().last() initial = {"timestamp_start": now}
initial = {"timestamp_start": now, "purchase": last.purchase}
form = SessionForm(request.POST or None, initial=initial) form = SessionForm(request.POST or None, initial=initial)
if form.is_valid(): if form.is_valid():
form.save() form.save()
@ -75,7 +74,6 @@ def list_sessions(request, filter="", purchase_id="", platform_id="", game_id=""
context["total_duration"] = dataset.total_duration() context["total_duration"] = dataset.total_duration()
context["dataset"] = dataset context["dataset"] = dataset
context["last"] = Session.objects.all().last()
# charts are always oldest->newest # charts are always oldest->newest
context["chart"] = playtime_over_time_chart(dataset.order_by("timestamp_start")) context["chart"] = playtime_over_time_chart(dataset.order_by("timestamp_start"))