Compare commits
No commits in common. "4b451273351f779bec70a24ffcf94339ad5f1462" and "61d2e65d835e8ed9d546f65c4a0bcf6b9588b149" have entirely different histories.
4b45127335
...
61d2e65d83
|
@ -1,9 +1,4 @@
|
||||||
## Unreleased
|
## Unreleased
|
||||||
* Allow deleting sessions
|
|
||||||
* Redirect after adding game/platform/purchase/session
|
|
||||||
* Fix display of duration_manual
|
|
||||||
* Fix display of duration_calculated, display durations less than a minute
|
|
||||||
* Make the "Finish now?" button on session list work
|
|
||||||
* Hide navigation bar items if there are no games/purchases/sessions
|
* Hide navigation bar items if there are no games/purchases/sessions
|
||||||
* Set default version to "git-main" to indicate development environment
|
* Set default version to "git-main" to indicate development environment
|
||||||
* Add homepage, link to it from the logo
|
* Add homepage, link to it from the logo
|
||||||
|
|
|
@ -12,5 +12,5 @@ COPY entrypoint.sh /
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
USER timetracker
|
USER timetracker
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
ENV VERSION_NUMBER 0.1.0-18-gb8a15e4
|
ENV VERSION_NUMBER 0.1.0-4-g166dd71
|
||||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
ENTRYPOINT [ "/entrypoint.sh" ]
|
|
@ -1,7 +0,0 @@
|
||||||
from datetime import datetime
|
|
||||||
from django.conf import settings
|
|
||||||
from zoneinfo import ZoneInfo
|
|
||||||
|
|
||||||
|
|
||||||
def now():
|
|
||||||
return datetime.now(ZoneInfo(settings.TIME_ZONE))
|
|
|
@ -1,7 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from datetime import datetime
|
from datetime import timedelta
|
||||||
from django.conf import settings
|
|
||||||
from zoneinfo import ZoneInfo
|
|
||||||
|
|
||||||
|
|
||||||
class Game(models.Model):
|
class Game(models.Model):
|
||||||
|
@ -42,17 +40,14 @@ class Session(models.Model):
|
||||||
mark = ", manual" if self.duration_manual != None else ""
|
mark = ", manual" if self.duration_manual != None else ""
|
||||||
return f"{str(self.purchase)} {str(self.timestamp_start.date())} ({self.duration_any()}{mark})"
|
return f"{str(self.purchase)} {str(self.timestamp_start.date())} ({self.duration_any()}{mark})"
|
||||||
|
|
||||||
def finish_now(self):
|
|
||||||
self.timestamp_end = datetime.now(ZoneInfo(settings.TIME_ZONE))
|
|
||||||
|
|
||||||
def duration_seconds(self):
|
def duration_seconds(self):
|
||||||
if self.duration_manual == None:
|
|
||||||
if self.timestamp_end == None or self.timestamp_start == None:
|
if self.timestamp_end == None or self.timestamp_start == None:
|
||||||
|
if self.duration_manual == None:
|
||||||
return 0
|
return 0
|
||||||
else:
|
|
||||||
value = self.timestamp_end - self.timestamp_start
|
|
||||||
else:
|
else:
|
||||||
value = self.duration_manual
|
value = self.duration_manual
|
||||||
|
else:
|
||||||
|
value = self.timestamp_end - self.timestamp_start
|
||||||
return value.total_seconds()
|
return value.total_seconds()
|
||||||
|
|
||||||
def duration_formatted(self):
|
def duration_formatted(self):
|
||||||
|
@ -60,10 +55,7 @@ class Session(models.Model):
|
||||||
if seconds == 0:
|
if seconds == 0:
|
||||||
return seconds
|
return seconds
|
||||||
hours, remainder = divmod(seconds, 3600)
|
hours, remainder = divmod(seconds, 3600)
|
||||||
minutes = remainder // 60
|
minutes = remainder % 60
|
||||||
if hours == 0 and minutes == 0:
|
|
||||||
return "less than a minute"
|
|
||||||
else:
|
|
||||||
hour_string = f"{int(hours)}h" if hours != 0 else ""
|
hour_string = f"{int(hours)}h" if hours != 0 else ""
|
||||||
minute_string = f"{int(minutes)}m" if minutes != 0 else ""
|
minute_string = f"{int(minutes)}m" if minutes != 0 else ""
|
||||||
return f"{hour_string}{minute_string}"
|
return f"{hour_string}{minute_string}"
|
||||||
|
|
|
@ -766,8 +766,8 @@ select {
|
||||||
max-width: 1024px;
|
max-width: 1024px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid-cols-5 {
|
.grid-cols-4 {
|
||||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
}
|
}
|
||||||
|
|
||||||
.flex-col {
|
.flex-col {
|
||||||
|
@ -819,6 +819,11 @@ select {
|
||||||
border-color: rgb(229 231 235 / var(--tw-border-opacity));
|
border-color: rgb(229 231 235 / var(--tw-border-opacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.border-red-800 {
|
||||||
|
--tw-border-opacity: 1;
|
||||||
|
border-color: rgb(153 27 27 / var(--tw-border-opacity));
|
||||||
|
}
|
||||||
|
|
||||||
.border-red-900 {
|
.border-red-900 {
|
||||||
--tw-border-opacity: 1;
|
--tw-border-opacity: 1;
|
||||||
border-color: rgb(127 29 29 / var(--tw-border-opacity));
|
border-color: rgb(127 29 29 / var(--tw-border-opacity));
|
||||||
|
@ -938,6 +943,21 @@ form input[type=submit] {
|
||||||
border-color: rgb(255 255 255 / var(--tw-border-opacity));
|
border-color: rgb(255 255 255 / var(--tw-border-opacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hover\:bg-red-600:hover {
|
||||||
|
--tw-bg-opacity: 1;
|
||||||
|
background-color: rgb(220 38 38 / var(--tw-bg-opacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
.hover\:bg-red-500:hover {
|
||||||
|
--tw-bg-opacity: 1;
|
||||||
|
background-color: rgb(239 68 68 / var(--tw-bg-opacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
.hover\:bg-yellow-700:hover {
|
||||||
|
--tw-bg-opacity: 1;
|
||||||
|
background-color: rgb(161 98 7 / var(--tw-bg-opacity));
|
||||||
|
}
|
||||||
|
|
||||||
.hover\:bg-orange-700:hover {
|
.hover\:bg-orange-700:hover {
|
||||||
--tw-bg-opacity: 1;
|
--tw-bg-opacity: 1;
|
||||||
background-color: rgb(194 65 12 / var(--tw-bg-opacity));
|
background-color: rgb(194 65 12 / var(--tw-bg-opacity));
|
||||||
|
|
|
@ -9,18 +9,17 @@
|
||||||
<a class="dark:text-white hover:underline" href="{% url 'list_sessions' %}">View all sessions</a>
|
<a class="dark:text-white hover:underline" href="{% url 'list_sessions' %}">View all sessions</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="grid grid-cols-5 gap-4 shadow rounded-xl max-w-screen-lg mx-auto dark:bg-slate-700 p-2 justify-center">
|
<div class="grid grid-cols-4 gap-4 shadow rounded-xl max-w-screen-lg mx-auto dark:bg-slate-700 p-2 justify-center">
|
||||||
<div class="dark:border-white dark:text-slate-300 text-lg">Name</div>
|
<div class="dark:border-white dark:text-slate-300 text-lg">Name</div>
|
||||||
<div class="dark:border-white dark:text-slate-300 text-lg">Start</div>
|
<div class="dark:border-white dark:text-slate-300 text-lg">Start</div>
|
||||||
<div class="dark:border-white dark:text-slate-300 text-lg">End</div>
|
<div class="dark:border-white dark:text-slate-300 text-lg">End</div>
|
||||||
<div class="dark:border-white dark:text-slate-300 text-lg">Duration</div>
|
<div class="dark:border-white dark:text-slate-300 text-lg">Duration</div>
|
||||||
<div></div>
|
|
||||||
{% for data in dataset %}
|
{% for data in dataset %}
|
||||||
<div class=""><a class="dark:text-white hover:underline" href="{% url 'list_sessions' data.purchase.id %}">{{ data.purchase }}</a></div>
|
<div class=""><a class="dark:text-white hover:underline" href="{% url 'list_sessions' data.purchase.id %}">{{ data.purchase }}</a></div>
|
||||||
<div class="dark:text-slate-400">{{ data.timestamp_start | date:"d/m/Y H:i" }}</div>
|
<div class="dark:text-slate-400">{{ data.timestamp_start | date:"d/m/Y H:i" }}</div>
|
||||||
<div class="dark:text-slate-400">
|
<div class="dark:text-slate-400">
|
||||||
{% if data.unfinished %}
|
{% if data.unfinished %}
|
||||||
Not finished yet. <a href="{% url 'update_session' data.id %}"><button class="bg-red-700 hover:bg-orange-700 border border-red-900 hover:border-dotted hover:border-white rounded p-1 text-white text-sm">Finish now?</button></a>
|
Not finished yet. <button class="bg-red-700 hover:bg-orange-700 border border-red-900 hover:border-dotted hover:border-white rounded p-1 text-white text-sm">Finish now?</button>
|
||||||
{% elif data.duration_manual %}
|
{% elif data.duration_manual %}
|
||||||
MANUAL
|
MANUAL
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -28,9 +27,6 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="dark:text-slate-400">{{ data.duration_formatted }}{% if data.duration_manual %} (M){% endif %}</div>
|
<div class="dark:text-slate-400">{{ data.duration_formatted }}{% if data.duration_manual %} (M){% endif %}</div>
|
||||||
<div>
|
|
||||||
<a href="{% url 'delete_session' data.id %}"><button>❌</button></a>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
|
@ -7,16 +7,6 @@ urlpatterns = [
|
||||||
path("add-game/", views.add_game, name="add_game"),
|
path("add-game/", views.add_game, name="add_game"),
|
||||||
path("add-platform/", views.add_platform, name="add_platform"),
|
path("add-platform/", views.add_platform, name="add_platform"),
|
||||||
path("add-session/", views.add_session, name="add_session"),
|
path("add-session/", views.add_session, name="add_session"),
|
||||||
path(
|
|
||||||
"update-session/by-session/<int:session_id>",
|
|
||||||
views.update_session,
|
|
||||||
name="update_session",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"delete_session/by-id/<int:session_id>",
|
|
||||||
views.delete_session,
|
|
||||||
name="delete_session",
|
|
||||||
),
|
|
||||||
path("add-purchase/", views.add_purchase, name="add_purchase"),
|
path("add-purchase/", views.add_purchase, name="add_purchase"),
|
||||||
path("list-sessions/", views.list_sessions, name="list_sessions"),
|
path("list-sessions/", views.list_sessions, name="list_sessions"),
|
||||||
path(
|
path(
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render
|
||||||
|
|
||||||
from .models import Game, Platform, Purchase, Session
|
from .models import Game, Platform, Purchase, Session
|
||||||
from .forms import SessionForm, PurchaseForm, GameForm, PlatformForm
|
from .forms import SessionForm, PurchaseForm, GameForm, PlatformForm
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from common.util.time import now as now_with_tz
|
|
||||||
|
|
||||||
|
|
||||||
def model_counts(request):
|
def model_counts(request):
|
||||||
|
@ -19,30 +18,16 @@ def model_counts(request):
|
||||||
|
|
||||||
def add_session(request):
|
def add_session(request):
|
||||||
context = {}
|
context = {}
|
||||||
now = now_with_tz()
|
now = datetime.now()
|
||||||
initial = {"timestamp_start": now}
|
initial = {"timestamp_start": now, "timestamp_end": now}
|
||||||
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()
|
||||||
return redirect("list_sessions")
|
|
||||||
|
|
||||||
context["form"] = form
|
context["form"] = form
|
||||||
return render(request, "add_session.html", context)
|
return render(request, "add_session.html", context)
|
||||||
|
|
||||||
|
|
||||||
def update_session(request, session_id=None):
|
|
||||||
session = Session.objects.get(id=session_id)
|
|
||||||
session.finish_now()
|
|
||||||
session.save()
|
|
||||||
return redirect("list_sessions")
|
|
||||||
|
|
||||||
|
|
||||||
def delete_session(request, session_id=None):
|
|
||||||
session = Session.objects.get(id=session_id)
|
|
||||||
session.delete()
|
|
||||||
return redirect("list_sessions")
|
|
||||||
|
|
||||||
|
|
||||||
def list_sessions(request, purchase_id=None):
|
def list_sessions(request, purchase_id=None):
|
||||||
context = {}
|
context = {}
|
||||||
|
|
||||||
|
@ -69,7 +54,6 @@ def add_purchase(request):
|
||||||
form = PurchaseForm(request.POST or None, initial=initial)
|
form = PurchaseForm(request.POST or None, initial=initial)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
return redirect("index")
|
|
||||||
|
|
||||||
context["form"] = form
|
context["form"] = form
|
||||||
context["title"] = "Add New Purchase"
|
context["title"] = "Add New Purchase"
|
||||||
|
@ -81,7 +65,6 @@ def add_game(request):
|
||||||
form = GameForm(request.POST or None)
|
form = GameForm(request.POST or None)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
return redirect("index")
|
|
||||||
|
|
||||||
context["form"] = form
|
context["form"] = form
|
||||||
context["title"] = "Add New Game"
|
context["title"] = "Add New Game"
|
||||||
|
@ -93,7 +76,6 @@ def add_platform(request):
|
||||||
form = PlatformForm(request.POST or None)
|
form = PlatformForm(request.POST or None)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
return redirect("index")
|
|
||||||
|
|
||||||
context["form"] = form
|
context["form"] = form
|
||||||
context["title"] = "Add New Platform"
|
context["title"] = "Add New Platform"
|
||||||
|
|
Loading…
Reference in New Issue