Compare commits

..

No commits in common. "fda4913c979a30477523ec945cdb535ac5076408" and "2e5e77b4e57fcdfa4903b2e9740aa5692b32f39a" have entirely different histories.

16 changed files with 173 additions and 187 deletions

View File

@ -1,10 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 24.8.0
rev: 24.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.13.2
rev: 5.12.0
hooks:
- id: isort
name: isort (python)

View File

@ -1,6 +1,6 @@
{
"recommendations": [
"charliermarsh.ruff",
"ms-python.black-formatter",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.debugpy",

View File

@ -6,14 +6,9 @@
"python.testing.pytestEnabled": true,
"python.analysis.typeCheckingMode": "strict",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"ruff.path": ["/nix/store/s3q6qc2954x62bkcs9dwaxyiqchl7j01-ruff-0.5.6/bin/ruff"],
"tailwind-fold.supportedLanguages": [
"html",
"typescriptreact",

View File

@ -20,7 +20,7 @@ def list_purchases(request: HttpRequest) -> HttpResponse:
purchases = Purchase.objects.order_by("-date_purchased")
page_obj = None
if int(limit) != 0:
paginator = Paginator(purchases, limit)
paginator = Paginator(Purchase.objects.order_by("-date_purchased"), limit)
page_obj = paginator.get_page(page_number)
purchases = page_obj.object_list

View File

@ -1,86 +0,0 @@
from typing import Any
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.template.loader import render_to_string
from django.urls import reverse
from common.time import format_duration
from games.models import Session
from games.views import dateformat, datetimeformat, timeformat
@login_required
def list_sessions(request: HttpRequest) -> HttpResponse:
context: dict[Any, Any] = {}
page_number = request.GET.get("page", 1)
limit = request.GET.get("limit", 10)
sessions = Session.objects.order_by("-created_at")
page_obj = None
if int(limit) != 0:
paginator = Paginator(sessions, limit)
page_obj = paginator.get_page(page_number)
sessions = page_obj.object_list
context = {
"title": "Manage sessions",
"page_obj": page_obj or None,
"elided_page_range": (
page_obj.paginator.get_elided_page_range(
page_number, on_each_side=1, on_ends=1
)
if page_obj
else None
),
"data": {
"columns": [
"Name",
"Date",
"Duration",
"Duration (manual)",
"Device",
"Created",
"Actions",
],
"rows": [
[
session.purchase.edition.name,
f"{session.timestamp_start.strftime(datetimeformat)}{f"{session.timestamp_end.strftime(timeformat)}" if session.timestamp_end else ""}",
(
format_duration(session.duration_calculated, "%2.1H hours")
if session.duration_calculated
else "-"
),
(
format_duration(session.duration_manual)
if session.duration_manual
else "-"
),
session.device,
session.created_at.strftime(dateformat),
render_to_string(
"components/button_group_sm.html",
{
"buttons": [
{
"href": reverse("edit_session", args=[session.pk]),
"text": "Edit",
},
{
"href": reverse(
"delete_session", args=[session.pk]
),
"text": "Delete",
"color": "red",
},
]
},
),
]
for session in sessions
],
},
}
return render(request, "list_purchases.html", context)

View File

@ -1346,6 +1346,10 @@ input:checked + .toggle-bg {
z-index: 50;
}
.z-0 {
z-index: 0;
}
.mx-2 {
margin-left: 0.5rem;
margin-right: 0.5rem;
@ -1402,10 +1406,6 @@ input:checked + .toggle-bg {
margin-inline-start: 0px;
}
.ms-2\.5 {
margin-inline-start: 0.625rem;
}
.mt-2 {
margin-top: 0.5rem;
}
@ -1414,6 +1414,10 @@ input:checked + .toggle-bg {
margin-top: 1rem;
}
.ms-2\.5 {
margin-inline-start: 0.625rem;
}
.block {
display: block;
}
@ -1451,16 +1455,12 @@ input:checked + .toggle-bg {
height: 1.5rem;
}
.h-10 {
height: 2.5rem;
}
.h-12 {
height: 3rem;
}
.h-2\.5 {
height: 0.625rem;
.h-24 {
height: 6rem;
}
.h-3 {
@ -1487,6 +1487,14 @@ input:checked + .toggle-bg {
height: 2.25rem;
}
.h-10 {
height: 2.5rem;
}
.h-2\.5 {
height: 0.625rem;
}
.min-h-screen {
min-height: 100vh;
}
@ -1495,14 +1503,6 @@ input:checked + .toggle-bg {
width: 50%;
}
.w-10 {
width: 2.5rem;
}
.w-2\.5 {
width: 0.625rem;
}
.w-24 {
width: 6rem;
}
@ -1511,10 +1511,6 @@ input:checked + .toggle-bg {
width: 1rem;
}
.w-44 {
width: 11rem;
}
.w-5 {
width: 1.25rem;
}
@ -1531,20 +1527,36 @@ input:checked + .toggle-bg {
width: 1.75rem;
}
.w-auto {
width: auto;
}
.w-full {
width: 100%;
}
.w-10 {
width: 2.5rem;
}
.w-2\.5 {
width: 0.625rem;
}
.w-44 {
width: 11rem;
}
.max-w-80 {
max-width: 20rem;
}
.max-w-screen-lg {
max-width: 1024px;
.max-w-screen-2xl {
max-width: 1536px;
}
.max-w-screen-xl {
max-width: 1280px;
.max-w-screen-lg {
max-width: 1024px;
}
.max-w-sm {
@ -1555,6 +1567,10 @@ input:checked + .toggle-bg {
max-width: 20rem;
}
.max-w-screen-xl {
max-width: 1280px;
}
.flex-1 {
flex: 1 1 0%;
}
@ -1748,10 +1764,6 @@ input:checked + .toggle-bg {
text-wrap: wrap;
}
.rounded {
border-radius: 0.25rem;
}
.rounded-full {
border-radius: 9999px;
}
@ -1768,6 +1780,10 @@ input:checked + .toggle-bg {
border-radius: 0.125rem;
}
.rounded {
border-radius: 0.25rem;
}
.rounded-e-lg {
border-start-end-radius: 0.5rem;
border-end-end-radius: 0.5rem;
@ -1845,11 +1861,6 @@ input:checked + .toggle-bg {
background-color: rgb(229 231 235 / var(--tw-bg-opacity));
}
.bg-gray-400 {
--tw-bg-opacity: 1;
background-color: rgb(156 163 175 / var(--tw-bg-opacity));
}
.bg-gray-50 {
--tw-bg-opacity: 1;
background-color: rgb(249 250 251 / var(--tw-bg-opacity));
@ -1883,12 +1894,18 @@ input:checked + .toggle-bg {
background-color: rgb(255 255 255 / 0.5);
}
.p-1 {
padding: 0.25rem;
.bg-gray-300 {
--tw-bg-opacity: 1;
background-color: rgb(209 213 219 / var(--tw-bg-opacity));
}
.p-2 {
padding: 0.5rem;
.bg-gray-400 {
--tw-bg-opacity: 1;
background-color: rgb(156 163 175 / var(--tw-bg-opacity));
}
.p-1 {
padding: 0.25rem;
}
.p-2\.5 {
@ -1899,6 +1916,10 @@ input:checked + .toggle-bg {
padding: 1rem;
}
.p-2 {
padding: 0.5rem;
}
.px-2 {
padding-left: 0.5rem;
padding-right: 0.5rem;
@ -1949,6 +1970,18 @@ input:checked + .toggle-bg {
padding-bottom: 1rem;
}
.pl-3 {
padding-left: 0.75rem;
}
.pr-4 {
padding-right: 1rem;
}
.pt-1 {
padding-top: 0.25rem;
}
.pt-2 {
padding-top: 0.5rem;
}
@ -2063,11 +2096,6 @@ input:checked + .toggle-bg {
color: rgb(28 100 242 / var(--tw-text-opacity));
}
.text-gray-300 {
--tw-text-opacity: 1;
color: rgb(209 213 219 / var(--tw-text-opacity));
}
.text-gray-400 {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
@ -2118,6 +2146,16 @@ input:checked + .toggle-bg {
color: rgb(250 202 21 / var(--tw-text-opacity));
}
.text-gray-300 {
--tw-text-opacity: 1;
color: rgb(209 213 219 / var(--tw-text-opacity));
}
.text-gray-100 {
--tw-text-opacity: 1;
color: rgb(243 244 246 / var(--tw-text-opacity));
}
.underline {
text-decoration-line: underline;
}
@ -2211,10 +2249,6 @@ input:checked + .toggle-bg {
max-width: 20ch;
}
.min-w-30char {
min-width: 30ch;
}
.max-w-30char {
max-width: 30ch;
}
@ -2508,6 +2542,11 @@ textarea:disabled:is(.dark *) {
background-color: rgb(243 244 246 / var(--tw-bg-opacity));
}
.hover\:bg-gray-400:hover {
--tw-bg-opacity: 1;
background-color: rgb(156 163 175 / var(--tw-bg-opacity));
}
.hover\:bg-gray-50:hover {
--tw-bg-opacity: 1;
background-color: rgb(249 250 251 / var(--tw-bg-opacity));
@ -2573,6 +2612,10 @@ textarea:disabled:is(.dark *) {
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.hover\:underline:hover {
text-decoration-line: underline;
}
.focus\:z-10:focus {
z-index: 10;
}
@ -2653,6 +2696,10 @@ textarea:disabled:is(.dark *) {
top: -2rem;
}
.group:hover .group-hover\:block {
display: block;
}
.group:hover .group-hover\:min-w-60 {
min-width: 15rem;
}
@ -2773,11 +2820,6 @@ textarea:disabled:is(.dark *) {
color: rgb(63 131 248 / var(--tw-text-opacity));
}
.dark\:text-gray-200:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(229 231 235 / var(--tw-text-opacity));
}
.dark\:text-gray-400:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
@ -2813,6 +2855,11 @@ textarea:disabled:is(.dark *) {
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.dark\:text-gray-200:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(229 231 235 / var(--tw-text-opacity));
}
.odd\:dark\:bg-gray-900:is(.dark *):nth-child(odd) {
--tw-bg-opacity: 1;
background-color: rgb(17 24 39 / var(--tw-bg-opacity));
@ -2888,9 +2935,9 @@ textarea:disabled:is(.dark *) {
--tw-ring-color: rgb(63 131 248 / var(--tw-ring-opacity));
}
.dark\:focus\:ring-gray-600:focus:is(.dark *) {
.dark\:focus\:ring-gray-700:focus:is(.dark *) {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(75 85 99 / var(--tw-ring-opacity));
--tw-ring-color: rgb(55 65 81 / var(--tw-ring-opacity));
}
.dark\:focus\:ring-green-500:focus:is(.dark *) {
@ -2898,6 +2945,11 @@ textarea:disabled:is(.dark *) {
--tw-ring-color: rgb(14 159 110 / var(--tw-ring-opacity));
}
.dark\:focus\:ring-gray-600:focus:is(.dark *) {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(75 85 99 / var(--tw-ring-opacity));
}
@media (min-width: 640px) {
.sm\:inline {
display: inline;
@ -2911,14 +2963,14 @@ textarea:disabled:is(.dark *) {
max-width: 28rem;
}
.sm\:max-w-screen-sm {
max-width: 640px;
}
.sm\:max-w-xl {
max-width: 36rem;
}
.sm\:max-w-screen-sm {
max-width: 640px;
}
.sm\:rounded-lg {
border-radius: 0.5rem;
}

View File

@ -40,7 +40,8 @@
{% endblock content %}
</div>
{% load version %}
<span class="fixed left-2 bottom-2 text-xs text-slate-300 dark:text-slate-600">{% version %} ({% version_date %})</span>
<span class="fixed left-2 bottom-2 text-xs text-slate-300 dark:text-slate-600">{% version %} ({% version_date
%})</span>
</div>
{% block scripts %}
{% endblock scripts %}

View File

@ -1,16 +1,9 @@
{% fragment as default_content %}
{% load randomid %}
{% for td in data %}
{% if forloop.first %}
<th scope="row"
class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white min-w-30char">
{% randomid td as th_popover_id %}
<span data-popover-target="{{ th_popover_id }}">{{ td|truncatechars:30 }}</span>
{% if td|length > 30 %}
{% #popover id=th_popover_id %}
{{ td }}
{% /popover %}
{% endif %}
class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white min-w-30-char max-w-30char text-ellipsis overflow-hidden">
<span title="{{ td }}">{{ td }}</span>
</th>
{% else %}
{% #table_td %}

View File

@ -115,7 +115,7 @@
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Purchases</a>
</li>
<li>
<a href="{% url 'list_sessions' %}"
<a href="{% url 'add_session' %}"
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Sessions</a>
</li>
</ul>

View File

@ -1,11 +0,0 @@
import random
import string
from django import template
register = template.Library()
@register.simple_tag
def randomid(seed: str = "") -> str:
return str(hash(seed + "".join(random.choices(string.ascii_lowercase, k=10))))

View File

@ -1,6 +1,6 @@
from django.urls import path
from games import purchaseviews, sessionviews, views
from games import purchaseviews, views
urlpatterns = [
path("", views.index, name="index"),
@ -76,7 +76,7 @@ urlpatterns = [
{"template": "list_sessions.html#session-row"},
name="list_sessions_end_session",
),
path("session/list", sessionviews.list_sessions, name="list_sessions"),
path("session/list", views.list_sessions, name="list_sessions"),
path(
"session/list/recent",
views.list_sessions,

View File

@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, Callable
from typing import Any, Callable, TypedDict
from django.contrib.auth.decorators import login_required
from django.db.models import Avg, Count, ExpressionWrapper, F, Prefetch, Q, Sum, fields
@ -26,11 +26,10 @@ from .forms import (
PurchaseForm,
SessionForm,
)
from .models import Edition, Game, Platform, Purchase, Session
from .models import Edition, Game, Platform, Purchase, PurchaseQueryset, Session
dateformat: str = "%d/%m/%Y"
datetimeformat: str = "%d/%m/%Y %H:%M"
timeformat = "%H:%M"
def model_counts(request: HttpRequest) -> dict[str, bool]:
@ -80,7 +79,7 @@ def add_session(request: HttpRequest, purchase_id: int = 0) -> HttpResponse:
def use_custom_redirect(
func: Callable[..., HttpResponse],
func: Callable[..., HttpResponse]
) -> Callable[..., HttpResponse]:
"""
Will redirect to "return_path" session variable if set.

View File

@ -1,6 +1,5 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

46
poetry.lock generated
View File

@ -28,6 +28,50 @@ files = [
[package.extras]
tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"]
[[package]]
name = "black"
version = "24.8.0"
description = "The uncompromising code formatter."
optional = false
python-versions = ">=3.8"
files = [
{file = "black-24.8.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:09cdeb74d494ec023ded657f7092ba518e8cf78fa8386155e4a03fdcc44679e6"},
{file = "black-24.8.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:81c6742da39f33b08e791da38410f32e27d632260e599df7245cccee2064afeb"},
{file = "black-24.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:707a1ca89221bc8a1a64fb5e15ef39cd755633daa672a9db7498d1c19de66a42"},
{file = "black-24.8.0-cp310-cp310-win_amd64.whl", hash = "sha256:d6417535d99c37cee4091a2f24eb2b6d5ec42b144d50f1f2e436d9fe1916fe1a"},
{file = "black-24.8.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:fb6e2c0b86bbd43dee042e48059c9ad7830abd5c94b0bc518c0eeec57c3eddc1"},
{file = "black-24.8.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:837fd281f1908d0076844bc2b801ad2d369c78c45cf800cad7b61686051041af"},
{file = "black-24.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:62e8730977f0b77998029da7971fa896ceefa2c4c4933fcd593fa599ecbf97a4"},
{file = "black-24.8.0-cp311-cp311-win_amd64.whl", hash = "sha256:72901b4913cbac8972ad911dc4098d5753704d1f3c56e44ae8dce99eecb0e3af"},
{file = "black-24.8.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:7c046c1d1eeb7aea9335da62472481d3bbf3fd986e093cffd35f4385c94ae368"},
{file = "black-24.8.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:649f6d84ccbae73ab767e206772cc2d7a393a001070a4c814a546afd0d423aed"},
{file = "black-24.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2b59b250fdba5f9a9cd9d0ece6e6d993d91ce877d121d161e4698af3eb9c1018"},
{file = "black-24.8.0-cp312-cp312-win_amd64.whl", hash = "sha256:6e55d30d44bed36593c3163b9bc63bf58b3b30e4611e4d88a0c3c239930ed5b2"},
{file = "black-24.8.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:505289f17ceda596658ae81b61ebbe2d9b25aa78067035184ed0a9d855d18afd"},
{file = "black-24.8.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b19c9ad992c7883ad84c9b22aaa73562a16b819c1d8db7a1a1a49fb7ec13c7d2"},
{file = "black-24.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1f13f7f386f86f8121d76599114bb8c17b69d962137fc70efe56137727c7047e"},
{file = "black-24.8.0-cp38-cp38-win_amd64.whl", hash = "sha256:f490dbd59680d809ca31efdae20e634f3fae27fba3ce0ba3208333b713bc3920"},
{file = "black-24.8.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:eab4dd44ce80dea27dc69db40dab62d4ca96112f87996bca68cd75639aeb2e4c"},
{file = "black-24.8.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3c4285573d4897a7610054af5a890bde7c65cb466040c5f0c8b732812d7f0e5e"},
{file = "black-24.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9e84e33b37be070ba135176c123ae52a51f82306def9f7d063ee302ecab2cf47"},
{file = "black-24.8.0-cp39-cp39-win_amd64.whl", hash = "sha256:73bbf84ed136e45d451a260c6b73ed674652f90a2b3211d6a35e78054563a9bb"},
{file = "black-24.8.0-py3-none-any.whl", hash = "sha256:972085c618ee94f402da1af548a4f218c754ea7e5dc70acb168bfaca4c2542ed"},
{file = "black-24.8.0.tar.gz", hash = "sha256:2500945420b6784c38b9ee885af039f5e7471ef284ab03fa35ecdde4688cd83f"},
]
[package.dependencies]
click = ">=8.0.0"
mypy-extensions = ">=0.4.3"
packaging = ">=22.0"
pathspec = ">=0.9.0"
platformdirs = ">=2"
[package.extras]
colorama = ["colorama (>=0.4.3)"]
d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"]
jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"]
uvloop = ["uvloop (>=0.15.2)"]
[[package]]
name = "cfgv"
version = "3.4.0"
@ -928,4 +972,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "eb741020e400664070ed1eee24a17b6a9c07a2f2d44103e4947279aa26a40315"
content-hash = "ca9188453f62ec4470e2b2f8bc1e4a17ad421272f401328f82d6fede231dc737"

View File

@ -8,6 +8,7 @@ readme = "README.md"
packages = [{include = "timetracker"}]
[tool.poetry.group.dev.dependencies]
black = "^24.4.2"
mypy = "^1.10.1"
pyyaml = "^6.0.1"
pytest = "^8.2.2"

View File

@ -7,7 +7,6 @@ pkgs.mkShell {
nodejs
python3
poetry
ruff
];
shellHook = ''