Session list: speed up starting new sessions
This commit is contained in:
parent
0cf3411f63
commit
44f49e5974
|
@ -3,7 +3,7 @@
|
|||
## Improved
|
||||
* game overview: improve how editions and purchases are displayed
|
||||
* add purchase: only allow choosing purchases of selected edition
|
||||
* session list: clicking the "End now?" link is not much faster
|
||||
* session list: starting and ending sessions is much faster/doest not reload the page
|
||||
|
||||
## 1.5.1 / 2023-11-14 21:10+01:00
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
hx-get="{% url 'start_session_same_as_last' last.id %}"
|
||||
hx-swap="afterbegin"
|
||||
hx-target=".responsive-table tbody"
|
||||
hx-select=".responsive-table tbody tr:first-child"
|
||||
onClick="document.querySelector('#last-session-start').classList.add('invisible')"
|
||||
class="{% if last.timestamp_end == null %}invisible{% endif %}">
|
||||
{% include 'components/button_start.html' with text=last.purchase title="Start session of last played game" only %}
|
||||
|
@ -42,7 +41,7 @@
|
|||
{{ session.timestamp_start | date:"d/m/Y H:i" }}
|
||||
</td>
|
||||
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono hidden lg:table-cell">
|
||||
{% if session.unfinished %}
|
||||
{% if not session.timestamp_end %}
|
||||
<a href="{% url 'update_session' session.id %}"
|
||||
hx-get="{% url 'update_session' session.id %}"
|
||||
hx-target="closest tr"
|
||||
|
|
|
@ -245,15 +245,17 @@ def start_game_session(request, game_id: int):
|
|||
|
||||
|
||||
def start_session_same_as_last(request, last_session_id: int):
|
||||
last_session = Session.objects.get(id=last_session_id)
|
||||
session = SessionForm(
|
||||
{
|
||||
"purchase": last_session.purchase.id,
|
||||
"timestamp_start": timezone.now(),
|
||||
"device": last_session.device,
|
||||
}
|
||||
)
|
||||
last_session = get_object_or_404(Session, id=last_session_id)
|
||||
# clone it
|
||||
session = last_session
|
||||
session.pk = None
|
||||
# set new data
|
||||
session.timestamp_start = timezone.now()
|
||||
session.timestamp_end = None
|
||||
session.save()
|
||||
if request.htmx:
|
||||
context = {"session": session}
|
||||
return render(request, "list_sessions.html#session-row", context)
|
||||
return redirect("list_sessions")
|
||||
|
||||
|
||||
|
@ -301,13 +303,6 @@ def list_sessions(
|
|||
# by default, sort from newest to oldest
|
||||
dataset = Session.objects.order_by("-timestamp_start")
|
||||
|
||||
for session in dataset:
|
||||
if session.timestamp_end == None and session.duration_manual == timedelta(
|
||||
seconds=0
|
||||
):
|
||||
session.timestamp_end = timezone.now()
|
||||
session.unfinished = True
|
||||
|
||||
context["total_duration"] = dataset.total_duration_formatted()
|
||||
context["dataset"] = dataset
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue