Compare commits
3 Commits
0.2.4
...
fix-splitd
Author | SHA1 | Date | |
---|---|---|---|
7dfd91421e | |||
4d91a76513 | |||
e51d586255 |
@ -1,3 +1,9 @@
|
|||||||
|
## 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
|
||||||
|
@ -4,6 +4,23 @@ from .models import Game, Platform, Purchase, Session
|
|||||||
|
|
||||||
|
|
||||||
class SessionForm(forms.ModelForm):
|
class SessionForm(forms.ModelForm):
|
||||||
|
custom_datetime_widget = forms.SplitDateTimeWidget(
|
||||||
|
date_format=("%d-%m-%Y"),
|
||||||
|
time_format=("%H:%M"),
|
||||||
|
date_attrs={"type": "date"},
|
||||||
|
time_attrs={"type": "time"},
|
||||||
|
)
|
||||||
|
timestamp_start = forms.SplitDateTimeField(
|
||||||
|
input_date_formats="['%d-%m-%Y]",
|
||||||
|
input_time_formats="['%H:%M']",
|
||||||
|
widget=custom_datetime_widget,
|
||||||
|
)
|
||||||
|
timestamp_end = forms.SplitDateTimeField(
|
||||||
|
input_date_formats="['%d-%m-%Y]",
|
||||||
|
input_time_formats="['%H:%M']",
|
||||||
|
widget=custom_datetime_widget,
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Session
|
model = Session
|
||||||
fields = [
|
fields = [
|
||||||
@ -14,11 +31,27 @@ class SessionForm(forms.ModelForm):
|
|||||||
"note",
|
"note",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# fields_classes = {
|
||||||
|
# "timestamp_start": custom_datetime_field,
|
||||||
|
# "timestamp_end": custom_datetime_field,
|
||||||
|
# }
|
||||||
|
# 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):
|
||||||
|
@ -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")[:-1]
|
return Session.objects.all().order_by("timestamp_start")[0]
|
||||||
|
|
||||||
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:
|
||||||
|
@ -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>
|
||||||
{{ dataset.last.purchase }}
|
{{ last.purchase }}
|
||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -22,7 +22,12 @@ def model_counts(request):
|
|||||||
def add_session(request):
|
def add_session(request):
|
||||||
context = {}
|
context = {}
|
||||||
now = now_with_tz()
|
now = now_with_tz()
|
||||||
initial = {"timestamp_start": now}
|
last = Session.objects.all().last()
|
||||||
|
initial = {
|
||||||
|
"timestamp_start_0": now.date(),
|
||||||
|
"timestamp_start_1": now.time(),
|
||||||
|
"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()
|
||||||
@ -74,6 +79,7 @@ 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"))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user