Session list: speed up starting new sessions
This commit is contained in:
		| @ -3,7 +3,7 @@ | |||||||
| ## Improved | ## Improved | ||||||
| * game overview: improve how editions and purchases are displayed | * game overview: improve how editions and purchases are displayed | ||||||
| * add purchase: only allow choosing purchases of selected edition | * 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 | ## 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-get="{% url 'start_session_same_as_last' last.id %}" | ||||||
|                 hx-swap="afterbegin" |                 hx-swap="afterbegin" | ||||||
|                 hx-target=".responsive-table tbody" |                 hx-target=".responsive-table tbody" | ||||||
|                 hx-select=".responsive-table tbody tr:first-child" |  | ||||||
|                 onClick="document.querySelector('#last-session-start').classList.add('invisible')" |                 onClick="document.querySelector('#last-session-start').classList.add('invisible')" | ||||||
|                 class="{% if last.timestamp_end == null %}invisible{% endif %}"> |                 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 %} |                 {% 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" }} |                                     {{ session.timestamp_start | date:"d/m/Y H:i" }} | ||||||
|                                 </td> |                                 </td> | ||||||
|                                 <td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono hidden lg:table-cell"> |                                 <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 %}" |                                         <a href="{% url 'update_session' session.id %}" | ||||||
|                                             hx-get="{% url 'update_session' session.id %}" |                                             hx-get="{% url 'update_session' session.id %}" | ||||||
|                                             hx-target="closest tr" |                                             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): | def start_session_same_as_last(request, last_session_id: int): | ||||||
|     last_session = Session.objects.get(id=last_session_id) |     last_session = get_object_or_404(Session, id=last_session_id) | ||||||
|     session = SessionForm( |     # clone it | ||||||
|         { |     session = last_session | ||||||
|             "purchase": last_session.purchase.id, |     session.pk = None | ||||||
|             "timestamp_start": timezone.now(), |     # set new data | ||||||
|             "device": last_session.device, |     session.timestamp_start = timezone.now() | ||||||
|         } |     session.timestamp_end = None | ||||||
|     ) |  | ||||||
|     session.save() |     session.save() | ||||||
|  |     if request.htmx: | ||||||
|  |         context = {"session": session} | ||||||
|  |         return render(request, "list_sessions.html#session-row", context) | ||||||
|     return redirect("list_sessions") |     return redirect("list_sessions") | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -301,13 +303,6 @@ def list_sessions( | |||||||
|         # by default, sort from newest to oldest |         # by default, sort from newest to oldest | ||||||
|         dataset = Session.objects.order_by("-timestamp_start") |         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["total_duration"] = dataset.total_duration_formatted() | ||||||
|     context["dataset"] = dataset |     context["dataset"] = dataset | ||||||
|     try: |     try: | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user