Automatically select purchase when adding session

This commit is contained in:
Lukáš Kucharczyk 2023-01-16 21:19:20 +01:00
parent 2553d6f9e6
commit e51d586255
4 changed files with 10 additions and 3 deletions

View File

@ -1,3 +1,8 @@
## Unreleased
* New
* When adding session, pre-select game with the last session
## 0.2.4 / 2023-01-16 19:39+01:00 ## 0.2.4 / 2023-01-16 19:39+01:00
* Fixed * Fixed

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")[:-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:

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>
{{ dataset.last.purchase }} {{ last.purchase }}
</button> </button>
</a> </a>
{% endif %} {% endif %}

View File

@ -22,7 +22,8 @@ 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": 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()
@ -74,6 +75,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"))