Compare commits
38 Commits
v1.6.1
...
c10b7a8013
| Author | SHA1 | Date | |
|---|---|---|---|
|
c10b7a8013
|
|||
|
103c29e234
|
|||
|
5003b739d3
|
|||
|
4ba3ed555f
|
|||
|
e3b53cd4a9
|
|||
|
a4e697a274
|
|||
|
b8187c32b1
|
|||
|
bf2b86ba1f
|
|||
|
913c7d3a98
|
|||
|
37e3c69abc
|
|||
|
0866eb25e9
|
|||
|
39f21bc7db
|
|||
|
1416d00a37
|
|||
|
d9fe99963a
|
|||
|
393476be85
|
|||
|
e32af2f576
|
|||
|
e565002244
|
|||
|
1a4e51c95a
|
|||
|
eae020fd34
|
|||
|
1f4dd60c54
|
|||
|
656a96f55c
|
|||
|
8c3e819a5f
|
|||
|
ff11e35115
|
|||
|
ebef0bba87
|
|||
|
140f3d2bd6
|
|||
|
245a4f5b3e
|
|||
|
cd9f0b4111
|
|||
|
f82c61ef1e
|
|||
|
4e3b0ddb08
|
|||
|
a549050860
|
|||
|
596d1ccfe1
|
|||
|
bb26fec5e3
|
|||
|
1ba7de0bb7
|
|||
|
3391fb72f2
|
|||
|
0986e59fe7
|
|||
|
46b1199863
|
|||
|
bc1092b0b3
|
|||
|
996c0107c9
|
@@ -1,3 +1,8 @@
|
||||
## Unreleased
|
||||
|
||||
### Improved
|
||||
* Add a prompt to set game to Abandoned upon refund
|
||||
|
||||
## 1.6.1 / 2026-01-30 11:48+01:00
|
||||
|
||||
### New
|
||||
|
||||
@@ -40,7 +40,10 @@ caddy:
|
||||
caddy run --watch
|
||||
|
||||
dev-prod: migrate collectstatic
|
||||
PROD=1 uv run python -m gunicorn --bind 0.0.0.0:8001 timetracker.asgi:application -k uvicorn.workers.UvicornWorker
|
||||
@npx concurrently \
|
||||
--names "Django,Django-Q" \
|
||||
"PROD=1 uv run python -m gunicorn --bind 0.0.0.0:8001 timetracker.asgi:application -k uvicorn.workers.UvicornWorker"
|
||||
"uv run manage.py qcluster"
|
||||
|
||||
dumpgames:
|
||||
uv run python manage.py dumpdata --format yaml games --output tracker_fixture.yaml
|
||||
@@ -67,7 +70,7 @@ uv.lock: pyproject.toml
|
||||
uv sync
|
||||
|
||||
test: uv.lock
|
||||
uv run pytest
|
||||
uv run --with pytest-django pytest
|
||||
|
||||
date:
|
||||
uv run python -c 'import datetime; from zoneinfo import ZoneInfo; print(datetime.datetime.isoformat(datetime.datetime.now(ZoneInfo("Europe/Prague")), timespec="minutes", sep=" "))'
|
||||
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
# Game & Purchase Status Definitions
|
||||
|
||||
## Game Statuses
|
||||
|
||||
Games have a `status` field with the following values:
|
||||
|
||||
| Status | Code | Description |
|
||||
|--------|------|-------------|
|
||||
| **Unplayed** | `u` | Game was purchased but never played |
|
||||
| **Played** | `p` | Game was played but not yet finished |
|
||||
| **Finished** | `f` | Game has been completed |
|
||||
| **Retired** | `r` | Game was intentionally retired (e.g., no longer accessible, collector's item) |
|
||||
| **Abandoned** | `a` | Game was played but the user gave up on it |
|
||||
|
||||
**Setting game status:**
|
||||
- Users explicitly set game status via the UI (finish/drop purchase buttons, status change form)
|
||||
- Status changes are tracked in `GameStatusChange` model
|
||||
- Refunding a purchase always marks its games as abandoned
|
||||
|
||||
---
|
||||
|
||||
## Purchase-Level Status Concepts
|
||||
|
||||
These concepts determine whether a purchase appears in the "unfinished" or "dropped" lists in stats views.
|
||||
|
||||
### Finished
|
||||
|
||||
A purchase is considered **finished** when:
|
||||
|
||||
```
|
||||
Game.status == "f" OR Purchase.games.* has a PlayEvent with an ended date
|
||||
```
|
||||
|
||||
Either signal indicates the game is complete:
|
||||
- **Explicit**: User marked the game as finished (`Game.status = "f"`)
|
||||
- **Implicit**: A PlayEvent exists with `ended` date set (data-driven)
|
||||
|
||||
This uses **OR** logic during a transition period. Later, these signals should be kept in sync so only one source of truth is needed.
|
||||
|
||||
### Dropped
|
||||
|
||||
A purchase is considered **dropped** when:
|
||||
|
||||
```
|
||||
Game.status == "a" OR Purchase.date_refunded IS NOT NULL
|
||||
```
|
||||
|
||||
Either signal indicates the user no longer has an active interest in the game:
|
||||
- **Explicit**: User marked the game as abandoned (`Game.status = "a"`)
|
||||
- **Implicit**: User refunded the purchase (which automatically sets games to abandoned)
|
||||
|
||||
Note: Refunding a purchase always marks its games as abandoned. There is no option to refund without abandoning.
|
||||
|
||||
---
|
||||
|
||||
## Unfinished vs. Dropped
|
||||
|
||||
The stats views categorize purchases into **unfinished** and **dropped** lists.
|
||||
|
||||
### Unfinished
|
||||
|
||||
A purchase is **unfinished** when:
|
||||
1. It was purchased in the relevant time period (this year for yearly stats, all time for all-time stats)
|
||||
2. It was NOT refunded (only counts toward unfinished/backlog)
|
||||
3. It is NOT finished (per the finished definition above)
|
||||
4. It is NOT dropped (per the dropped definition above)
|
||||
5. It is NOT infinite (subscription, etc.)
|
||||
6. It IS a game or DLC (not season passes or battle passes)
|
||||
|
||||
**Unfinished = Active backlog** — games the user may still play.
|
||||
|
||||
### Dropped
|
||||
|
||||
A purchase is **dropped** when:
|
||||
1. It was purchased in the relevant time period
|
||||
2. It is NOT finished (per the finished definition above)
|
||||
3. It matches at least one dropped signal (per the dropped definition above)
|
||||
4. It is NOT infinite
|
||||
5. It IS a game or DLC
|
||||
|
||||
**Dropped = Terminal state** — games the user has given up on or refunded.
|
||||
|
||||
### Summary Table
|
||||
|
||||
| Category | Includes Refunded? | Key Condition |
|
||||
|----------|-------------------|---------------|
|
||||
| **Unfinished** | No | NOT finished, NOT dropped |
|
||||
| **Dropped** | Yes | Finished OR Abandoned/Retired |
|
||||
| **Refunded** | Yes | `date_refunded IS NOT NULL` |
|
||||
| **Infinite** | Yes | `infinite = True` |
|
||||
|
||||
---
|
||||
|
||||
## Query Patterns
|
||||
|
||||
### Checking if a game is finished
|
||||
|
||||
```python
|
||||
game.finished() # Returns True if status="f" or has PlayEvent with ended date
|
||||
```
|
||||
|
||||
### Checking if a game is abandoned
|
||||
|
||||
```python
|
||||
game.abandoned() # Returns True if status="a"
|
||||
```
|
||||
|
||||
### Getting finished purchases
|
||||
|
||||
```python
|
||||
Purchase.objects.finished() # All purchases where games are finished
|
||||
```
|
||||
|
||||
### Getting dropped purchases
|
||||
|
||||
```python
|
||||
Purchase.objects.dropped() # All purchases that are abandoned or refunded
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Transition State
|
||||
|
||||
The system uses **OR logic** for both finished and dropped to catch any mismatch between explicit user actions and data signals:
|
||||
|
||||
- **Finished**: `status="f" OR PlayEvent.ended`
|
||||
- **Dropped**: `status="a" OR date_refunded`
|
||||
|
||||
This bridges the gap between the old model (where `date_finished` and `date_dropped` were on the Purchase model) and the new model (where `Game.status` and `PlayEvent` are the sources of truth).
|
||||
|
||||
**Future:** These signals should be kept in sync. For example:
|
||||
- Setting `Game.status = "f"` should create a PlayEvent with `ended` date
|
||||
- When the sync is reliable, the OR can be simplified to a single check
|
||||
|
||||
Note: Refunding a purchase always automatically sets its games' status to Abandoned. This is not optional — there is no way to refund without abandoning.
|
||||
|
||||
---
|
||||
|
||||
## Edge Cases
|
||||
|
||||
### Unplayed games
|
||||
- Unplayed games (`status="u"`) are considered **unfinished**, not dropped
|
||||
- They appear in the unfinished/backlog list since they are still games the user may play
|
||||
- Unplayed games that are refunded DO count as **dropped** (refund signal overrides)
|
||||
|
||||
### Multiple games per purchase
|
||||
- A purchase can have multiple games via `Purchase.games` (many-to-many)
|
||||
- A purchase is finished if ANY of its games is finished
|
||||
- A purchase is dropped if ANY of its games is abandoned OR the purchase itself is refunded
|
||||
|
||||
### PlayEvents without ended date
|
||||
- A PlayEvent with `started` but no `ended` does NOT count as finished
|
||||
- This represents a game that was started but not completed
|
||||
|
||||
### Retired games
|
||||
- Retired games (`status="r"`) are considered **dropped**
|
||||
- Retirement is for games the user intentionally removed from their collection (collector's items, no longer accessible, etc.)
|
||||
@@ -0,0 +1,46 @@
|
||||
# Suggested Improvements to common/components.py
|
||||
|
||||
## Completed
|
||||
|
||||
### Caching on template rendering
|
||||
- Added `functools.lru_cache` on `_render_cached()` wrapper around `render_to_string`
|
||||
- Cache key: `(template_path, json.dumps(context, sort_keys=True))` — deterministic and unique
|
||||
- `maxsize=4096` in production, disabled entirely in DEBUG mode (so template changes are reflected immediately)
|
||||
- Only caches `template` path calls; `tag_name` calls are already nanosecond string ops
|
||||
- Verified working: identical calls return identical output, different inputs produce separate cache entries
|
||||
|
||||
### Non-deterministic IDs
|
||||
`randomid()` was replaced with `hashlib.sha1(content_hash.encode()).hexdigest()[:10]` for deterministic ID generation.
|
||||
- `Popover()` passes content hash (`wrapped_content:popover_content:wrapped_classes`) so IDs are deterministic per unique content
|
||||
- `games/templatetags/randomid.py` uses the same hash-based approach
|
||||
- Fixes: caching (Popover output now cacheable), page consistency, thread safety
|
||||
|
||||
### Inconsistent return types
|
||||
All component functions now return `SafeText` and are annotated accordingly. Redundant `mark_safe()` wrappers removed from `LinkedPurchase()` and `NameWithIcon()`.
|
||||
|
||||
### Fragile A() URL resolution
|
||||
Replaced single `url` parameter with explicit `url_name` (URL pattern name resolved via `reverse()`) and `href` (literal path). Removed dead `Callable` type hint. `reverse()` now raises `NoReverseMatch` instead of silently falling back to literal text. Added mutual exclusion check — providing both parameters raises `ValueError`. Updated all 10 call sites across 6 view files and internal callers (`LinkedPurchase()`, `NameWithIcon()`).
|
||||
|
||||
### Toast XSS vulnerability
|
||||
The vulnerable `Toast()` component (which used unsafe string escaping for
|
||||
Alpine.js interpolation) had no callers and was deleted entirely. Toast display
|
||||
is handled by the existing event-driven pipeline: middleware → `HX-Trigger`
|
||||
headers → `show-toast` CustomEvent → Alpine store.
|
||||
|
||||
### Default mutable arguments
|
||||
All functions with mutable defaults (`attributes` and `children`) changed from `= []` to `| None = None` with `or []` conversion in the body.
|
||||
|
||||
What was fixed: `attributes: list[HTMLAttribute] = []` and `children: list[HTMLTag] | HTMLTag = []` are a classic Python gotcha — the default is shared across all callers and could silently corrupt state if ever mutated in place. Changed 8 functions (`Component`, `Popover`, `A`, `Button`, `Div`, `Input`, `Form`, `Icon`) to use the `None` sentinel pattern, preventing future bugs and eliminating linter warnings.
|
||||
|
||||
### NameWithIcon dead code and untestable design
|
||||
The `NameWithIcon()` function had a `platform` parameter that was immediately overwritten by `platform = None` and never used (dead code). The function mixed data lookup (database queries via IDs) with rendering, making it untestable.
|
||||
|
||||
**Fix**: Refactored `NameWithIcon()` to follow the `LinkedPurchase` pattern — accepts model objects (`Game`, `Session`) instead of IDs. Extracted `_resolve_name_with_icon()` helper for testable computation logic (name resolution, platform extraction, link creation). Fixed bug where `platform` was not extracted when `session` parameter was passed. Removed dead `platform` parameter from the public API. Updated all 3 production call sites (already using model objects). Added 10 unit tests for `_resolve_name_with_icon()` covering session override, custom names, linkify behavior, platform resolution, and edge cases. Updated 6 integration tests to use model-based parameters.
|
||||
|
||||
### No tests
|
||||
Zero test coverage for the entire component system.
|
||||
|
||||
**Fix**: Add unit tests for each component function — basic rendering, edge cases,
|
||||
and cache hit/miss verification.
|
||||
|
||||
**Done**: 96 unit tests covering all component functions (`Component`, `randomid`, `Popover`, `PopoverTruncated`, `A`, `Button`, `Div`, `Icon`, `Form`, `Input`, `NameWithIcon`, `LinkedPurchase`, `PurchasePrice`, `_render_cached`, `enable_cache`). Includes template rendering, deterministic ID generation, LRU cache behavior, HTML output validation, edge cases, error handling, and model-dependent integration tests.
|
||||
+131
-80
@@ -1,11 +1,13 @@
|
||||
from random import choices as random_choices
|
||||
from string import ascii_lowercase
|
||||
from typing import Any, Callable
|
||||
import hashlib
|
||||
import json
|
||||
from functools import lru_cache
|
||||
from typing import Any
|
||||
|
||||
from django.conf import settings
|
||||
from django.template import TemplateDoesNotExist
|
||||
from django.template.defaultfilters import floatformat
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import NoReverseMatch, reverse
|
||||
from django.urls import reverse
|
||||
from django.utils.safestring import SafeText, mark_safe
|
||||
|
||||
from common.utils import truncate
|
||||
@@ -15,12 +17,32 @@ HTMLAttribute = tuple[str, str | int | bool]
|
||||
HTMLTag = str
|
||||
|
||||
|
||||
def _render_cached_impl(template: str, context_json: str) -> str:
|
||||
context = json.loads(context_json)
|
||||
context["slot"] = mark_safe(context["slot"])
|
||||
return render_to_string(template, context)
|
||||
|
||||
|
||||
if not settings.DEBUG:
|
||||
_render_cached = lru_cache(maxsize=4096)(_render_cached_impl)
|
||||
else:
|
||||
_render_cached = _render_cached_impl
|
||||
|
||||
|
||||
def enable_cache():
|
||||
"""Wrap _render_cached with LRU cache (for testing in DEBUG mode)."""
|
||||
global _render_cached
|
||||
_render_cached = lru_cache(maxsize=4096)(_render_cached_impl)
|
||||
|
||||
|
||||
def Component(
|
||||
attributes: list[HTMLAttribute] = [],
|
||||
children: list[HTMLTag] | HTMLTag = [],
|
||||
attributes: list[HTMLAttribute] | None = None,
|
||||
children: list[HTMLTag] | HTMLTag | None = None,
|
||||
template: str = "",
|
||||
tag_name: str = "",
|
||||
) -> HTMLTag:
|
||||
) -> SafeText:
|
||||
attributes = attributes or []
|
||||
children = children or []
|
||||
if not tag_name and not template:
|
||||
raise ValueError("One of template or tag_name is required.")
|
||||
if isinstance(children, str):
|
||||
@@ -37,28 +59,32 @@ def Component(
|
||||
if tag_name != "":
|
||||
tag = f"<{tag_name}{attributesBlob}>{childrenBlob}</{tag_name}>"
|
||||
elif template != "":
|
||||
tag = render_to_string(
|
||||
template,
|
||||
{name: value for name, value in attributes}
|
||||
| {"slot": mark_safe("\n".join(children))},
|
||||
)
|
||||
context = {name: value for name, value in attributes} | {"slot": "\n".join(children)}
|
||||
tag = _render_cached(template, json.dumps(context, sort_keys=True))
|
||||
return mark_safe(tag)
|
||||
|
||||
|
||||
def randomid(seed: str = "", length: int = 10) -> str:
|
||||
return seed + "".join(random_choices(ascii_lowercase, k=length))
|
||||
def randomid(seed: str = "", content: str = "", length: int = 10) -> str:
|
||||
if not seed and not content:
|
||||
return seed
|
||||
hash_input = f"{seed}:{content}" if seed else content
|
||||
content_hash = hashlib.sha1(hash_input.encode()).hexdigest()
|
||||
base = content_hash[:length] if not seed else content_hash[:max(0, length - len(seed))]
|
||||
return seed + base
|
||||
|
||||
|
||||
def Popover(
|
||||
popover_content: str,
|
||||
wrapped_content: str = "",
|
||||
wrapped_classes: str = "",
|
||||
children: list[HTMLTag] = [],
|
||||
attributes: list[HTMLAttribute] = [],
|
||||
children: list[HTMLTag] | None = None,
|
||||
attributes: list[HTMLAttribute] | None = None,
|
||||
) -> str:
|
||||
attributes = attributes or []
|
||||
children = children or []
|
||||
if not wrapped_content and not children:
|
||||
raise ValueError("One of wrapped_content or children is required.")
|
||||
id = randomid()
|
||||
id = randomid(content=f"{wrapped_content}:{popover_content}:{wrapped_classes}")
|
||||
return Component(
|
||||
attributes=attributes
|
||||
+ [
|
||||
@@ -105,41 +131,42 @@ def PopoverTruncated(
|
||||
|
||||
|
||||
def A(
|
||||
attributes: list[HTMLAttribute] = [],
|
||||
children: list[HTMLTag] | HTMLTag = [],
|
||||
url: str | Callable[..., Any] = "",
|
||||
):
|
||||
attributes: list[HTMLAttribute] | None = None,
|
||||
children: list[HTMLTag] | HTMLTag | None = None,
|
||||
url_name: str | None = None,
|
||||
href: str | None = None,
|
||||
) -> SafeText:
|
||||
"""
|
||||
Returns the HTML tag "a".
|
||||
"url" can either be:
|
||||
- URL (string)
|
||||
- path name passed to reverse() (string)
|
||||
- function
|
||||
Returns an anchor <a> tag.
|
||||
|
||||
Accepts one of two mutually-exclusive URL specifications:
|
||||
- url_name: URL pattern name, resolved via reverse()
|
||||
- href: Literal path string passed through as-is
|
||||
"""
|
||||
attributes = attributes or []
|
||||
children = children or []
|
||||
if url_name is not None and href is not None:
|
||||
raise ValueError("Provide exactly one of 'url_name' or 'href', not both.")
|
||||
|
||||
additional_attributes = []
|
||||
if url:
|
||||
if type(url) is str:
|
||||
try:
|
||||
url_result = reverse(url)
|
||||
except NoReverseMatch:
|
||||
url_result = url
|
||||
elif callable(url):
|
||||
url_result = url()
|
||||
else:
|
||||
raise TypeError("'url' is neither str nor function.")
|
||||
additional_attributes = [("href", url_result)]
|
||||
if url_name is not None:
|
||||
additional_attributes = [("href", reverse(url_name))]
|
||||
elif href is not None:
|
||||
additional_attributes = [("href", href)]
|
||||
return Component(
|
||||
tag_name="a", attributes=attributes + additional_attributes, children=children
|
||||
)
|
||||
|
||||
|
||||
def Button(
|
||||
attributes: list[HTMLAttribute] = [],
|
||||
children: list[HTMLTag] | HTMLTag = [],
|
||||
attributes: list[HTMLAttribute] | None = None,
|
||||
children: list[HTMLTag] | HTMLTag | None = None,
|
||||
size: str = "base",
|
||||
icon: bool = False,
|
||||
color: str = "blue",
|
||||
):
|
||||
) -> SafeText:
|
||||
attributes = attributes or []
|
||||
children = children or []
|
||||
return Component(
|
||||
template="cotton/button.html",
|
||||
attributes=attributes
|
||||
@@ -154,17 +181,21 @@ def Button(
|
||||
|
||||
|
||||
def Div(
|
||||
attributes: list[HTMLAttribute] = [],
|
||||
children: list[HTMLTag] | HTMLTag = [],
|
||||
):
|
||||
attributes: list[HTMLAttribute] | None = None,
|
||||
children: list[HTMLTag] | HTMLTag | None = None,
|
||||
) -> SafeText:
|
||||
attributes = attributes or []
|
||||
children = children or []
|
||||
return Component(tag_name="div", attributes=attributes, children=children)
|
||||
|
||||
|
||||
def Input(
|
||||
type: str = "text",
|
||||
attributes: list[HTMLAttribute] = [],
|
||||
children: list[HTMLTag] | HTMLTag = [],
|
||||
):
|
||||
attributes: list[HTMLAttribute] | None = None,
|
||||
children: list[HTMLTag] | HTMLTag | None = None,
|
||||
) -> SafeText:
|
||||
attributes = attributes or []
|
||||
children = children or []
|
||||
return Component(
|
||||
tag_name="input", attributes=attributes + [("type", type)], children=children
|
||||
)
|
||||
@@ -173,9 +204,11 @@ def Input(
|
||||
def Form(
|
||||
action="",
|
||||
method="get",
|
||||
attributes: list[HTMLAttribute] = [],
|
||||
children: list[HTMLTag] | HTMLTag = [],
|
||||
):
|
||||
attributes: list[HTMLAttribute] | None = None,
|
||||
children: list[HTMLTag] | HTMLTag | None = None,
|
||||
) -> SafeText:
|
||||
attributes = attributes or []
|
||||
children = children or []
|
||||
return Component(
|
||||
tag_name="form",
|
||||
attributes=attributes + [("action", action), ("method", method)],
|
||||
@@ -185,8 +218,9 @@ def Form(
|
||||
|
||||
def Icon(
|
||||
name: str,
|
||||
attributes: list[HTMLAttribute] = [],
|
||||
):
|
||||
attributes: list[HTMLAttribute] | None = None,
|
||||
) -> SafeText:
|
||||
attributes = attributes or []
|
||||
try:
|
||||
result = Component(template=f"cotton/icon/{name}.html", attributes=attributes)
|
||||
except TemplateDoesNotExist:
|
||||
@@ -195,7 +229,7 @@ def Icon(
|
||||
|
||||
|
||||
def LinkedPurchase(purchase: Purchase) -> SafeText:
|
||||
link = reverse("view_purchase", args=[int(purchase.id)])
|
||||
link = reverse("games:view_purchase", args=[int(purchase.id)])
|
||||
link_content = ""
|
||||
popover_content = ""
|
||||
game_count = purchase.games.count()
|
||||
@@ -232,35 +266,20 @@ def LinkedPurchase(purchase: Purchase) -> SafeText:
|
||||
),
|
||||
],
|
||||
)
|
||||
return mark_safe(A(url=link, children=[a_content]))
|
||||
return A(href=link, children=[a_content])
|
||||
|
||||
|
||||
def NameWithIcon(
|
||||
name: str = "",
|
||||
platform: str = "",
|
||||
game_id: int = 0,
|
||||
session_id: int = 0,
|
||||
purchase_id: int = 0,
|
||||
game: Game | None = None,
|
||||
session: Session | None = None,
|
||||
linkify: bool = True,
|
||||
emulated: bool = False,
|
||||
) -> SafeText:
|
||||
create_link = False
|
||||
link = ""
|
||||
platform = None
|
||||
if (game_id != 0 or session_id != 0 or purchase_id != 0) and linkify:
|
||||
create_link = True
|
||||
if session_id:
|
||||
session = Session.objects.get(pk=session_id)
|
||||
emulated = session.emulated
|
||||
game_id = session.game.pk
|
||||
if purchase_id:
|
||||
purchase = Purchase.objects.get(pk=purchase_id)
|
||||
game_id = purchase.games.first().pk
|
||||
if game_id:
|
||||
game = Game.objects.get(pk=game_id)
|
||||
name = name or game.name
|
||||
platform = game.platform
|
||||
link = reverse("view_game", args=[int(game_id)])
|
||||
_name, platform, final_emulated, create_link, link = _resolve_name_with_icon(
|
||||
name, game, session, linkify
|
||||
)
|
||||
|
||||
content = Div(
|
||||
[("class", "inline-flex gap-2 items-center")],
|
||||
[
|
||||
@@ -270,24 +289,56 @@ def NameWithIcon(
|
||||
)
|
||||
if platform
|
||||
else "",
|
||||
Icon("emulated", [("title", "Emulated")]) if emulated else "",
|
||||
PopoverTruncated(name),
|
||||
Icon("emulated", [("title", "Emulated")]) if final_emulated else "",
|
||||
PopoverTruncated(_name),
|
||||
],
|
||||
)
|
||||
|
||||
return mark_safe(
|
||||
return (
|
||||
A(
|
||||
url=link,
|
||||
href=link,
|
||||
children=[content],
|
||||
)
|
||||
if create_link
|
||||
else content,
|
||||
else content
|
||||
)
|
||||
|
||||
|
||||
def PurchasePrice(purchase) -> str:
|
||||
def _resolve_name_with_icon(
|
||||
name: str,
|
||||
game: Game | None,
|
||||
session: Session | None,
|
||||
linkify: bool,
|
||||
) -> tuple[str, Any, bool, bool, str]:
|
||||
create_link = False
|
||||
link = ""
|
||||
platform = None
|
||||
final_emulated = False
|
||||
|
||||
if session is not None:
|
||||
game = session.game
|
||||
platform = game.platform
|
||||
final_emulated = session.emulated
|
||||
if linkify:
|
||||
create_link = True
|
||||
link = reverse("games:view_game", args=[int(game.pk)])
|
||||
elif game is not None:
|
||||
platform = game.platform
|
||||
if linkify:
|
||||
create_link = True
|
||||
link = reverse("games:view_game", args=[int(game.pk)])
|
||||
|
||||
_name = name or (game.name if game else "")
|
||||
|
||||
return _name, platform, final_emulated, create_link, link
|
||||
|
||||
|
||||
def PurchasePrice(purchase) -> SafeText:
|
||||
return Popover(
|
||||
popover_content=f"{floatformat(purchase.price)} {purchase.price_currency}",
|
||||
wrapped_content=f"{floatformat(purchase.converted_price)} {purchase.converted_currency}",
|
||||
wrapped_classes="underline decoration-dotted",
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
+51
-58
@@ -4,7 +4,8 @@
|
||||
@plugin '@tailwindcss/forms';
|
||||
@plugin 'flowbite/plugin';
|
||||
|
||||
@source '../node_modules/flowbite/**/*.js';
|
||||
@source "../node_modules/flowbite";
|
||||
@import "flowbite/src/themes/default";
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
@@ -25,6 +26,7 @@
|
||||
--color-background: #1f2937;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
The default border color has changed to `currentcolor` in Tailwind CSS v4,
|
||||
so we've added these compatibility styles to make sure everything still
|
||||
@@ -103,16 +105,6 @@
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a:hover {
|
||||
text-decoration-color: #ff4400;
|
||||
color: rgb(254, 185, 160);
|
||||
transition: all 0.2s ease-out;
|
||||
} */
|
||||
|
||||
/* form label {
|
||||
@apply dark:text-slate-400;
|
||||
} */
|
||||
|
||||
.responsive-table {
|
||||
@apply dark:text-white mx-auto table-fixed;
|
||||
}
|
||||
@@ -135,38 +127,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* form input,
|
||||
select,
|
||||
textarea {
|
||||
@apply dark:border dark:border-slate-900 dark:bg-slate-500 dark:text-slate-100;
|
||||
} */
|
||||
|
||||
form input:disabled,
|
||||
select:disabled,
|
||||
textarea:disabled {
|
||||
@apply dark:bg-slate-800 dark:text-slate-500 cursor-not-allowed;
|
||||
@apply cursor-not-allowed bg-neutral-secondary-strong text-fg-disabled;
|
||||
|
||||
}
|
||||
|
||||
.errorlist {
|
||||
@apply mt-4 mb-1 pl-3 py-2 bg-red-600 text-slate-200 w-[300px];
|
||||
}
|
||||
|
||||
/* @media screen and (min-width: 768px) {
|
||||
form input,
|
||||
select,
|
||||
textarea {
|
||||
width: 300px;
|
||||
}
|
||||
} */
|
||||
|
||||
/* @media screen and (max-width: 768px) {
|
||||
form input,
|
||||
select,
|
||||
textarea {
|
||||
width: 150px;
|
||||
}
|
||||
} */
|
||||
|
||||
#button-container button {
|
||||
@apply mx-1;
|
||||
}
|
||||
@@ -207,34 +178,56 @@ textarea:disabled {
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
/* .truncate-container {
|
||||
@apply inline-block relative;
|
||||
a {
|
||||
@apply inline-block truncate max-w-20char transition-all group-hover:absolute group-hover:max-w-none group-hover:-top-8 group-hover:-left-6 group-hover:min-w-60 group-hover:px-6 group-hover:py-3.5 group-hover:bg-purple-600 group-hover:rounded-sm group-hover:outline-dashed group-hover:outline-purple-400 group-hover:outline-4;
|
||||
|
||||
#add-form {
|
||||
label + select, input, textarea {
|
||||
@apply mt-1;
|
||||
}
|
||||
form {
|
||||
@apply flex flex-col gap-3;
|
||||
}
|
||||
} */
|
||||
|
||||
.form-row-button-group {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
@apply gap-0 p-0;
|
||||
button {
|
||||
@apply mr-0;
|
||||
&:first-child {
|
||||
@apply rounded-e-none;
|
||||
}
|
||||
&:nth-child(2) {
|
||||
@apply rounded-none;
|
||||
}
|
||||
&:last-child {
|
||||
@apply rounded-s-none;
|
||||
}
|
||||
}
|
||||
}
|
||||
label {
|
||||
@apply dark:text-slate-500;
|
||||
@apply mb-2.5 text-sm font-medium text-heading;
|
||||
}
|
||||
input:not([type="checkbox"]) {
|
||||
@apply mb-3 bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base focus:ring-brand focus:border-brand block w-full px-3 py-2.5 shadow-xs placeholder:text-body;
|
||||
}
|
||||
input[type="checkbox"] {
|
||||
@apply w-4 h-4 border border-default-medium rounded-xs bg-neutral-secondary-medium focus:ring-2 focus:ring-brand-soft;
|
||||
}
|
||||
select {
|
||||
@apply w-full px-3 py-2.5 bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base focus:ring-brand focus:border-brand shadow-xs placeholder:text-body;
|
||||
}
|
||||
textarea {
|
||||
@apply bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base focus:ring-brand focus:border-brand block w-full p-3.5 shadow-xs placeholder:text-body;
|
||||
}
|
||||
:has(> label + input[type="checkbox"]) {
|
||||
@apply mt-3; /* needed because compared to all other form elements checkbox and its label are on the same row */
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
|
||||
[type="text"], [type="password"], [type="datetime-local"], [type="datetime"], [type="date"], [type="number"], select, textarea {
|
||||
@apply dark:bg-slate-600 dark:text-slate-300;
|
||||
@layer utilities {
|
||||
.toast-container {
|
||||
@apply fixed z-50 flex flex-col items-end bottom-0 right-0 p-4;
|
||||
}
|
||||
|
||||
[type="submit"] {
|
||||
@apply dark:text-white font-bold dark:bg-blue-600 px-4 py-2;
|
||||
}
|
||||
|
||||
form div label {
|
||||
@apply dark:text-white;
|
||||
}
|
||||
|
||||
form div {
|
||||
@apply flex flex-col;
|
||||
}
|
||||
|
||||
div [type="submit"] {
|
||||
@apply mt-3;
|
||||
}
|
||||
|
||||
+25
-4
@@ -1,11 +1,12 @@
|
||||
from datetime import date, datetime
|
||||
from typing import List
|
||||
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.timezone import now as django_timezone_now
|
||||
from ninja import Field, ModelSchema, NinjaAPI, Router, Schema
|
||||
from ninja import Field, ModelSchema, NinjaAPI, Router, Schema, Status
|
||||
|
||||
from games.models import Game, PlayEvent
|
||||
from games.models import Game, PlayEvent, Session
|
||||
|
||||
api = NinjaAPI()
|
||||
playevent_router = Router()
|
||||
@@ -54,7 +55,8 @@ def partial_update_game(request, game_id: int, payload: GameStatusUpdate):
|
||||
game = get_object_or_404(Game, id=game_id)
|
||||
setattr(game, "status", payload.status)
|
||||
game.save()
|
||||
return 204, None
|
||||
messages.success(request, "Status updated")
|
||||
return Status(204, None)
|
||||
|
||||
|
||||
@playevent_router.get("/", response=List[PlayEventOut])
|
||||
@@ -65,6 +67,7 @@ def list_playevents(request):
|
||||
@playevent_router.post("/", response={201: PlayEventOut})
|
||||
def create_playevent(request, payload: PlayEventIn):
|
||||
playevent = PlayEvent.objects.create(**payload.dict())
|
||||
messages.success(request, "Game played!")
|
||||
return playevent
|
||||
|
||||
|
||||
@@ -87,9 +90,27 @@ def partial_update_playevent(request, playevent_id: int, payload: UpdatePlayEven
|
||||
def delete_playevent(request, playevent_id: int):
|
||||
playevent = get_object_or_404(PlayEvent, id=playevent_id)
|
||||
playevent.delete()
|
||||
return 204, None
|
||||
return Status(204, None)
|
||||
|
||||
|
||||
api.add_router("/playevent", playevent_router)
|
||||
api.add_router("/games", game_router)
|
||||
|
||||
session_router = Router()
|
||||
|
||||
|
||||
class SessionDeviceUpdate(Schema):
|
||||
device_id: int
|
||||
|
||||
|
||||
@session_router.patch("/{session_id}/device", response={204: None})
|
||||
def partial_update_session_device(request, session_id: int, payload: SessionDeviceUpdate):
|
||||
session = get_object_or_404(Session, id=session_id)
|
||||
session.device_id = payload.device_id
|
||||
session.save()
|
||||
messages.success(request, "Device updated")
|
||||
return Status(204, None)
|
||||
|
||||
|
||||
api.add_router("/session", session_router)
|
||||
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ class PurchaseForm(forms.ModelForm):
|
||||
|
||||
# Automatically update related_purchase <select/>
|
||||
# to only include purchases of the selected game.
|
||||
related_purchase_by_game_url = reverse("related_purchase_by_game")
|
||||
related_purchase_by_game_url = reverse("games:related_purchase_by_game")
|
||||
self.fields["games"].widget.attrs.update(
|
||||
{
|
||||
"hx-trigger": "load, click",
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from .game import Mutation as GameMutation
|
||||
@@ -1,29 +0,0 @@
|
||||
import graphene
|
||||
|
||||
from games.graphql.types import Game
|
||||
from games.models import Game as GameModel
|
||||
|
||||
|
||||
class UpdateGameMutation(graphene.Mutation):
|
||||
class Arguments:
|
||||
id = graphene.ID(required=True)
|
||||
name = graphene.String()
|
||||
year_released = graphene.Int()
|
||||
wikidata = graphene.String()
|
||||
|
||||
game = graphene.Field(Game)
|
||||
|
||||
def mutate(self, info, id, name=None, year_released=None, wikidata=None):
|
||||
game_instance = GameModel.objects.get(pk=id)
|
||||
if name is not None:
|
||||
game_instance.name = name
|
||||
if year_released is not None:
|
||||
game_instance.year_released = year_released
|
||||
if wikidata is not None:
|
||||
game_instance.wikidata = wikidata
|
||||
game_instance.save()
|
||||
return UpdateGameMutation(game=game_instance)
|
||||
|
||||
|
||||
class Mutation(graphene.ObjectType):
|
||||
update_game = UpdateGameMutation.Field()
|
||||
@@ -1,5 +0,0 @@
|
||||
from .device import Query as DeviceQuery
|
||||
from .game import Query as GameQuery
|
||||
from .platform import Query as PlatformQuery
|
||||
from .purchase import Query as PurchaseQuery
|
||||
from .session import Query as SessionQuery
|
||||
@@ -1,11 +0,0 @@
|
||||
import graphene
|
||||
|
||||
from games.graphql.types import Device
|
||||
from games.models import Device as DeviceModel
|
||||
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
devices = graphene.List(Device)
|
||||
|
||||
def resolve_devices(self, info, **kwargs):
|
||||
return DeviceModel.objects.all()
|
||||
@@ -1,18 +0,0 @@
|
||||
import graphene
|
||||
|
||||
from games.graphql.types import Game
|
||||
from games.models import Game as GameModel
|
||||
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
games = graphene.List(Game)
|
||||
game_by_name = graphene.Field(Game, name=graphene.String(required=True))
|
||||
|
||||
def resolve_games(self, info, **kwargs):
|
||||
return GameModel.objects.all()
|
||||
|
||||
def resolve_game_by_name(self, info, name):
|
||||
try:
|
||||
return GameModel.objects.get(name=name)
|
||||
except GameModel.DoesNotExist:
|
||||
return None
|
||||
@@ -1,11 +0,0 @@
|
||||
import graphene
|
||||
|
||||
from games.graphql.types import Platform
|
||||
from games.models import Platform as PlatformModel
|
||||
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
platforms = graphene.List(Platform)
|
||||
|
||||
def resolve_platforms(self, info, **kwargs):
|
||||
return PlatformModel.objects.all()
|
||||
@@ -1,11 +0,0 @@
|
||||
import graphene
|
||||
|
||||
from games.graphql.types import Purchase
|
||||
from games.models import Purchase as PurchaseModel
|
||||
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
purchases = graphene.List(Purchase)
|
||||
|
||||
def resolve_purchases(self, info, **kwargs):
|
||||
return PurchaseModel.objects.all()
|
||||
@@ -1,11 +0,0 @@
|
||||
import graphene
|
||||
|
||||
from games.graphql.types import Session
|
||||
from games.models import Session as SessionModel
|
||||
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
sessions = graphene.List(Session)
|
||||
|
||||
def resolve_sessions(self, info, **kwargs):
|
||||
return SessionModel.objects.all()
|
||||
@@ -1,44 +0,0 @@
|
||||
from graphene_django import DjangoObjectType
|
||||
|
||||
from games.models import Device as DeviceModel
|
||||
from games.models import Edition as EditionModel
|
||||
from games.models import Game as GameModel
|
||||
from games.models import Platform as PlatformModel
|
||||
from games.models import Purchase as PurchaseModel
|
||||
from games.models import Session as SessionModel
|
||||
|
||||
|
||||
class Game(DjangoObjectType):
|
||||
class Meta:
|
||||
model = GameModel
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class Edition(DjangoObjectType):
|
||||
class Meta:
|
||||
model = EditionModel
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class Purchase(DjangoObjectType):
|
||||
class Meta:
|
||||
model = PurchaseModel
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class Session(DjangoObjectType):
|
||||
class Meta:
|
||||
model = SessionModel
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class Platform(DjangoObjectType):
|
||||
class Meta:
|
||||
model = PlatformModel
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class Device(DjangoObjectType):
|
||||
class Meta:
|
||||
model = DeviceModel
|
||||
fields = "__all__"
|
||||
@@ -0,0 +1,64 @@
|
||||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages as django_messages
|
||||
from django.contrib.messages import constants as message_constants
|
||||
|
||||
MESSAGE_LEVEL_MAP = {
|
||||
message_constants.DEBUG: "debug",
|
||||
message_constants.INFO: "info",
|
||||
message_constants.SUCCESS: "success",
|
||||
message_constants.WARNING: "warning",
|
||||
message_constants.ERROR: "error",
|
||||
}
|
||||
|
||||
|
||||
class HTMXMessagesMiddleware:
|
||||
"""
|
||||
Converts Django messages into HX-Trigger headers so toasts display
|
||||
automatically without changes to views.
|
||||
|
||||
Works for HTMX requests (processed natively by HTMX client),
|
||||
vanilla fetch() calls using fetchWithHtmxTriggers(), and is harmless
|
||||
for full-page loads (browsers ignore HX-Trigger).
|
||||
"""
|
||||
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
response = self.get_response(request)
|
||||
|
||||
# Skip HX-Trigger and don't consume messages if there's an HX-Redirect
|
||||
# so the message persists in the session for the redirect target page
|
||||
if "HX-Redirect" in response:
|
||||
return response
|
||||
|
||||
min_level = message_constants.DEBUG if settings.DEBUG else message_constants.INFO
|
||||
backend = django_messages.get_messages(request)
|
||||
if hasattr(backend, '_set_level') and backend._get_level() > min_level:
|
||||
backend._set_level(min_level)
|
||||
messages = list(backend)
|
||||
if not messages:
|
||||
return response
|
||||
|
||||
triggers = []
|
||||
for msg in messages:
|
||||
toast_type = MESSAGE_LEVEL_MAP.get(msg.level, "info")
|
||||
triggers.append(
|
||||
{
|
||||
"message": msg.message,
|
||||
"type": toast_type,
|
||||
}
|
||||
)
|
||||
|
||||
if triggers:
|
||||
# Use last message (most recent) as the primary toast
|
||||
trigger = triggers[-1]
|
||||
response["HX-Trigger"] = json.dumps(
|
||||
{
|
||||
"show-toast": trigger,
|
||||
}
|
||||
)
|
||||
|
||||
return response
|
||||
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 6.0.1 on 2026-05-12 11:57
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('games', '0015_alter_purchase_date_purchased_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='purchase',
|
||||
name='needs_price_update',
|
||||
field=models.BooleanField(db_index=True, default=True),
|
||||
),
|
||||
migrations.RunSQL(
|
||||
"UPDATE games_purchase SET needs_price_update = FALSE WHERE converted_price IS NOT NULL AND converted_currency != ''",
|
||||
reverse_sql="UPDATE games_purchase SET needs_price_update = TRUE WHERE converted_price IS NOT NULL AND converted_currency != ''",
|
||||
),
|
||||
]
|
||||
+20
-20
@@ -4,7 +4,7 @@ from datetime import timedelta
|
||||
import requests
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.db.models import F, Sum
|
||||
from django.db.models import F, Q, Sum
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.db.models.fields.generated import GeneratedField
|
||||
from django.db.models.functions import Coalesce
|
||||
@@ -66,7 +66,8 @@ class Game(models.Model):
|
||||
return self.name
|
||||
|
||||
def finished(self):
|
||||
return self.status == self.Status.FINISHED
|
||||
return (self.status == self.Status.FINISHED or
|
||||
self.playevents.filter(ended__isnull=False).exists())
|
||||
|
||||
def abandoned(self):
|
||||
return self.status == self.Status.ABANDONED
|
||||
@@ -120,6 +121,19 @@ class PurchaseQueryset(models.QuerySet):
|
||||
def games_only(self):
|
||||
return self.filter(type=Purchase.GAME)
|
||||
|
||||
def finished(self):
|
||||
return self.filter(
|
||||
Q(games__status="f") | Q(games__playevents__ended__isnull=False)
|
||||
).distinct()
|
||||
|
||||
def abandoned(self):
|
||||
return self.filter(games__status="a").distinct()
|
||||
|
||||
def dropped(self):
|
||||
return self.filter(
|
||||
Q(games__status="a") | Q(date_refunded__isnull=False)
|
||||
).distinct()
|
||||
|
||||
|
||||
class Purchase(models.Model):
|
||||
PHYSICAL = "ph"
|
||||
@@ -165,6 +179,7 @@ class Purchase(models.Model):
|
||||
price_currency = models.CharField(max_length=3, default="USD")
|
||||
converted_price = models.FloatField(null=True)
|
||||
converted_currency = models.CharField(max_length=3, blank=True, default="")
|
||||
needs_price_update = models.BooleanField(default=True, db_index=True)
|
||||
price_per_game = GeneratedField(
|
||||
expression=Coalesce(F("converted_price"), F("price"), 0) / F("num_purchases"),
|
||||
output_field=models.FloatField(),
|
||||
@@ -226,30 +241,15 @@ class Purchase(models.Model):
|
||||
def is_game(self):
|
||||
return self.type == self.GAME
|
||||
|
||||
def price_or_currency_differ_from(self, purchase_to_compare):
|
||||
return (
|
||||
self.price != purchase_to_compare.price
|
||||
or self.price_currency != purchase_to_compare.price_currency
|
||||
)
|
||||
def refund(self):
|
||||
self.date_refunded = timezone.now()
|
||||
self.save()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.type != Purchase.GAME and not self.related_purchase:
|
||||
raise ValidationError(
|
||||
f"{self.get_type_display()} must have a related purchase."
|
||||
)
|
||||
if self.pk is not None:
|
||||
# Retrieve the existing instance from the database
|
||||
existing_purchase = Purchase.objects.get(pk=self.pk)
|
||||
# If price has changed, reset converted fields
|
||||
if existing_purchase.price_or_currency_differ_from(self):
|
||||
from games.tasks import currency_to
|
||||
|
||||
exchange_rate = get_or_create_rate(
|
||||
self.price_currency, currency_to, self.date_purchased.year
|
||||
)
|
||||
if exchange_rate:
|
||||
self.converted_price = floatformat(self.price * exchange_rate, 0)
|
||||
self.converted_currency = currency_to
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import graphene
|
||||
|
||||
from games.graphql.mutations import GameMutation
|
||||
from games.graphql.queries import (
|
||||
DeviceQuery,
|
||||
EditionQuery,
|
||||
GameQuery,
|
||||
PlatformQuery,
|
||||
PurchaseQuery,
|
||||
SessionQuery,
|
||||
)
|
||||
|
||||
|
||||
class Query(
|
||||
GameQuery,
|
||||
EditionQuery,
|
||||
DeviceQuery,
|
||||
PlatformQuery,
|
||||
PurchaseQuery,
|
||||
SessionQuery,
|
||||
graphene.ObjectType,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
class Mutation(GameMutation, graphene.ObjectType):
|
||||
pass
|
||||
|
||||
|
||||
schema = graphene.Schema(query=Query, mutation=Mutation)
|
||||
@@ -17,6 +17,29 @@ from games.models import Game, GameStatusChange, Purchase, Session
|
||||
logger = logging.getLogger("games")
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Purchase)
|
||||
def store_purchase_price_snapshot(sender, instance, **kwargs):
|
||||
"""Store old price values before save so we can detect changes."""
|
||||
if instance.pk is not None:
|
||||
try:
|
||||
old_instance = sender.objects.get(pk=instance.pk)
|
||||
instance._old_price = old_instance.price
|
||||
instance._old_currency = old_instance.price_currency
|
||||
except sender.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
@receiver(post_save, sender=Purchase)
|
||||
def mark_needs_price_update(sender, instance, created, **kwargs):
|
||||
"""Mark purchase for price update if price or currency changed."""
|
||||
if not created and hasattr(instance, "_old_price"):
|
||||
if (
|
||||
instance.price != instance._old_price
|
||||
or instance.price_currency != instance._old_currency
|
||||
):
|
||||
sender.objects.filter(pk=instance.pk).update(needs_price_update=True)
|
||||
|
||||
|
||||
@receiver(m2m_changed, sender=Purchase.games.through)
|
||||
def update_num_purchases(sender, instance, action, reverse, **kwargs):
|
||||
if not reverse and action.startswith("post_"):
|
||||
|
||||
+2278
-318
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
(function() {
|
||||
htmx.defineExtension("hx-redirect-toast", {
|
||||
isInlineSwap: function(swapStyle) {
|
||||
return swapStyle === "hx-redirect-toast";
|
||||
},
|
||||
handleSwap: function(swapStyle, target, fragment, settleInfo, htmxConfig) {
|
||||
var xhr = htmxConfig.xhr;
|
||||
var hxRedirect = xhr.getResponseHeader("HX-Redirect");
|
||||
var hxTrigger = xhr.getResponseHeader("HX-Trigger");
|
||||
|
||||
// Redirect immediately (toast will be shown on the new page)
|
||||
if (hxRedirect) {
|
||||
window.location.href = hxRedirect;
|
||||
}
|
||||
|
||||
// Only dispatch HX-Trigger events for toasts when not redirecting
|
||||
if (!hxRedirect && hxTrigger) {
|
||||
var triggers = JSON.parse(hxTrigger);
|
||||
var events = Array.isArray(triggers) ? triggers : [triggers];
|
||||
events.forEach(function(triggerObj) {
|
||||
Object.entries(triggerObj).forEach(function(entry) {
|
||||
var name = entry[0];
|
||||
var detail = entry[1];
|
||||
try { detail = JSON.parse(detail); } catch(e) {}
|
||||
target.dispatchEvent(new CustomEvent(name, {
|
||||
detail: detail,
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
// Return null to prevent any DOM swap
|
||||
return null;
|
||||
}
|
||||
});
|
||||
})();
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,173 @@
|
||||
document.addEventListener("alpine:init", () => {
|
||||
let idCounter = 0;
|
||||
|
||||
console.log("[toast] Alpine available:", typeof Alpine !== "undefined");
|
||||
|
||||
Alpine.store("toasts", {
|
||||
toasts: [],
|
||||
|
||||
addToast(message, type) {
|
||||
console.log("[toast] addToast called:", { message, type });
|
||||
if (!type) type = "info";
|
||||
const validTypes = ["success", "error", "info", "warning", "debug"];
|
||||
if (!validTypes.includes(type)) type = "info";
|
||||
|
||||
if (this.toasts.length >= 3) {
|
||||
console.log("[toast] max 3 toasts reached, removing oldest");
|
||||
this.toasts.shift();
|
||||
}
|
||||
|
||||
const id = ++idCounter;
|
||||
console.log("[toast] toast added, count:", this.toasts.length);
|
||||
this.toasts.push({ id, message, type, visible: true, timer: null, pausedAt: null });
|
||||
|
||||
if (type !== "error") {
|
||||
const toast = this.toasts[this.toasts.length - 1];
|
||||
const autoDismissDelay = type === "debug" ? 3000 : 5000;
|
||||
toast.timer = setTimeout(() => {
|
||||
console.log("[toast] auto-dismiss after " + (autoDismissDelay / 1000) + "s");
|
||||
this.dismissToast(id);
|
||||
}, autoDismissDelay);
|
||||
}
|
||||
},
|
||||
|
||||
dismissToast(id) {
|
||||
console.log("[toast] dismissToast for id:", id);
|
||||
const idx = this.toasts.findIndex((t) => t.id === id);
|
||||
if (idx === -1) { console.log("[toast] toast not found"); return; }
|
||||
|
||||
const toast = this.toasts[idx];
|
||||
if (toast.timer) clearTimeout(toast.timer);
|
||||
toast.visible = false;
|
||||
|
||||
setTimeout(() => {
|
||||
this.toasts = this.toasts.filter((t) => t.id !== id);
|
||||
console.log("[toast] after dismiss, count:", this.toasts.length);
|
||||
}, 300);
|
||||
},
|
||||
|
||||
clearToastTimer(id) {
|
||||
const toast = this.toasts.find((t) => t.id === id);
|
||||
if (toast?.timer) {
|
||||
console.log("[toast] pause timer for toast id:", id);
|
||||
clearTimeout(toast.timer);
|
||||
toast.timer = null;
|
||||
toast.pausedAt = Date.now();
|
||||
}
|
||||
},
|
||||
|
||||
resumeToastTimer(id, duration) {
|
||||
const toast = this.toasts.find((t) => t.id === id);
|
||||
if (toast?.pausedAt && toast.timer === null) {
|
||||
console.log("[toast] resume timer for toast id:", id);
|
||||
toast.timer = setTimeout(() => {
|
||||
this.dismissToast(id);
|
||||
}, duration);
|
||||
toast.pausedAt = null;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Alpine.data("toastStore", () => ({
|
||||
init() {
|
||||
console.log("[toast] toastStore.init running");
|
||||
console.log("[toast] Alpine store toasts:", Alpine.store("toasts").toasts);
|
||||
|
||||
window.addEventListener("show-toast", (e) => {
|
||||
console.log("[toast] show-toast event received:", e.detail);
|
||||
if (Array.isArray(e.detail)) {
|
||||
e.detail.forEach((msg) => {
|
||||
Alpine.store("toasts").addToast(msg.message, msg.type);
|
||||
});
|
||||
} else {
|
||||
Alpine.store("toasts").addToast(e.detail.message, e.detail.type);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
const script = document.getElementById("django-messages");
|
||||
if (script) {
|
||||
const msgs = JSON.parse(
|
||||
script.textContent || script.innerText || "[]"
|
||||
);
|
||||
console.log("[toast] django-messages script found:", msgs);
|
||||
if (Array.isArray(msgs)) {
|
||||
msgs.forEach((msg) => {
|
||||
console.log("[toast] loading django-message:", msg);
|
||||
Alpine.store("toasts").addToast(msg.message, msg.type || "info");
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[toast] localStorage restore failed:", e);
|
||||
// ignore parse errors
|
||||
}
|
||||
},
|
||||
|
||||
addToast(message, type) {
|
||||
console.log("[toast] toastStore.addToast delegating:", { message, type });
|
||||
Alpine.store("toasts").addToast(message, type);
|
||||
},
|
||||
|
||||
dismissToast(id) {
|
||||
console.log("[toast] toastStore.dismissToast delegating:", id);
|
||||
Alpine.store("toasts").dismissToast(id);
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
function toast(message, type) {
|
||||
console.log("[toast] toast() called:", { message, type });
|
||||
const evt = new CustomEvent("show-toast", {
|
||||
detail: { message, type },
|
||||
bubbles: true,
|
||||
});
|
||||
document.dispatchEvent(evt);
|
||||
console.log("[toast] CustomEvent dispatched, type:", evt.type);
|
||||
}
|
||||
window.toast = toast;
|
||||
|
||||
/**
|
||||
* Wrapper around fetch() that dispatches HTMX HX-Trigger events.
|
||||
* Use this for any fetch() call that expects HX-Trigger headers
|
||||
* (e.g., to show toasts via the HTMX middleware).
|
||||
*
|
||||
* @todo Migrate these call sites to hx-post + hx-on::after-request
|
||||
* for HTMX-native toast handling.
|
||||
*/
|
||||
window.fetchWithHtmxTriggers = function fetchWithHtmxTriggers(url, options = {}) {
|
||||
console.log("[fetchWithHtmxTriggers] fetching:", url);
|
||||
return fetch(url, options).then(async (response) => {
|
||||
console.log("[fetchWithHtmxTriggers] response status:", response.status);
|
||||
const htmxTrigger = response.headers.get("HX-Trigger");
|
||||
console.log("[fetchWithHtmxTriggers] HX-Trigger header:", htmxTrigger);
|
||||
if (htmxTrigger) {
|
||||
let triggers;
|
||||
try {
|
||||
triggers = JSON.parse(htmxTrigger);
|
||||
console.log("[fetchWithHtmxTriggers] parsed triggers:", triggers);
|
||||
} catch {
|
||||
console.warn("[fetchWithHtmxTriggers] failed to parse HX-Trigger JSON");
|
||||
return response;
|
||||
}
|
||||
// Handle both single object and array of events
|
||||
const events = Array.isArray(triggers) ? triggers : [triggers];
|
||||
events.forEach((triggerObj) => {
|
||||
Object.entries(triggerObj).forEach(([name, detail]) => {
|
||||
console.log("[fetchWithHtmxTriggers] dispatching event:", name, detail);
|
||||
let parsedDetail = detail;
|
||||
try {
|
||||
parsedDetail = JSON.parse(detail);
|
||||
} catch {
|
||||
// keep as string
|
||||
}
|
||||
document.dispatchEvent(new CustomEvent(name, {
|
||||
detail: parsedDetail,
|
||||
bubbles: true,
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
return response;
|
||||
});
|
||||
};
|
||||
+45
-35
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
import requests
|
||||
from django.db import models
|
||||
from django.template.defaultfilters import floatformat
|
||||
|
||||
logger = logging.getLogger("games")
|
||||
@@ -12,41 +13,18 @@ currency_to = "CZK"
|
||||
currency_to = currency_to.upper()
|
||||
|
||||
|
||||
def save_converted_info(purchase, converted_price, converted_currency):
|
||||
logger.info(
|
||||
f"Setting converted price of {purchase} to {converted_price} {converted_currency} (originally {purchase.price} {purchase.price_currency})"
|
||||
)
|
||||
purchase.converted_price = converted_price
|
||||
purchase.converted_currency = converted_currency
|
||||
purchase.save()
|
||||
|
||||
|
||||
def convert_prices():
|
||||
purchases = Purchase.objects.filter(
|
||||
converted_price__isnull=True, converted_currency=""
|
||||
)
|
||||
if purchases.count() == 0:
|
||||
logger.info("[convert_prices]: No prices to convert.")
|
||||
|
||||
for purchase in purchases:
|
||||
if purchase.price_currency.upper() == currency_to or purchase.price == 0:
|
||||
save_converted_info(purchase, purchase.price, currency_to)
|
||||
continue
|
||||
year = purchase.date_purchased.year
|
||||
currency_from = purchase.price_currency.upper()
|
||||
|
||||
exchange_rate = ExchangeRate.objects.filter(
|
||||
currency_from=currency_from, currency_to=currency_to, year=year
|
||||
).first()
|
||||
logger.info(
|
||||
def _get_exchange_rate(currency_from, currency_to, year):
|
||||
logger.debug(
|
||||
f"[convert_prices]: Looking for exchange rate in database: {currency_from}->{currency_to}"
|
||||
)
|
||||
if not exchange_rate:
|
||||
logger.info(
|
||||
rate = ExchangeRate.objects.filter(
|
||||
currency_from=currency_from, currency_to=currency_to, year=year
|
||||
).first()
|
||||
if not rate:
|
||||
logger.debug(
|
||||
f"[convert_prices]: Getting exchange rate from {currency_from} to {currency_to} for {year}..."
|
||||
)
|
||||
try:
|
||||
# this API endpoint only accepts lowercase currency string
|
||||
response = requests.get(
|
||||
f"https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@{year}-01-01/v1/currencies/{currency_from.lower()}.json"
|
||||
)
|
||||
@@ -54,7 +32,6 @@ def convert_prices():
|
||||
data = response.json()
|
||||
currency_from_data = data.get(currency_from.lower())
|
||||
rate = currency_from_data.get(currency_to.lower())
|
||||
|
||||
if rate:
|
||||
logger.info(f"[convert_prices]: Got {rate}, saving...")
|
||||
exchange_rate = ExchangeRate.objects.create(
|
||||
@@ -63,17 +40,50 @@ def convert_prices():
|
||||
year=year,
|
||||
rate=floatformat(rate, 2),
|
||||
)
|
||||
rate = exchange_rate.rate
|
||||
else:
|
||||
logger.info("[convert_prices]: Could not get an exchange rate.")
|
||||
except requests.RequestException as e:
|
||||
logger.info(
|
||||
f"[convert_prices]: Failed to fetch exchange rate for {currency_from}->{currency_to} in {year}: {e}"
|
||||
)
|
||||
if exchange_rate:
|
||||
save_converted_info(
|
||||
elif rate:
|
||||
rate = rate.rate
|
||||
return rate
|
||||
|
||||
|
||||
def _save_converted_price(purchase, converted_price, needs_update):
|
||||
logger.info(
|
||||
f"Setting converted price of {purchase} to {converted_price} {currency_to} (originally {purchase.price} {purchase.price_currency})"
|
||||
)
|
||||
purchase.converted_price = converted_price
|
||||
purchase.converted_currency = currency_to
|
||||
if needs_update:
|
||||
purchase.needs_price_update = False
|
||||
purchase.save(update_fields=["converted_price", "converted_currency", "needs_price_update"])
|
||||
|
||||
|
||||
def convert_prices():
|
||||
purchases = Purchase.objects.filter(
|
||||
models.Q(needs_price_update=True) | models.Q(converted_price__isnull=True)
|
||||
).distinct()
|
||||
if purchases.count() == 0:
|
||||
logger.info("[convert_prices]: No prices to convert.")
|
||||
return
|
||||
|
||||
for purchase in purchases:
|
||||
needs_update = purchase.needs_price_update
|
||||
if purchase.price_currency.upper() == currency_to or purchase.price == 0:
|
||||
_save_converted_price(purchase, purchase.price, needs_update)
|
||||
continue
|
||||
year = purchase.date_purchased.year
|
||||
currency_from = purchase.price_currency.upper()
|
||||
rate = _get_exchange_rate(currency_from, currency_to, year)
|
||||
if rate:
|
||||
_save_converted_price(
|
||||
purchase,
|
||||
floatformat(purchase.price * exchange_rate.rate, 0),
|
||||
currency_to,
|
||||
floatformat(purchase.price * rate, 0),
|
||||
needs_update,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<c-layouts.add>
|
||||
<c-slot name="additional_row">
|
||||
<input type="submit"
|
||||
<c-button type="submit" color="gray"
|
||||
name="submit_and_redirect"
|
||||
value="Submit & Create Purchase" />
|
||||
>
|
||||
Submit & Create Purchase
|
||||
</c-button>
|
||||
</c-slot>
|
||||
</c-layouts.add>
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<input type="submit"
|
||||
<c-button type="submit"
|
||||
color="gray"
|
||||
name="submit_and_redirect"
|
||||
value="Submit & Create Session" />
|
||||
>
|
||||
Submit & Create Session
|
||||
</c-button>
|
||||
</td>
|
||||
</tr>
|
||||
</c-slot>
|
||||
|
||||
@@ -1,36 +1,38 @@
|
||||
<c-layouts.add>
|
||||
<c-slot name="form_content">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<table class="mx-auto">
|
||||
<div class="max-width-container">
|
||||
<div id="add-form" class="form-container max-w-xl mx-auto">
|
||||
<form method="post" enctype="multipart/form-data" class="">
|
||||
{% csrf_token %}
|
||||
{% for field in form %}
|
||||
<tr>
|
||||
<th>{{ field.label_tag }}</th>
|
||||
<div>
|
||||
{{ field.label_tag }}
|
||||
{% if field.name == "note" %}
|
||||
<td>{{ field }}</td>
|
||||
{{ field }}
|
||||
{% else %}
|
||||
<td>{{ field }}</td>
|
||||
{{ field }}
|
||||
{% endif %}
|
||||
{% if field.name == "timestamp_start" or field.name == "timestamp_end" %}
|
||||
<td>
|
||||
<div class="basic-button-container" hx-boost="false">
|
||||
<button class="basic-button" data-target="{{ field.name }}" data-type="now">Set to now</button>
|
||||
<button class="basic-button"
|
||||
data-target="{{ field.name }}"
|
||||
data-type="toggle">Toggle text</button>
|
||||
<button class="basic-button" data-target="{{ field.name }}" data-type="copy">Copy</button>
|
||||
</div>
|
||||
</td>
|
||||
<span class="form-row-button-group flex-row gap-3 justify-start mt-3" hx-boost="false">
|
||||
<c-button data-target="{{ field.name }}" data-type="now" size="xs">Set to now</c-button>
|
||||
<c-button data-target="{{ field.name }}" data-type="toggle" size="xs">Toggle text</c-button>
|
||||
<c-button data-target="{{ field.name }}" data-type="copy" size="xs">
|
||||
Copy {%if field.name == "timestamp_start" %}start{% else %}end{% endif %} value to {%if field.name == "timestamp_start" %}end{% else %}start{% endif %}
|
||||
</c-button>
|
||||
</span>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<input type="submit" value="Submit" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div>
|
||||
<c-button type="submit">
|
||||
Submit
|
||||
</c-button>
|
||||
</div>
|
||||
<div class="submit-button-container">
|
||||
{{ additional_row }}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</c-slot>
|
||||
</c-layouts.add>
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
<c-vars color="blue" size="base" type="button" />
|
||||
<button type="{{ type }}"
|
||||
title="{{ title }}"
|
||||
class="{{ class }} {% if color == "blue" %} bg-blue-700 dark:bg-blue-600 dark:focus:ring-blue-800 dark:hover:bg-blue-700 focus:ring-blue-300 hover:bg-blue-800 text-white {% elif color == "red" %} bg-red-700 dark:bg-red-600 dark:focus:ring-red-900 dark:hover:bg-red-700 focus:ring-red-300 hover:bg-red-800 text-white {% elif color == "gray" %} bg-white border-gray-200 dark:bg-gray-800 dark:border-gray-600 dark:focus:ring-gray-700 dark:hover:bg-gray-700 dark:hover:text-white dark:text-gray-400 focus:ring-gray-100 hover:bg-gray-100 hover:text-blue-700 text-gray-900 border {% elif color == "green" %} bg-green-700 dark:bg-green-600 dark:focus:ring-green-800 dark:hover:bg-green-700 focus:ring-green-300 hover:bg-green-800 text-white {% endif %} focus:outline-hidden focus:ring-4 font-medium mb-2 me-2 rounded-lg {% if size == "xs" %} px-3 py-2 text-xs {% elif size == "sm" %} px-3 py-2 text-sm {% elif size == "base" %} px-5 py-2.5 text-sm {% elif size == "lg" %} px-5 py-3 text-base {% elif size == "xl" %} px-6 py-3.5 text-base {% endif %} {% if icon %} inline-flex text-center items-center gap-2 {% else %} {% endif %} ">
|
||||
<button
|
||||
{% if hx_get %}hx-get="{{ hx_get }}"{% endif %}
|
||||
{% if hx_target %}hx-target="{{ hx_target }}"{% endif %}
|
||||
{% if hx_swap %}hx-swap="{{ hx_swap }}"{% endif %}
|
||||
{% if type %}type="{{ type }}"{% endif %}
|
||||
{% if title %}title="{{ title }}"{% endif %}
|
||||
{% if onclick %}onclick="{{ onclick }}"{% endif %}
|
||||
{% if data_target %}data-target="{{ data_target }}"{% endif %}
|
||||
{% if data_type %}data-type="{{ data_type }}"{% endif %}
|
||||
{% if name %}name="{{ name }}"{% endif %}
|
||||
class="{% if class %}{{ class }} {%else%}{%endif%}{% if color == "blue" %}text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium {% elif color == "red" %} bg-red-700 dark:bg-red-600 dark:focus:ring-red-900 dark:hover:bg-red-700 focus:ring-red-300 hover:bg-red-800 text-white {% elif color == "gray" %} bg-white border-gray-200 dark:bg-gray-800 dark:border-gray-600 dark:focus:ring-gray-700 dark:hover:bg-gray-700 dark:hover:text-white dark:text-gray-400 focus:ring-gray-100 hover:bg-gray-100 hover:text-blue-700 text-gray-900 border {% elif color == "green" %} bg-green-700 dark:bg-green-600 dark:focus:ring-green-800 dark:hover:bg-green-700 focus:ring-green-300 hover:bg-green-800 text-white {% endif %} leading-5 focus:outline-hidden focus:ring-4 font-medium mb-2 me-2 rounded-base {% if size == "xs" %} px-3 py-2 text-xs shadow-xs {% elif size == "sm" %} px-3 py-2 text-sm {% elif size == "base" %} px-5 py-2.5 text-sm {% elif size == "lg" %} px-5 py-3 text-base {% elif size == "xl" %} px-6 py-3.5 text-base {% endif %} {% if icon %} inline-flex text-center items-center gap-2 {% else %} {% endif %} ">
|
||||
{{ slot }}
|
||||
</button>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{% if slot %}{{ slot }}{% endif %}
|
||||
{% for button in buttons %}
|
||||
{% if button.slot %}
|
||||
<c-button-group-button-sm :href=button.href :slot=button.slot :color=button.color :hover=button.hover :title=button.title />
|
||||
<c-button-group-button-sm :href=button.href :slot=button.slot :color=button.color :hover=button.hover :title=button.title :hx_get=button.hx_get :hx_target=button.hx_target :hx_swap=button.hx_swap />
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<c-vars color="gray" />
|
||||
<a href="{{ href }}"
|
||||
{% if hx_get %}hx-get="{{ hx_get }}"{% endif %}
|
||||
{% if hx_target %}hx-target="{{ hx_target }}"{% endif %}
|
||||
{% if click %}@click="{{ click }}"{% endif %}
|
||||
class="[&:first-of-type_button]:rounded-s-lg [&:last-of-type_button]:rounded-e-lg">
|
||||
{% if color == "gray" %}
|
||||
<button type="button"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<span class="truncate-container">
|
||||
<a class="underline decoration-slate-500 sm:decoration-2"
|
||||
href="{% url 'view_game' game_id %}">
|
||||
href="{% url 'games:view_game' game_id %}">
|
||||
{% if slot %}
|
||||
{{ slot }}
|
||||
{% else %}
|
||||
|
||||
@@ -3,12 +3,16 @@
|
||||
{% if form_content %}
|
||||
{{ form_content }}
|
||||
{% else %}
|
||||
<div class="max-width-container">
|
||||
<div class="form-container max-w-xl mx-auto">
|
||||
<div id="add-form" class="max-width-container">
|
||||
<div id="add-form" class="form-container max-w-xl mx-auto">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ form.as_div }}
|
||||
<div><input type="submit" value="Submit" /></div>
|
||||
<div>
|
||||
<c-button type="submit" class="mt-3">
|
||||
Submit
|
||||
</c-button>
|
||||
</div>
|
||||
<div class="submit-button-container">
|
||||
{{ additional_row }}
|
||||
</div>
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Timetracker - {{ title }}</title>
|
||||
<script src="{% static 'js/htmx.min.js' %}"></script>
|
||||
<script>
|
||||
htmx.config.scrollBehavior = 'smooth';
|
||||
htmx.config.selfRequestsOnly = false;
|
||||
</script>
|
||||
<script src="{% static 'js/htmx-redirect-toast.js' %}"></script>
|
||||
{% django_htmx_script %}
|
||||
<link rel="stylesheet" href="{% static 'base.css' %}" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/flowbite@2.4.1/dist/flowbite.min.js"></script>
|
||||
@@ -25,7 +30,14 @@
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body hx-indicator="#indicator">
|
||||
<body hx-indicator="#indicator" class="bg-neutral-primary">
|
||||
<script id="django-messages" type="application/json">
|
||||
[
|
||||
{% for message in messages %}
|
||||
{"message": "{{ message|escapejs }}", "type": "{{ message.tags|default:'info' }}"}{% if not forloop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
]
|
||||
</script>
|
||||
<img id="indicator"
|
||||
src="{% static 'icons/loading.png' %}"
|
||||
class="absolute right-3 top-3 animate-spin htmx-indicator"
|
||||
@@ -34,7 +46,7 @@
|
||||
alt="loading indicator" />
|
||||
<div class="flex flex-col min-h-screen">
|
||||
{% include "navbar.html" %}
|
||||
<div class="flex flex-1 flex-col dark:bg-gray-800 pt-8">{{ slot }}</div>
|
||||
<div id="main-container" class="flex flex-1 flex-col pt-8 pb-16">{{ slot }}</div>
|
||||
{% load version %}
|
||||
<span class="fixed left-2 bottom-2 text-xs text-slate-300 dark:text-slate-600">{% version %} ({% version_date %})</span>
|
||||
</div>
|
||||
@@ -94,5 +106,107 @@
|
||||
}
|
||||
});
|
||||
</script>
|
||||
// hx-swap-oob makes sure the modal gets removed upon any HTMX response
|
||||
<div id="global-modal-container" hx-swap-oob="true"></div>
|
||||
|
||||
<div x-data="toastStore()"
|
||||
role="region"
|
||||
aria-label="Notifications"
|
||||
aria-atomic="true"
|
||||
class="fixed z-50 bottom-0 right-0 flex flex-col items-end pointer-events-none p-4">
|
||||
<template x-for="toast in $store.toasts.toasts" :key="toast.id">
|
||||
<div x-show="toast.visible"
|
||||
x-transition:enter="transition ease-out duration-300"
|
||||
x-transition:enter-start="opacity-0 translate-x-8"
|
||||
x-transition:enter-end="opacity-100 translate-x-0"
|
||||
x-transition:leave="transition ease-in duration-200"
|
||||
x-transition:leave-start="opacity-100 translate-x-0"
|
||||
x-transition:leave-end="opacity-0 translate-x-8"
|
||||
:role="toast.type === 'error' || toast.type === 'warning' ? 'alert' : 'status'"
|
||||
:aria-live="toast.type === 'error' ? 'assertive' : 'polite'"
|
||||
tabindex="0"
|
||||
class="pointer-events-auto max-w-sm w-72 cursor-pointer mb-3 last:mb-0"
|
||||
:class="{
|
||||
'success': toast.type === 'success',
|
||||
'error': toast.type === 'error',
|
||||
'info': toast.type === 'info',
|
||||
'warning': toast.type === 'warning',
|
||||
'debug': toast.type === 'debug'
|
||||
}"
|
||||
@click="dismissToast(toast.id)"
|
||||
@mouseenter="$store.toasts.clearToastTimer(toast.id)"
|
||||
@mouseleave="$store.toasts.resumeToastTimer(toast.id, 5000)"
|
||||
@keydown.escape="dismissToast(toast.id)">
|
||||
<div class="rounded-lg shadow-lg p-4 flex items-start gap-3"
|
||||
:class="{
|
||||
'bg-green-50 dark:bg-green-900 border border-green-200 dark:border-green-700': toast.type === 'success',
|
||||
'bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700': toast.type === 'error',
|
||||
'bg-blue-50 dark:bg-blue-900 border border-blue-200 dark:border-blue-700': toast.type === 'info',
|
||||
'bg-amber-50 dark:bg-amber-900 border border-amber-200 dark:border-amber-700': toast.type === 'warning',
|
||||
'bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700': toast.type === 'debug'
|
||||
}">
|
||||
<span class="flex-shrink-0 mt-0.5"
|
||||
:class="{
|
||||
'text-green-500': toast.type === 'success',
|
||||
'text-red-500': toast.type === 'error',
|
||||
'text-blue-500': toast.type === 'info',
|
||||
'text-amber-500': toast.type === 'warning',
|
||||
'text-gray-500': toast.type === 'debug'
|
||||
}">
|
||||
<template x-if="toast.type === 'success'">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
|
||||
</svg>
|
||||
</template>
|
||||
<template x-if="toast.type === 'error'">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
|
||||
</svg>
|
||||
</template>
|
||||
<template x-if="toast.type === 'info'">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M12 20a8 8 0 100-16 8 8 0 000 16z"/>
|
||||
</svg>
|
||||
</template>
|
||||
<template x-if="toast.type === 'warning'">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 13l5 5 5-5M7 6l5 5 5-5"/>
|
||||
</svg>
|
||||
</template>
|
||||
<template x-if="toast.type === 'debug'">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
|
||||
</svg>
|
||||
</template>
|
||||
</span>
|
||||
<p class="flex-1 text-sm"
|
||||
:class="{
|
||||
'text-green-800 dark:text-green-200': toast.type === 'success',
|
||||
'text-red-800 dark:text-red-200': toast.type === 'error',
|
||||
'text-blue-800 dark:text-blue-200': toast.type === 'info',
|
||||
'text-amber-800 dark:text-amber-200': toast.type === 'warning',
|
||||
'text-gray-800 dark:text-gray-200': toast.type === 'debug'
|
||||
}"
|
||||
x-text="toast.message"></p>
|
||||
<button @click.stop="dismissToast(toast.id)"
|
||||
class="flex-shrink-0"
|
||||
:class="{
|
||||
'text-green-400 hover:text-green-600 dark:text-green-500 dark:hover:text-green-300': toast.type === 'success',
|
||||
'text-red-400 hover:text-red-600 dark:text-red-500 dark:hover:text-red-300': toast.type === 'error',
|
||||
'text-blue-400 hover:text-blue-600 dark:text-blue-500 dark:hover:text-blue-300': toast.type === 'info',
|
||||
'text-amber-400 hover:text-amber-600 dark:text-amber-500 dark:hover:text-amber-300': toast.type === 'warning',
|
||||
'text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300': toast.type === 'debug'
|
||||
}">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<script src="{% static 'js/toast.js' %}"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<c-vars without_buttons="false" submit_text="Submit" close_text="Cancel" />
|
||||
<div id="modal-container">
|
||||
<div class="tt-modal fixed inset-0 bg-black/70 dark:bg-gray-600/50 overflow-y-auto h-full w-full flex items-center justify-center">
|
||||
<div class="relative mx-auto p-5 border-accent border w-full max-w-md shadow-lg/50 rounded-md bg-white dark:bg-gray-900">
|
||||
<div class="{{ container_class }}">
|
||||
{{ slot }}
|
||||
{% if not without_buttons %}
|
||||
<div class="items-center mt-5">
|
||||
<c-button color="blue" size="lg" type="submit" class="w-full">{{ submit_text }}</c-button>
|
||||
<c-button color="gray" size="base" class="mt-0 w-full" onclick="this.closest('.tt-modal').remove()">{{ close_text }}</c-button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,5 +1,5 @@
|
||||
<c-vars :name="id" />
|
||||
<div class="pb-4 bg-white dark:bg-gray-900">
|
||||
<!-- <div class="pb-4 bg-white dark:bg-gray-900">
|
||||
<label for="table-search" class="sr-only">Search</label>
|
||||
<div class="relative mt-1">
|
||||
<div class="absolute inset-y-3 rtl:inset-r-0 start-0 flex items-center ps-3 pointer-events-none">
|
||||
@@ -9,4 +9,17 @@
|
||||
</div>
|
||||
<input type="text" id="{{ id }}" name="{{ name }}" value="{{ search_string }}" class="block pt-2 ps-10 text-sm text-gray-900 border border-gray-300 rounded-lg w-80 bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="{% if placeholder %}{{ placeholder }}{% else %}Search{% endif %}">
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
|
||||
<form class="max-w-md mx-auto">
|
||||
<label for="search" class="block mb-2.5 text-sm font-medium text-heading sr-only ">Search</label>
|
||||
<div class="relative">
|
||||
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
|
||||
<svg class="w-4 h-4 text-body" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="m21 21-3.5-3.5M17 10a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z"/></svg>
|
||||
</div>
|
||||
<input type="search" id="{{ id }}" name="{{ name }}" value="{{ search_string }}" class="block w-full p-3 ps-9 bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base focus:ring-brand focus:border-brand shadow-xs placeholder:text-body" placeholder="{% if placeholder %}{{ placeholder }}{% else %}Search{% endif %}" required />
|
||||
<button type="button" class="absolute end-1.5 bottom-1.5 text-white bg-brand hover:bg-brand-strong box-border border border-transparent focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded text-xs px-3 py-1.5 focus:outline-none cursor-pointer">Search</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
<tr class="odd:bg-white dark:odd:bg-gray-900 even:bg-gray-50 dark:even:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 [&_a]:underline [&_a]:underline-offset-4 [&_a]:decoration-2 [&_td:last-child]:text-right">
|
||||
<tr class="odd:bg-white dark:odd:bg-gray-900 even:bg-gray-50 dark:even:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 [&_a]:underline [&_a]:underline-offset-4 [&_a]:decoration-2 [&_td:last-child]:text-right"
|
||||
{% if data.row_id %}id="{{ data.row_id }}"{% endif %}
|
||||
{% if data.hx_trigger %}hx-trigger="{{ data.hx_trigger }}"{% endif %}
|
||||
{% if data.hx_get %}hx-get="{{ data.hx_get }}"{% endif %}
|
||||
{% if data.hx_select %}hx-select="{{ data.hx_select }}"{% endif %}
|
||||
{% if data.hx_swap %}hx-swap="{{ data.hx_swap }}"{% endif %}
|
||||
>
|
||||
{% if slot %}
|
||||
{{ slot }}
|
||||
{% elif data.row_id %}
|
||||
{% for td in data.cell_data %}
|
||||
{% if forloop.first %}
|
||||
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{{ td }}</th>
|
||||
{% else %}
|
||||
<c-table-td>
|
||||
{{ td }}
|
||||
</c-table-td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% 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">{{ td }}</th>
|
||||
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{{ td }}</th>
|
||||
{% else %}
|
||||
<c-table-td>
|
||||
{{ td }}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div>
|
||||
<p>Are you sure you want to delete this status change?</p>
|
||||
<c-button color="red" type="submit" size="lg" class="w-full">Delete</c-button>
|
||||
<a href="{% url 'view_game' object.game.id %}" class="">
|
||||
<a href="{% url 'games:view_game' object.game.id %}" class="">
|
||||
<c-button color="gray" class="w-full">Cancel</c-button>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
{% block content %}
|
||||
<div class="flex-col">
|
||||
{% if dataset_count >= 1 %}
|
||||
{% url 'list_sessions_start_session_from_session' last.id as start_session_url %}
|
||||
{% url 'games:list_sessions_start_session_from_session' last.id as start_session_url %}
|
||||
<div class="mx-auto text-center my-4">
|
||||
<a id="last-session-start"
|
||||
href="{{ start_session_url }}"
|
||||
@@ -36,7 +36,7 @@
|
||||
<td class="px-2 sm:px-4 md:px-6 md:py-2 purchase-name relative align-top w-24 h-12 group">
|
||||
<span class="inline-block relative">
|
||||
<a class="underline decoration-slate-500 sm:decoration-2 inline-block truncate max-w-20char group-hover:absolute group-hover:max-w-none group-hover:-top-8 group-hover:-left-6 group-hover:min-w-60 group-hover:px-6 group-hover:py-3.5 group-hover:bg-purple-600 group-hover:rounded-xs group-hover:outline-dashed group-hover:outline-purple-400 group-hover:outline-4 group-hover:decoration-purple-900 group-hover:text-purple-100"
|
||||
href="{% url 'view_game' session.game.id %}">
|
||||
href="{% url 'games:view_game' session.game.id %}">
|
||||
{{ session.game.name }}
|
||||
</a>
|
||||
</span>
|
||||
@@ -46,7 +46,7 @@
|
||||
</td>
|
||||
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono hidden lg:table-cell">
|
||||
{% if not session.timestamp_end %}
|
||||
{% url 'list_sessions_end_session' session.id as end_session_url %}
|
||||
{% url 'games:list_sessions_end_session' session.id as end_session_url %}
|
||||
<a href="{{ end_session_url }}"
|
||||
hx-get="{{ end_session_url }}"
|
||||
hx-target="closest tr"
|
||||
|
||||
+14
-14
@@ -1,7 +1,7 @@
|
||||
{% load static %}
|
||||
<nav class="bg-white border-gray-200 dark:bg-gray-900 dark:border-gray-700">
|
||||
<nav class="bg-neutral-primary-soft border-b border-default">
|
||||
<div class="max-w-(--breakpoint-xl) flex flex-wrap items-center justify-between mx-auto p-4">
|
||||
<a href="{% url 'index' %}"
|
||||
<a href="{% url 'games:index' %}"
|
||||
class="flex items-center space-x-3 rtl:space-x-reverse">
|
||||
<img src="{% static 'icons/schedule.png' %}"
|
||||
height="48"
|
||||
@@ -64,23 +64,23 @@
|
||||
<ul class="py-2 text-sm text-gray-700 dark:text-gray-400"
|
||||
aria-labelledby="dropdownLargeButton">
|
||||
<li>
|
||||
<a href="{% url 'add_device' %}"
|
||||
<a href="{% url 'games:add_device' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Device</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'add_game' %}"
|
||||
<a href="{% url 'games:add_game' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Game</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'add_platform' %}"
|
||||
<a href="{% url 'games:add_platform' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Platform</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'add_purchase' %}"
|
||||
<a href="{% url 'games:add_purchase' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Purchase</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'add_session' %}"
|
||||
<a href="{% url 'games:add_session' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Session</a>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -105,34 +105,34 @@
|
||||
<ul class="py-2 text-sm text-gray-700 dark:text-gray-400"
|
||||
aria-labelledby="dropdownLargeButton">
|
||||
<li>
|
||||
<a href="{% url 'list_devices' %}"
|
||||
<a href="{% url 'games:list_devices' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Devices</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'list_games' %}"
|
||||
<a href="{% url 'games:list_games' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Games</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'list_platforms' %}"
|
||||
<a href="{% url 'games:list_platforms' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Platforms</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'list_playevents' %}"
|
||||
<a href="{% url 'games:list_playevents' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Play events</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'list_purchases' %}"
|
||||
<a href="{% url 'games:list_purchases' %}"
|
||||
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 'games:list_sessions' %}"
|
||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Sessions</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'stats_by_year' global_current_year %}"
|
||||
<a href="{% url 'games:stats_by_year' global_current_year %}"
|
||||
class="block py-2 px-3 text-gray-900 rounded-sm hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">Stats</a>
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<div id="delete-game-confirmation-modal" class="fixed inset-0 bg-black/70 dark:bg-gray-600/50 overflow-y-auto h-full w-full flex items-center justify-center">
|
||||
<div class="relative mx-auto p-5 border-accent border w-full max-w-md shadow-lg/50 rounded-md bg-white dark:bg-gray-900">
|
||||
<div class="">
|
||||
<h1 class="text-2xl leading-6 font-medium dark:text-white text-center">Delete Game</h1>
|
||||
<p class="dark:text-white text-center mt-5">
|
||||
Are you sure you want to delete <strong>{{ game.name }}</strong>?
|
||||
</p>
|
||||
<form class=""
|
||||
hx-post="{% url 'games:delete_game' game.id %}"
|
||||
hx-replace-url="true"
|
||||
hx-target="#main-container"
|
||||
hx-select="#main-container"
|
||||
hx-swap="outerHTML"
|
||||
hw-swap-oob="#global-modal-container"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<p class="dark:text-white text-center mt-3 text-sm text-gray-600 dark:text-gray-400">
|
||||
This will permanently delete this game and all associated data:
|
||||
</p>
|
||||
<ul class="dark:text-white text-center mt-1 text-sm text-gray-600 dark:text-gray-400 list-disc list-inside">
|
||||
{% if session_count %}<li>{{ session_count }} session(s)</li>{% endif %}
|
||||
{% if purchase_count %}<li>{{ purchase_count }} purchase(s)</li>{% endif %}
|
||||
{% if playevent_count %}<li>{{ playevent_count }} play event(s)</li>{% endif %}
|
||||
{% if not session_count and not purchase_count and not playevent_count %}<li>No associated data</li>{% endif %}
|
||||
</ul>
|
||||
<p class="dark:text-white text-center mt-3 text-sm font-medium text-red-600 dark:text-red-400">
|
||||
This action cannot be undone.
|
||||
</p>
|
||||
<div class="items-center mt-5">
|
||||
<c-button color="red" size="lg" type="submit" class="w-full">Delete</c-button>
|
||||
<c-button color="gray" size="base" class="mt-0 w-full" onclick="this.closest('#delete-game-confirmation-modal').remove()">Cancel</c-button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -8,16 +8,21 @@
|
||||
this.status = newStatus;
|
||||
this.status_display = newStatusDisplay;
|
||||
this.saving = true;
|
||||
fetch(`/api/games/{{ game.id }}/status`, {
|
||||
// TODO: migrate to hx-post + hx-on::after-request for HTMX-native toast handling
|
||||
fetchWithHtmxTriggers(`/api/games/{{ game.id }}/status`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': '{{ csrf_token }}'
|
||||
},
|
||||
body: JSON.stringify({ status: newStatus })
|
||||
}).then(() => {
|
||||
})
|
||||
.then(() => {
|
||||
document.body.dispatchEvent(new CustomEvent('status-changed'));
|
||||
})
|
||||
.catch(() => {
|
||||
console.error('Failed to update status');
|
||||
})
|
||||
.finally(() => this.saving = false);
|
||||
}
|
||||
}"
|
||||
@@ -41,5 +46,4 @@
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<div x-show="saving" style="display: none;">Saving...</div>
|
||||
</div>
|
||||
@@ -1,6 +1,6 @@
|
||||
<ul class="list-disc list-inside">
|
||||
{% for change in statuschanges %}
|
||||
<li class="text-slate-500">
|
||||
{% if change.timestamp %}{{ change.timestamp | date:"d/m/Y H:i" }}: Changed{% else %}At some point changed{% endif %} status from <c-gamestatus :status="change.old_status">{{ change.get_old_status_display }}</c-gamestatus> to <c-gamestatus :status="change.new_status">{{ change.get_new_status_display }}</c-gamestatus> (<a href="{% url 'edit_statuschange' change.id %}">Edit</a>, <a href="{% url 'delete_statuschange' change.id %}">Delete</a>)</li>
|
||||
{% if change.timestamp %}{{ change.timestamp | date:"d/m/Y H:i" }}: Changed{% else %}At some point changed{% endif %} status from <c-gamestatus :status="change.old_status">{{ change.get_old_status_display }}</c-gamestatus> to <c-gamestatus :status="change.new_status">{{ change.get_new_status_display }}</c-gamestatus> (<a href="{% url 'games:edit_statuschange' change.id %}">Edit</a>, <a href="{% url 'games:delete_statuschange' change.id %}">Delete</a>)</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
@@ -0,0 +1,20 @@
|
||||
<div id="refund-confirmation-modal" class="fixed inset-0 bg-black/70 dark:bg-gray-600/50 overflow-y-auto h-full w-full flex items-center justify-center">
|
||||
<div class="relative mx-auto p-5 border-accent border w-full max-w-md shadow-lg/50 rounded-md bg-white dark:bg-gray-900">
|
||||
<div class="">
|
||||
<h1 class="text-2xl leading-6 font-medium dark:text-white text-center">Confirm Refund</h1>
|
||||
<p class="dark:text-white text-center mt-5">
|
||||
Are you sure you want to mark this purchase as refunded?
|
||||
</p>
|
||||
<form class="" hx-post="{% url 'games:refund_purchase' purchase_id %}" hx-target="#purchase-row-{{ purchase_id }}" hx-swap="outerHTML">
|
||||
{% csrf_token %}
|
||||
<p class="dark:text-white text-center mt-3 text-sm">
|
||||
Games will be marked as abandoned.
|
||||
</p>
|
||||
<div class="items-center mt-5">
|
||||
<c-button color="blue" size="lg" type="submit" class="w-full">Refund</c-button>
|
||||
<c-button color="gray" size="base" class="mt-0 w-full" onclick="this.closest('#refund-confirmation-modal').remove()">Cancel</c-button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,49 @@
|
||||
<div class="flex gap-2 items-center"
|
||||
x-data="{
|
||||
originalDeviceId: {{ session.device.id|default:'null' }},
|
||||
originalDeviceName: '{{ session.device.name|default:'Unknown'|escapejs }}',
|
||||
deviceId: {{ session.device.id|default:'null' }},
|
||||
deviceName: '{{ session.device.name|default:'Unknown'|escapejs }}',
|
||||
open: false,
|
||||
saving: false,
|
||||
setDevice(newDeviceId, newDeviceName) {
|
||||
this.deviceId = newDeviceId;
|
||||
this.deviceName = newDeviceName;
|
||||
this.saving = true;
|
||||
// TODO: migrate to hx-post + hx-on::after-request for HTMX-native toast handling
|
||||
fetchWithHtmxTriggers(`/api/session/{{ session.id }}/device`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': '{{ csrf_token }}'
|
||||
},
|
||||
body: JSON.stringify({ device_id: newDeviceId })
|
||||
})
|
||||
.then((res) => {
|
||||
document.body.dispatchEvent(new CustomEvent('device-changed'));
|
||||
})
|
||||
.catch(() => {
|
||||
this.deviceName = this.originalDeviceName;
|
||||
this.deviceId = this.originalDeviceId;
|
||||
console.error('Failed to update device');
|
||||
})
|
||||
.finally(() => this.saving = false);
|
||||
}
|
||||
}"
|
||||
>
|
||||
<div class="inline-flex rounded-md shadow-2xs" role="group" @click.outside="open = false">
|
||||
<button type="button" @click="open = !open" class="relative px-4 py-2 text-sm font-medium bg-white border border-gray-200 rounded-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white align-middle hover:cursor-pointer">
|
||||
<span class="flex flex-row gap-4 justify-between items-center">
|
||||
<span x-text="deviceName"></span>
|
||||
<c-icon.arrowdown />
|
||||
</span>
|
||||
<div class="absolute top-[105%] left-0 w-full whitespace-nowrap z-10 text-sm font-medium bg-gray-800/20 backdrop-blur-lg rounded-md rounded-t-none border border-gray-200 dark:border-gray-700" x-show="open" style="display: none;">
|
||||
<ul class="[&_li:first-of-type_a]:rounded-none [&_li:last-of-type_a]:rounded-t-none">
|
||||
{% for device in session_devices %}
|
||||
<li><a href="#" @click.prevent.stop="setDevice({{ device.id }}, '{{ device.name|escapejs }}'); open = false;" class="block px-4 py-2 dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white rounded-sm no-underline! border-0!" :class="{ 'font-bold': deviceId === {{ device.id }} }">{{ device.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -68,7 +68,7 @@
|
||||
>
|
||||
<span class="uppercase">Played</span>
|
||||
<div class="inline-flex rounded-md shadow-2xs" role="group" x-data="{ played: {{ game.playevents.count }} }">
|
||||
<a href="{% url 'add_playevent' %}">
|
||||
<a href="{% url 'games:add_playevent' %}">
|
||||
<button type="button" class="px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-s-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white hover:cursor-pointer">
|
||||
<span x-text="played"></span> times
|
||||
</button>
|
||||
@@ -83,7 +83,7 @@
|
||||
class=""
|
||||
>
|
||||
<li class="px-4 py-2 dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white rounded-tr-md">
|
||||
<a href="{% url 'add_playevent_for_game' game.id %}">Add playthrough...</a>
|
||||
<a href="{% url 'games:add_playevent_for_game' game.id %}">Add playthrough...</a>
|
||||
</li>
|
||||
<li
|
||||
x-on:click="createPlayEvent"
|
||||
@@ -94,7 +94,16 @@
|
||||
<script>
|
||||
function createPlayEvent() {
|
||||
this.played++;
|
||||
fetch('{% url 'api-1.0.0:create_playevent' %}', { method: 'POST', headers: { 'X-CSRFToken': '{{ csrf_token }}' }, body: '{"game_id": {{ game.id }}}'})
|
||||
// TODO: migrate to hx-post + hx-on::after-request for HTMX-native toast handling
|
||||
fetchWithHtmxTriggers('{% url 'api-1.0.0:create_playevent' %}', {
|
||||
method: 'POST',
|
||||
headers: { 'X-CSRFToken': '{{ csrf_token }}', 'Content-Type': 'application/json' },
|
||||
body: '{"game_id": {{ game.id }}}'
|
||||
})
|
||||
.catch(() => {
|
||||
this.played--;
|
||||
console.error('Failed to record play');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</ul>
|
||||
@@ -112,13 +121,13 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="inline-flex rounded-md shadow-xs mb-3" role="group">
|
||||
<a href="{% url 'edit_game' game.id %}">
|
||||
<a href="{% url 'games:edit_game' game.id %}">
|
||||
<button type="button"
|
||||
class="px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-s-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white hover:cursor-pointer">
|
||||
Edit
|
||||
</button>
|
||||
</a>
|
||||
<a href="{% url 'delete_game' game.id %}">
|
||||
<a href="#" hx-get="{% url 'games:delete_game_confirmation' game.id %}" hx-target="#global-modal-container">
|
||||
<button type="button"
|
||||
class="px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-e-lg hover:bg-red-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-red-700 dark:focus:ring-blue-500 dark:focus:text-white hover:cursor-pointer">
|
||||
Delete
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
</span>
|
||||
</span>
|
||||
<div class="inline-flex rounded-md shadow-xs mb-3" role="group">
|
||||
<a href="{% url 'edit_purchase' purchase.id %}">
|
||||
<a href="{% url 'games:edit_purchase' purchase.id %}">
|
||||
<button type="button"
|
||||
class="px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-s-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white">
|
||||
Edit
|
||||
</button>
|
||||
</a>
|
||||
<a href="{% url 'delete_purchase' purchase.id %}">
|
||||
<a href="{% url 'games:delete_purchase' purchase.id %}">
|
||||
<button type="button"
|
||||
class="px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-e-lg hover:bg-red-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-red-700 dark:focus:ring-blue-500 dark:focus:text-white">
|
||||
Delete
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import random
|
||||
import string
|
||||
import hashlib
|
||||
|
||||
from django import template
|
||||
|
||||
@@ -8,4 +7,7 @@ register = template.Library()
|
||||
|
||||
@register.simple_tag
|
||||
def randomid(seed: str = "") -> str:
|
||||
return str(hash(seed + "".join(random.choices(string.ascii_lowercase, k=10))))
|
||||
content_hash = hashlib.sha1(seed.encode()).hexdigest()
|
||||
if seed:
|
||||
return content_hash[:max(0, 10 - len(seed))] + seed
|
||||
return content_hash[:10]
|
||||
|
||||
+100
-1
@@ -1,3 +1,102 @@
|
||||
from datetime import date
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
from games.models import Game, Platform, Purchase
|
||||
from games.tasks import convert_prices
|
||||
|
||||
|
||||
class PurchaseNeedsPriceUpdateTest(TestCase):
|
||||
def setUp(self):
|
||||
self.platform = Platform.objects.create(name="PC", icon="pc", group="PC")
|
||||
self.game = Game.objects.create(name="Test Game", platform=self.platform)
|
||||
|
||||
def test_new_purchase_has_needs_price_update_true(self):
|
||||
purchase = Purchase.objects.create(
|
||||
price=50.0,
|
||||
price_currency="USD",
|
||||
date_purchased=date(2025, 1, 1),
|
||||
)
|
||||
purchase.games.add(self.game)
|
||||
self.assertTrue(purchase.needs_price_update)
|
||||
|
||||
def test_convert_prices_sets_flag_to_false(self):
|
||||
purchase = Purchase.objects.create(
|
||||
price=50.0,
|
||||
price_currency="USD",
|
||||
date_purchased=date(2025, 1, 1),
|
||||
)
|
||||
purchase.games.add(self.game)
|
||||
self.assertTrue(purchase.needs_price_update)
|
||||
|
||||
convert_prices()
|
||||
|
||||
purchase.refresh_from_db()
|
||||
self.assertFalse(purchase.needs_price_update)
|
||||
|
||||
def test_price_change_sets_needs_price_update(self):
|
||||
purchase = Purchase.objects.create(
|
||||
price=50.0,
|
||||
price_currency="USD",
|
||||
date_purchased=date(2025, 1, 1),
|
||||
)
|
||||
purchase.games.add(self.game)
|
||||
purchase.converted_price = 1000
|
||||
purchase.converted_currency = "CZK"
|
||||
purchase.needs_price_update = False
|
||||
purchase.save()
|
||||
|
||||
purchase.price = 60.0
|
||||
purchase.save()
|
||||
purchase.refresh_from_db()
|
||||
self.assertTrue(purchase.needs_price_update)
|
||||
|
||||
def test_currency_change_sets_needs_price_update(self):
|
||||
purchase = Purchase.objects.create(
|
||||
price=50.0,
|
||||
price_currency="USD",
|
||||
date_purchased=date(2025, 1, 1),
|
||||
)
|
||||
purchase.games.add(self.game)
|
||||
purchase.converted_price = 1000
|
||||
purchase.converted_currency = "CZK"
|
||||
purchase.needs_price_update = False
|
||||
purchase.save()
|
||||
|
||||
purchase.price_currency = "EUR"
|
||||
purchase.save()
|
||||
purchase.refresh_from_db()
|
||||
self.assertTrue(purchase.needs_price_update)
|
||||
|
||||
def test_name_change_does_not_set_needs_price_update(self):
|
||||
purchase = Purchase.objects.create(
|
||||
price=50.0,
|
||||
price_currency="USD",
|
||||
date_purchased=date(2025, 1, 1),
|
||||
)
|
||||
purchase.games.add(self.game)
|
||||
purchase.converted_price = 1000
|
||||
purchase.converted_currency = "CZK"
|
||||
purchase.needs_price_update = False
|
||||
purchase.save()
|
||||
|
||||
purchase.name = "New Name"
|
||||
purchase.save()
|
||||
purchase.refresh_from_db()
|
||||
self.assertFalse(purchase.needs_price_update)
|
||||
|
||||
def test_convert_prices_skips_already_converted(self):
|
||||
purchase = Purchase.objects.create(
|
||||
price=50.0,
|
||||
price_currency="USD",
|
||||
date_purchased=date(2025, 1, 1),
|
||||
)
|
||||
purchase.games.add(self.game)
|
||||
purchase.converted_price = 1000
|
||||
purchase.converted_currency = "CZK"
|
||||
purchase.needs_price_update = False
|
||||
purchase.save()
|
||||
|
||||
convert_prices()
|
||||
purchase.refresh_from_db()
|
||||
self.assertFalse(purchase.needs_price_update)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from django.urls import path
|
||||
|
||||
app_name = "games"
|
||||
|
||||
from games.api import api
|
||||
from games.views import (
|
||||
device,
|
||||
@@ -21,6 +23,7 @@ urlpatterns = [
|
||||
path("game/add", game.add_game, name="add_game"),
|
||||
path("game/<int:game_id>/edit", game.edit_game, name="edit_game"),
|
||||
path("game/<int:game_id>/view", game.view_game, name="view_game"),
|
||||
path("game/<int:game_id>/delete/confirm", game.delete_game_confirmation, name="delete_game_confirmation"),
|
||||
path("game/<int:game_id>/delete", game.delete_game, name="delete_game"),
|
||||
path("game/list", game.list_games, name="list_games"),
|
||||
path("platform/add", platform.add_platform, name="add_platform"),
|
||||
@@ -88,6 +91,11 @@ urlpatterns = [
|
||||
purchase.list_purchases,
|
||||
name="list_purchases",
|
||||
),
|
||||
path(
|
||||
"purchase/<int:purchase_id>/refund/confirm",
|
||||
purchase.refund_purchase_confirmation,
|
||||
name="refund_purchase_confirmation",
|
||||
),
|
||||
path(
|
||||
"purchase/<int:purchase_id>/refund",
|
||||
purchase.refund_purchase,
|
||||
|
||||
@@ -36,7 +36,7 @@ def list_devices(request: HttpRequest) -> HttpResponse:
|
||||
else None
|
||||
),
|
||||
"data": {
|
||||
"header_action": A([], Button([], "Add device"), url="add_device"),
|
||||
"header_action": A([], Button([], "Add device"), url_name="games:add_device"),
|
||||
"columns": [
|
||||
"Name",
|
||||
"Type",
|
||||
@@ -53,12 +53,12 @@ def list_devices(request: HttpRequest) -> HttpResponse:
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"href": reverse("edit_device", args=[device.pk]),
|
||||
"href": reverse("games:edit_device", args=[device.pk]),
|
||||
"slot": Icon("edit"),
|
||||
"color": "gray",
|
||||
},
|
||||
{
|
||||
"href": reverse("delete_device", args=[device.pk]),
|
||||
"href": reverse("games:delete_device", args=[device.pk]),
|
||||
"slot": Icon("delete"),
|
||||
"color": "red",
|
||||
},
|
||||
@@ -79,7 +79,7 @@ def edit_device(request: HttpRequest, device_id: int = 0) -> HttpResponse:
|
||||
form = DeviceForm(request.POST or None, instance=device)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect("list_devices")
|
||||
return redirect("games:list_devices")
|
||||
|
||||
context: dict[str, Any] = {"form": form, "title": "Edit device"}
|
||||
return render(request, "add.html", context)
|
||||
@@ -89,7 +89,7 @@ def edit_device(request: HttpRequest, device_id: int = 0) -> HttpResponse:
|
||||
def delete_device(request: HttpRequest, device_id: int) -> HttpResponse:
|
||||
device = get_object_or_404(Device, id=device_id)
|
||||
device.delete()
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -98,7 +98,7 @@ def add_device(request: HttpRequest) -> HttpResponse:
|
||||
form = DeviceForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect("index")
|
||||
return redirect("games:index")
|
||||
|
||||
context["form"] = form
|
||||
context["title"] = "Add New Device"
|
||||
|
||||
+35
-19
@@ -89,7 +89,7 @@ def list_games(request: HttpRequest, search_string: str = "") -> HttpResponse:
|
||||
)
|
||||
]
|
||||
),
|
||||
A([], Button([], "Add game"), url="add_game"),
|
||||
A([], Button([], "Add game"), url_name="games:add_game"),
|
||||
],
|
||||
attributes=[("class", "flex justify-between")],
|
||||
),
|
||||
@@ -104,7 +104,7 @@ def list_games(request: HttpRequest, search_string: str = "") -> HttpResponse:
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
NameWithIcon(game_id=game.pk),
|
||||
NameWithIcon(game=game),
|
||||
PopoverTruncated(
|
||||
game.sort_name
|
||||
if game.sort_name is not None and game.name != game.sort_name
|
||||
@@ -126,12 +126,12 @@ def list_games(request: HttpRequest, search_string: str = "") -> HttpResponse:
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"href": reverse("edit_game", args=[game.pk]),
|
||||
"href": reverse("games:edit_game", args=[game.pk]),
|
||||
"slot": Icon("edit"),
|
||||
"color": "gray",
|
||||
},
|
||||
{
|
||||
"href": reverse("delete_game", args=[game.pk]),
|
||||
"href": reverse("games:delete_game", args=[game.pk]),
|
||||
"slot": Icon("delete"),
|
||||
"color": "red",
|
||||
},
|
||||
@@ -154,10 +154,10 @@ def add_game(request: HttpRequest) -> HttpResponse:
|
||||
game = form.save()
|
||||
if "submit_and_redirect" in request.POST:
|
||||
return HttpResponseRedirect(
|
||||
reverse("add_purchase_for_game", kwargs={"game_id": game.id})
|
||||
reverse("games:add_purchase_for_game", kwargs={"game_id": game.id})
|
||||
)
|
||||
else:
|
||||
return redirect("list_games")
|
||||
return redirect("games:list_games")
|
||||
|
||||
context["form"] = form
|
||||
context["title"] = "Add New Game"
|
||||
@@ -165,11 +165,29 @@ def add_game(request: HttpRequest) -> HttpResponse:
|
||||
return render(request, "add_game.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_game_confirmation(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
game = get_object_or_404(Game, id=game_id)
|
||||
session_count = game.sessions.count()
|
||||
purchase_count = game.purchases.count()
|
||||
playevent_count = game.playevents.count()
|
||||
return render(
|
||||
request,
|
||||
"partials/delete_game_confirmation.html",
|
||||
{
|
||||
"game": game,
|
||||
"session_count": session_count,
|
||||
"purchase_count": purchase_count,
|
||||
"playevent_count": playevent_count,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
game = get_object_or_404(Game, id=game_id)
|
||||
game.delete()
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -180,7 +198,7 @@ def edit_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
form = GameForm(request.POST or None, instance=purchase)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
context["title"] = "Edit Game"
|
||||
context["form"] = form
|
||||
return render(request, "add.html", context)
|
||||
@@ -242,12 +260,12 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"href": reverse("edit_purchase", args=[purchase.pk]),
|
||||
"href": reverse("games:edit_purchase", args=[purchase.pk]),
|
||||
"slot": Icon("edit"),
|
||||
"color": "gray",
|
||||
},
|
||||
{
|
||||
"href": reverse("delete_purchase", args=[purchase.pk]),
|
||||
"href": reverse("games:delete_purchase", args=[purchase.pk]),
|
||||
"slot": Icon("delete"),
|
||||
"color": "red",
|
||||
},
|
||||
@@ -274,7 +292,7 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
"header_action": Div(
|
||||
children=[
|
||||
A(
|
||||
url="add_session",
|
||||
url_name="games:add_session",
|
||||
children=Button(
|
||||
icon=True,
|
||||
size="xs",
|
||||
@@ -282,8 +300,8 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
),
|
||||
),
|
||||
A(
|
||||
url=reverse(
|
||||
"list_sessions_start_session_from_session",
|
||||
href=reverse(
|
||||
"games:list_sessions_start_session_from_session",
|
||||
args=[last_session.pk],
|
||||
),
|
||||
children=Popover(
|
||||
@@ -308,9 +326,7 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
"columns": ["Game", "Date", "Duration", "Actions"],
|
||||
"rows": [
|
||||
[
|
||||
NameWithIcon(
|
||||
session_id=session.pk,
|
||||
),
|
||||
NameWithIcon(session=session),
|
||||
f"{local_strftime(session.timestamp_start)}{f' — {local_strftime(session.timestamp_end, timeformat)}' if session.timestamp_end else ''}",
|
||||
session.duration_formatted_with_mark,
|
||||
render_to_string(
|
||||
@@ -319,7 +335,7 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
"buttons": [
|
||||
{
|
||||
"href": reverse(
|
||||
"list_sessions_end_session", args=[session.pk]
|
||||
"games:list_sessions_end_session", args=[session.pk]
|
||||
),
|
||||
"slot": Icon("end"),
|
||||
"title": "Finish session now",
|
||||
@@ -333,12 +349,12 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
# in the button group component
|
||||
else {},
|
||||
{
|
||||
"href": reverse("edit_session", args=[session.pk]),
|
||||
"href": reverse("games:edit_session", args=[session.pk]),
|
||||
"slot": Icon("edit"),
|
||||
"color": "gray",
|
||||
},
|
||||
{
|
||||
"href": reverse("delete_session", args=[session.pk]),
|
||||
"href": reverse("games:delete_session", args=[session.pk]),
|
||||
"slot": Icon("delete"),
|
||||
"color": "red",
|
||||
},
|
||||
|
||||
+60
-28
@@ -2,9 +2,9 @@ from datetime import datetime, timedelta
|
||||
from typing import Any, Callable
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Avg, Count, ExpressionWrapper, F, Prefetch, Q, Sum, fields
|
||||
from django.db.models import Avg, Count, ExpressionWrapper, F, Max, OuterRef, Prefetch, Q, Subquery, Sum, fields
|
||||
from django.db.models.functions import TruncDate, TruncMonth
|
||||
from django.db.models.manager import BaseManager
|
||||
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import redirect, render
|
||||
from django.urls import reverse
|
||||
@@ -90,26 +90,34 @@ def stats_alltime(request: HttpRequest) -> HttpResponse:
|
||||
|
||||
this_year_purchases = Purchase.objects.all()
|
||||
this_year_purchases_with_currency = this_year_purchases.select_related("games")
|
||||
this_year_purchases_without_refunded = this_year_purchases_with_currency.filter(
|
||||
this_year_purchases_without_refunded = Purchase.objects.filter(
|
||||
date_refunded=None
|
||||
)
|
||||
this_year_purchases_refunded = this_year_purchases_with_currency.refunded()
|
||||
this_year_purchases_refunded = Purchase.objects.refunded()
|
||||
|
||||
this_year_purchases_unfinished_dropped_nondropped = (
|
||||
this_year_purchases_without_refunded.filter(date_finished__isnull=True)
|
||||
this_year_purchases_without_refunded.filter(
|
||||
~Q(games__status="f")
|
||||
& ~Q(games__playevents__ended__isnull=False)
|
||||
)
|
||||
.filter(infinite=False)
|
||||
.filter(Q(type=Purchase.GAME) | Q(type=Purchase.DLC))
|
||||
) # do not count battle passes etc.
|
||||
|
||||
this_year_purchases_unfinished = (
|
||||
this_year_purchases_unfinished_dropped_nondropped.filter(
|
||||
date_dropped__isnull=True
|
||||
~Q(games__status="r")
|
||||
& ~Q(games__status="a")
|
||||
)
|
||||
)
|
||||
this_year_purchases_dropped = (
|
||||
this_year_purchases_unfinished_dropped_nondropped.filter(
|
||||
date_dropped__isnull=False
|
||||
this_year_purchases.filter(
|
||||
~Q(games__status="f")
|
||||
& ~Q(games__playevents__ended__isnull=False)
|
||||
)
|
||||
.filter(Q(games__status="a") | Q(date_refunded__isnull=False))
|
||||
.filter(infinite=False)
|
||||
.filter(Q(type=Purchase.GAME) | Q(type=Purchase.DLC))
|
||||
)
|
||||
|
||||
this_year_purchases_without_refunded_count = (
|
||||
@@ -124,13 +132,28 @@ def stats_alltime(request: HttpRequest) -> HttpResponse:
|
||||
* 100
|
||||
)
|
||||
|
||||
purchases_finished_this_year: BaseManager[Purchase] = Purchase.objects.finished()
|
||||
purchases_finished_this_year_released_this_year = (
|
||||
purchases_finished_this_year.all().order_by("date_finished")
|
||||
_finished_purchases_qs = Purchase.objects.finished()
|
||||
_finished_with_date = _finished_purchases_qs.annotate(
|
||||
date_finished=Subquery(
|
||||
Purchase.objects.filter(pk=OuterRef("pk"))
|
||||
.annotate(max_ended=Max("games__playevents__ended"))
|
||||
.values("max_ended")[:1]
|
||||
)
|
||||
)
|
||||
purchases_finished_this_year = _finished_with_date
|
||||
purchases_finished_this_year_released_this_year = _finished_with_date.order_by(
|
||||
"-date_finished"
|
||||
)
|
||||
purchased_this_year_finished_this_year = (
|
||||
this_year_purchases_without_refunded.all()
|
||||
).order_by("date_finished")
|
||||
this_year_purchases_without_refunded.filter(pk__in=_finished_purchases_qs.values("pk"))
|
||||
.annotate(
|
||||
date_finished=Subquery(
|
||||
Purchase.objects.filter(pk=OuterRef("pk"))
|
||||
.annotate(max_ended=Max("games__playevents__ended"))
|
||||
.values("max_ended")[:1]
|
||||
)
|
||||
)
|
||||
).order_by("-date_finished")
|
||||
|
||||
this_year_spendings = this_year_purchases_without_refunded.aggregate(
|
||||
total_spent=Sum(F("converted_price"))
|
||||
@@ -139,7 +162,9 @@ def stats_alltime(request: HttpRequest) -> HttpResponse:
|
||||
|
||||
games_with_playtime = Game.objects.filter(
|
||||
sessions__in=this_year_sessions
|
||||
).distinct()
|
||||
).distinct().annotate(
|
||||
total_playtime=Sum(F("sessions__duration_total"))
|
||||
).filter(total_playtime__gt=timedelta(0))
|
||||
month_playtimes = (
|
||||
this_year_sessions.annotate(month=TruncMonth("timestamp_start"))
|
||||
.values("month")
|
||||
@@ -166,11 +191,13 @@ def stats_alltime(request: HttpRequest) -> HttpResponse:
|
||||
)
|
||||
|
||||
backlog_decrease_count = (
|
||||
Purchase.objects.all().intersection(purchases_finished_this_year).count()
|
||||
purchases_finished_this_year.count()
|
||||
)
|
||||
|
||||
first_play_date = "N/A"
|
||||
last_play_date = "N/A"
|
||||
first_play_game = None
|
||||
last_play_game = None
|
||||
if this_year_sessions:
|
||||
first_session = this_year_sessions.earliest()
|
||||
first_play_game = first_session.game
|
||||
@@ -257,9 +284,9 @@ def stats_alltime(request: HttpRequest) -> HttpResponse:
|
||||
def stats(request: HttpRequest, year: int = 0) -> HttpResponse:
|
||||
selected_year = request.GET.get("year")
|
||||
if selected_year:
|
||||
return HttpResponseRedirect(reverse("stats_by_year", args=[selected_year]))
|
||||
return HttpResponseRedirect(reverse("games:stats_by_year", args=[selected_year]))
|
||||
if year == 0:
|
||||
return HttpResponseRedirect(reverse("stats_alltime"))
|
||||
return HttpResponseRedirect(reverse("games:stats_alltime"))
|
||||
this_year_sessions = Session.objects.filter(
|
||||
timestamp_start__year=year
|
||||
).prefetch_related("game")
|
||||
@@ -310,25 +337,30 @@ def stats(request: HttpRequest, year: int = 0) -> HttpResponse:
|
||||
# not infinite
|
||||
# only Game and DLC
|
||||
this_year_purchases_unfinished_dropped_nondropped = (
|
||||
this_year_purchases_without_refunded.exclude(
|
||||
games__in=Game.objects.filter(status="f")
|
||||
this_year_purchases_without_refunded.filter(
|
||||
~Q(games__status="f")
|
||||
& ~Q(games__playevents__ended__year=year)
|
||||
)
|
||||
.filter(infinite=False)
|
||||
.filter(Q(type=Purchase.GAME) | Q(type=Purchase.DLC))
|
||||
)
|
||||
|
||||
# not finished
|
||||
# unfinished = not finished AND not dropped
|
||||
this_year_purchases_unfinished = (
|
||||
this_year_purchases_unfinished_dropped_nondropped.exclude(
|
||||
games__status__in="ura"
|
||||
this_year_purchases_unfinished_dropped_nondropped.filter(
|
||||
~Q(games__status="r")
|
||||
& ~Q(games__status="a")
|
||||
)
|
||||
)
|
||||
# abandoned
|
||||
# retired
|
||||
# dropped = abandoned OR retired OR refunded (OR logic for transition)
|
||||
this_year_purchases_dropped = (
|
||||
this_year_purchases_unfinished_dropped_nondropped.exclude(
|
||||
games__in=Game.objects.filter(status="ar")
|
||||
this_year_purchases.filter(
|
||||
~Q(games__status="f")
|
||||
& ~Q(games__playevents__ended__year=year)
|
||||
)
|
||||
.filter(Q(games__status="a") | Q(date_refunded__isnull=False))
|
||||
.filter(infinite=False)
|
||||
.filter(Q(type=Purchase.GAME) | Q(type=Purchase.DLC))
|
||||
)
|
||||
|
||||
this_year_purchases_without_refunded_count = (
|
||||
@@ -343,7 +375,7 @@ def stats(request: HttpRequest, year: int = 0) -> HttpResponse:
|
||||
* 100
|
||||
)
|
||||
|
||||
purchases_finished_this_year = Purchase.objects.filter(
|
||||
purchases_finished_this_year = Purchase.objects.finished().filter(
|
||||
games__playevents__ended__year=year
|
||||
).annotate(game_name=F("games__name"), date_finished=F("games__playevents__ended"))
|
||||
purchases_finished_this_year_released_this_year = (
|
||||
@@ -512,4 +544,4 @@ def stats(request: HttpRequest, year: int = 0) -> HttpResponse:
|
||||
|
||||
@login_required
|
||||
def index(request: HttpRequest) -> HttpResponse:
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
|
||||
@@ -37,7 +37,7 @@ def list_platforms(request: HttpRequest) -> HttpResponse:
|
||||
else None
|
||||
),
|
||||
"data": {
|
||||
"header_action": A([], Button([], "Add platform"), url="add_platform"),
|
||||
"header_action": A([], Button([], "Add platform"), url_name="games:add_platform"),
|
||||
"columns": [
|
||||
"Name",
|
||||
"Icon",
|
||||
@@ -57,14 +57,14 @@ def list_platforms(request: HttpRequest) -> HttpResponse:
|
||||
"buttons": [
|
||||
{
|
||||
"href": reverse(
|
||||
"edit_platform", args=[platform.pk]
|
||||
"games:edit_platform", args=[platform.pk]
|
||||
),
|
||||
"slot": Icon("edit"),
|
||||
"color": "gray",
|
||||
},
|
||||
{
|
||||
"href": reverse(
|
||||
"delete_platform", args=[platform.pk]
|
||||
"games:delete_platform", args=[platform.pk]
|
||||
),
|
||||
"slot": Icon("delete"),
|
||||
"color": "red",
|
||||
@@ -84,7 +84,7 @@ def list_platforms(request: HttpRequest) -> HttpResponse:
|
||||
def delete_platform(request: HttpRequest, platform_id: int) -> HttpResponse:
|
||||
platform = get_object_or_404(Platform, id=platform_id)
|
||||
platform.delete()
|
||||
return redirect("list_platforms")
|
||||
return redirect("games:list_platforms")
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -95,7 +95,7 @@ def edit_platform(request: HttpRequest, platform_id: int) -> HttpResponse:
|
||||
form = PlatformForm(request.POST or None, instance=platform)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect("list_platforms")
|
||||
return redirect("games:list_platforms")
|
||||
context["title"] = "Edit Platform"
|
||||
context["form"] = form
|
||||
return render(request, "add.html", context)
|
||||
@@ -107,7 +107,7 @@ def add_platform(request: HttpRequest) -> HttpResponse:
|
||||
form = PlatformForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect("index")
|
||||
return redirect("games:index")
|
||||
|
||||
context["form"] = form
|
||||
context["title"] = "Add New Platform"
|
||||
|
||||
@@ -58,12 +58,12 @@ def create_playevent_tabledata(
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"href": reverse("edit_playevent", args=[playevent.pk]),
|
||||
"href": reverse("games:edit_playevent", args=[playevent.pk]),
|
||||
"slot": Icon("edit"),
|
||||
"color": "gray",
|
||||
},
|
||||
{
|
||||
"href": reverse("delete_playevent", args=[playevent.pk]),
|
||||
"href": reverse("games:delete_playevent", args=[playevent.pk]),
|
||||
"slot": Icon("delete"),
|
||||
"color": "red",
|
||||
},
|
||||
@@ -78,7 +78,7 @@ def create_playevent_tabledata(
|
||||
for row in row_list
|
||||
]
|
||||
return {
|
||||
"header_action": A([], Button([], "Add play event"), url="add_playevent"),
|
||||
"header_action": A([], Button([], "Add play event"), url_name="games:add_playevent"),
|
||||
"columns": list(filtered_column_list),
|
||||
"rows": filtered_row_list,
|
||||
}
|
||||
@@ -194,7 +194,7 @@ def add_playevent(request: HttpRequest, game_id: int = 0) -> HttpResponse:
|
||||
if not game_id:
|
||||
# coming from add_playevent url path
|
||||
game_id = form.instance.game.id
|
||||
return HttpResponseRedirect(reverse("view_game", args=[game_id]))
|
||||
return HttpResponseRedirect(reverse("games:view_game", args=[game_id]))
|
||||
|
||||
return render(request, "add.html", {"form": form, "title": "Add new playthrough"})
|
||||
|
||||
@@ -205,7 +205,7 @@ def edit_playevent(request: HttpRequest, playevent_id: int) -> HttpResponse:
|
||||
form = PlayEventForm(request.POST or None, instance=playevent)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return HttpResponseRedirect(reverse("view_game", args=[playevent.game.id]))
|
||||
return HttpResponseRedirect(reverse("games:view_game", args=[playevent.game.id]))
|
||||
|
||||
context = {
|
||||
"form": form,
|
||||
|
||||
+109
-68
@@ -1,17 +1,18 @@
|
||||
from typing import Any
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.paginator import Paginator
|
||||
from django.http import (
|
||||
HttpRequest,
|
||||
HttpResponse,
|
||||
HttpResponseBadRequest,
|
||||
HttpResponseRedirect,
|
||||
)
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from common.components import A, Button, Icon, LinkedPurchase, PurchasePrice
|
||||
from common.time import dateformat
|
||||
@@ -20,6 +21,62 @@ from games.models import Game, Purchase
|
||||
from games.views.general import use_custom_redirect
|
||||
|
||||
|
||||
def _render_purchase_buttons(purchase_id, is_refunded):
|
||||
"""Return button group HTML for a purchase row."""
|
||||
return render_to_string(
|
||||
"cotton/button_group.html",
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"href": "#",
|
||||
"hx_get": reverse(
|
||||
"games:refund_purchase_confirmation",
|
||||
args=[purchase_id],
|
||||
),
|
||||
"hx_target": "#global-modal-container",
|
||||
"slot": Icon("refund"),
|
||||
"title": "Mark as refunded",
|
||||
}
|
||||
if not is_refunded
|
||||
else {},
|
||||
{
|
||||
"href": reverse("games:edit_purchase", args=[purchase_id]),
|
||||
"slot": Icon("edit"),
|
||||
"title": "Edit",
|
||||
"color": "gray",
|
||||
},
|
||||
{
|
||||
"href": reverse("games:delete_purchase", args=[purchase_id]),
|
||||
"slot": Icon("delete"),
|
||||
"title": "Delete",
|
||||
"color": "red",
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _render_purchase_row(purchase):
|
||||
"""Return a row dict for simple-table rendering."""
|
||||
return {
|
||||
"row_id": f"purchase-row-{purchase.id}",
|
||||
"cell_data": [
|
||||
LinkedPurchase(purchase),
|
||||
purchase.get_type_display(),
|
||||
PurchasePrice(purchase),
|
||||
purchase.infinite,
|
||||
purchase.date_purchased.strftime(dateformat),
|
||||
(
|
||||
purchase.date_refunded.strftime(dateformat)
|
||||
if purchase.date_refunded
|
||||
else "-"
|
||||
),
|
||||
purchase.created_at.strftime(dateformat),
|
||||
_render_purchase_buttons(purchase.id, bool(purchase.date_refunded)),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@login_required
|
||||
def list_purchases(request: HttpRequest) -> HttpResponse:
|
||||
context: dict[Any, Any] = {}
|
||||
@@ -43,7 +100,7 @@ def list_purchases(request: HttpRequest) -> HttpResponse:
|
||||
else None
|
||||
),
|
||||
"data": {
|
||||
"header_action": A([], Button([], "Add purchase"), url="add_purchase"),
|
||||
"header_action": A([], Button([], "Add purchase"), url_name="games:add_purchase"),
|
||||
"columns": [
|
||||
"Name",
|
||||
"Type",
|
||||
@@ -54,54 +111,7 @@ def list_purchases(request: HttpRequest) -> HttpResponse:
|
||||
"Created",
|
||||
"Actions",
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
LinkedPurchase(purchase),
|
||||
purchase.get_type_display(),
|
||||
PurchasePrice(purchase),
|
||||
purchase.infinite,
|
||||
purchase.date_purchased.strftime(dateformat),
|
||||
(
|
||||
purchase.date_refunded.strftime(dateformat)
|
||||
if purchase.date_refunded
|
||||
else "-"
|
||||
),
|
||||
purchase.created_at.strftime(dateformat),
|
||||
render_to_string(
|
||||
"cotton/button_group.html",
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"href": reverse(
|
||||
"refund_purchase", args=[purchase.pk]
|
||||
),
|
||||
"slot": Icon("refund"),
|
||||
"title": "Mark as refunded",
|
||||
}
|
||||
if not purchase.date_refunded
|
||||
else {},
|
||||
{
|
||||
"href": reverse(
|
||||
"edit_purchase", args=[purchase.pk]
|
||||
),
|
||||
"slot": Icon("edit"),
|
||||
"title": "Edit",
|
||||
"color": "gray",
|
||||
},
|
||||
{
|
||||
"href": reverse(
|
||||
"delete_purchase", args=[purchase.pk]
|
||||
),
|
||||
"slot": Icon("delete"),
|
||||
"title": "Delete",
|
||||
"color": "red",
|
||||
},
|
||||
]
|
||||
},
|
||||
),
|
||||
]
|
||||
for purchase in purchases
|
||||
],
|
||||
"rows": [_render_purchase_row(purchase) for purchase in purchases],
|
||||
},
|
||||
}
|
||||
return render(request, "list_purchases.html", context)
|
||||
@@ -119,12 +129,12 @@ def add_purchase(request: HttpRequest, game_id: int = 0) -> HttpResponse:
|
||||
if "submit_and_redirect" in request.POST:
|
||||
return HttpResponseRedirect(
|
||||
reverse(
|
||||
"add_session_for_game",
|
||||
"games:add_session_for_game",
|
||||
kwargs={"game_id": purchase.first_game.id},
|
||||
)
|
||||
)
|
||||
else:
|
||||
return redirect("list_purchases")
|
||||
return redirect("games:list_purchases")
|
||||
else:
|
||||
if game_id:
|
||||
game = Game.objects.get(id=game_id)
|
||||
@@ -152,7 +162,7 @@ def edit_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse:
|
||||
form = PurchaseForm(request.POST or None, instance=purchase)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
context["title"] = "Edit Purchase"
|
||||
context["form"] = form
|
||||
context["purchase_id"] = str(purchase_id)
|
||||
@@ -164,7 +174,7 @@ def edit_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse:
|
||||
def delete_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse:
|
||||
purchase = get_object_or_404(Purchase, id=purchase_id)
|
||||
purchase.delete()
|
||||
return redirect("list_purchases")
|
||||
return redirect("games:list_purchases")
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -180,33 +190,60 @@ def view_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse:
|
||||
@login_required
|
||||
def drop_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse:
|
||||
purchase = get_object_or_404(Purchase, id=purchase_id)
|
||||
purchase.date_dropped = timezone.now()
|
||||
purchase.save()
|
||||
return redirect("list_purchases")
|
||||
for game in purchase.games.all():
|
||||
game.status = Game.Status.ABANDONED
|
||||
game.save()
|
||||
return redirect("games:list_purchases")
|
||||
|
||||
|
||||
@login_required
|
||||
def refund_purchase_confirmation(
|
||||
request: HttpRequest, purchase_id: int
|
||||
) -> HttpResponse:
|
||||
return render(
|
||||
request,
|
||||
"partials/refund_purchase_confirmation.html",
|
||||
{"purchase_id": purchase_id},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def refund_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse:
|
||||
purchase = get_object_or_404(Purchase, id=purchase_id)
|
||||
purchase.date_refunded = timezone.now()
|
||||
purchase.save()
|
||||
return redirect("list_purchases")
|
||||
|
||||
for game in purchase.games.all():
|
||||
game.status = Game.Status.ABANDONED
|
||||
game.save()
|
||||
|
||||
purchase.refund()
|
||||
|
||||
messages.success(request, "Purchase refunded")
|
||||
row_data = _render_purchase_row(purchase)
|
||||
row_html = render_to_string(
|
||||
"cotton/table_row.html",
|
||||
{"data": row_data},
|
||||
)
|
||||
modal_close = (
|
||||
'<template id="refund-confirmation-modal" hx-swap-oob="outerHTML"></template>'
|
||||
)
|
||||
return HttpResponse(row_html + modal_close, status=200)
|
||||
|
||||
|
||||
@login_required
|
||||
def finish_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse:
|
||||
purchase = get_object_or_404(Purchase, id=purchase_id)
|
||||
purchase.date_finished = timezone.now()
|
||||
purchase.save()
|
||||
return redirect("list_purchases")
|
||||
for game in purchase.games.all():
|
||||
game.status = Game.Status.FINISHED
|
||||
game.save()
|
||||
return redirect("games:list_purchases")
|
||||
|
||||
|
||||
def related_purchase_by_game(request: HttpRequest) -> HttpResponse:
|
||||
games: list[str] = []
|
||||
games = request.GET.getlist("games")
|
||||
if not games:
|
||||
return HttpResponseBadRequest("Invalid game_id")
|
||||
if isinstance(games, int) or isinstance(games, str):
|
||||
games = [games]
|
||||
context = {}
|
||||
if games:
|
||||
form = PurchaseForm()
|
||||
qs = Purchase.objects.filter(games__in=games, type=Purchase.GAME).order_by(
|
||||
"games__sort_name"
|
||||
@@ -216,4 +253,8 @@ def related_purchase_by_game(request: HttpRequest) -> HttpResponse:
|
||||
first_option = qs.first()
|
||||
if first_option:
|
||||
form.fields["related_purchase"].initial = first_option.id
|
||||
return render(request, "partials/related_purchase_field.html", {"form": form})
|
||||
context["form"] = form
|
||||
return render(request, "partials/related_purchase_field.html", context)
|
||||
else:
|
||||
# abort swap
|
||||
return HttpResponse(status=204)
|
||||
|
||||
+37
-20
@@ -25,7 +25,7 @@ from common.time import (
|
||||
)
|
||||
from common.utils import truncate
|
||||
from games.forms import SessionForm
|
||||
from games.models import Game, Session
|
||||
from games.models import Device, Game, Session
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -34,6 +34,7 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||
page_number = request.GET.get("page", 1)
|
||||
limit = request.GET.get("limit", 10)
|
||||
sessions = Session.objects.order_by("-timestamp_start", "created_at")
|
||||
device_list = Device.objects.order_by("name")
|
||||
search_string = request.GET.get("search_string", search_string)
|
||||
if search_string != "":
|
||||
sessions = sessions.filter(
|
||||
@@ -80,7 +81,7 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||
Div(
|
||||
children=[
|
||||
A(
|
||||
url="add_session",
|
||||
url_name="games:add_session",
|
||||
children=Button(
|
||||
icon=True,
|
||||
size="xs",
|
||||
@@ -88,8 +89,8 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||
),
|
||||
),
|
||||
A(
|
||||
url=reverse(
|
||||
"list_sessions_start_session_from_session",
|
||||
href=reverse(
|
||||
"games:list_sessions_start_session_from_session",
|
||||
args=[last_session.pk],
|
||||
),
|
||||
children=Popover(
|
||||
@@ -123,11 +124,25 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||
"Actions",
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
NameWithIcon(session_id=session.pk),
|
||||
{
|
||||
"row_id": f"session-row-{session.pk}",
|
||||
"hx_trigger": "device-changed from:body",
|
||||
"hx_get": "",
|
||||
"hx_select": f"#session-row-{session.pk}",
|
||||
"hx_swap": "outerHTML",
|
||||
"cell_data": [
|
||||
NameWithIcon(session=session),
|
||||
f"{local_strftime(session.timestamp_start)}{f' — {local_strftime(session.timestamp_end, timeformat)}' if session.timestamp_end else ''}",
|
||||
session.duration_formatted_with_mark,
|
||||
session.device,
|
||||
render_to_string(
|
||||
"partials/sessiondevice_selector.html",
|
||||
{
|
||||
"session": session,
|
||||
"session_device": session.device,
|
||||
"session_devices": device_list,
|
||||
},
|
||||
request=request,
|
||||
),
|
||||
session.created_at.strftime(dateformat),
|
||||
render_to_string(
|
||||
"cotton/button_group.html",
|
||||
@@ -135,7 +150,7 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||
"buttons": [
|
||||
{
|
||||
"href": reverse(
|
||||
"list_sessions_end_session", args=[session.pk]
|
||||
"games:list_sessions_end_session", args=[session.pk]
|
||||
),
|
||||
"slot": Icon("end"),
|
||||
"title": "Finish session now",
|
||||
@@ -149,7 +164,7 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||
# in the button group component
|
||||
else {},
|
||||
{
|
||||
"href": reverse("edit_session", args=[session.pk]),
|
||||
"href": reverse("games:edit_session", args=[session.pk]),
|
||||
"slot": Icon("edit"),
|
||||
"title": "Edit",
|
||||
# "color": "gray",
|
||||
@@ -157,7 +172,7 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||
},
|
||||
{
|
||||
"href": reverse(
|
||||
"delete_session", args=[session.pk]
|
||||
"games:delete_session", args=[session.pk]
|
||||
),
|
||||
"slot": Icon("delete"),
|
||||
"title": "Delete",
|
||||
@@ -167,7 +182,8 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||
]
|
||||
},
|
||||
),
|
||||
]
|
||||
],
|
||||
}
|
||||
for session in sessions
|
||||
],
|
||||
},
|
||||
@@ -193,7 +209,7 @@ def add_session(request: HttpRequest, game_id: int = 0) -> HttpResponse:
|
||||
form = SessionForm(request.POST or None, initial=initial)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
else:
|
||||
if game_id:
|
||||
game = Game.objects.get(id=game_id)
|
||||
@@ -208,9 +224,9 @@ def add_session(request: HttpRequest, game_id: int = 0) -> HttpResponse:
|
||||
|
||||
context["title"] = "Add New Session"
|
||||
# TODO: re-add custom buttons #91
|
||||
# context["script_name"] = "add_session.js"
|
||||
context["script_name"] = "add_session.js"
|
||||
context["form"] = form
|
||||
return render(request, "add.html", context)
|
||||
return render(request, "add_session.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -220,10 +236,11 @@ def edit_session(request: HttpRequest, session_id: int) -> HttpResponse:
|
||||
form = SessionForm(request.POST or None, instance=session)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
context["title"] = "Edit Session"
|
||||
context["script_name"] = "add_session.js"
|
||||
context["form"] = form
|
||||
return render(request, "add.html", context)
|
||||
return render(request, "add_session.html", context)
|
||||
|
||||
|
||||
def clone_session_by_id(session_id: int) -> Session:
|
||||
@@ -248,7 +265,7 @@ def new_session_from_existing_session(
|
||||
"session_count": int(request.GET.get("session_count", 0)) + 1,
|
||||
}
|
||||
return render(request, template, context)
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -264,18 +281,18 @@ def end_session(
|
||||
"session_count": request.GET.get("session_count", 0),
|
||||
}
|
||||
return render(request, template, context)
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_session(request: HttpRequest, session_id: int = 0) -> HttpResponse:
|
||||
session = get_object_or_404(Session, id=session_id)
|
||||
session.delete()
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_session(request: HttpRequest, session_id: int = 0) -> HttpResponse:
|
||||
session = get_object_or_404(Session, id=session_id)
|
||||
session.delete()
|
||||
return redirect("list_sessions")
|
||||
return redirect("games:list_sessions")
|
||||
|
||||
@@ -17,7 +17,7 @@ class EditStatusChangeView(LoginRequiredMixin, UpdateView):
|
||||
return get_object_or_404(GameStatusChange, id=self.kwargs["statuschange_id"])
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("list_platforms")
|
||||
return reverse_lazy("games:list_platforms")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
@@ -31,7 +31,7 @@ class AddStatusChangeView(LoginRequiredMixin, CreateView):
|
||||
template_name = "add.html"
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("view_game", kwargs={"pk": self.object.game.id})
|
||||
return reverse_lazy("games:view_game", kwargs={"pk": self.object.game.id})
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
@@ -54,4 +54,4 @@ class GameStatusChangeDeleteView(LoginRequiredMixin, DeleteView):
|
||||
template_name = "gamestatuschange_confirm_delete.html"
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("view_game", kwargs={"game_id": self.object.game.id})
|
||||
return reverse_lazy("games:view_game", kwargs={"game_id": self.object.game.id})
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/cli": "^4.1.18",
|
||||
"flowbite": "^2.4.1"
|
||||
"flowbite": "^4.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -17,7 +17,6 @@ dependencies = [
|
||||
"django>6.0",
|
||||
"gunicorn>=23.0.0,<24",
|
||||
"uvicorn>=0.30.1,<0.31",
|
||||
"graphene-django>=3.2.0,<4",
|
||||
"django-htmx>=1.18.0,<2",
|
||||
"django-template-partials>=24.2,<25",
|
||||
"markdown>=3.6,<4",
|
||||
@@ -26,7 +25,7 @@ dependencies = [
|
||||
"croniter>=5.0.1,<6",
|
||||
"requests>=2.32.3,<3",
|
||||
"pyyaml>=6.0.2,<7",
|
||||
"django-ninja>1.5",
|
||||
"django-ninja>=1.6.2",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
@@ -43,7 +42,8 @@ dev = [
|
||||
"isort>=5.13.2,<6",
|
||||
"pre-commit>=3.7.1,<4",
|
||||
"django-debug-toolbar>=4.4.2,<5",
|
||||
"ruff"
|
||||
"ruff",
|
||||
"pytest-django>=4.12.0",
|
||||
]
|
||||
|
||||
[tool.uv]
|
||||
@@ -57,3 +57,7 @@ requires = ["uv_build>=0.9.26,<0.10.0"]
|
||||
build-backend = "uv_build"
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
DJANGO_SETTINGS_MODULE = "timetracker.settings"
|
||||
python_files = ["test_*.py"]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,35 +0,0 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import django
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "timetracker.settings")
|
||||
django.setup()
|
||||
|
||||
from django.test import TestCase
|
||||
from graphene_django.utils.testing import GraphQLTestCase
|
||||
|
||||
from games import schema
|
||||
from games.models import Game
|
||||
|
||||
|
||||
class GameAPITestCase(GraphQLTestCase):
|
||||
GRAPHENE_SCHEMA = schema.schema
|
||||
|
||||
def test_query_all_games(self):
|
||||
response = self.query(
|
||||
"""
|
||||
query {
|
||||
games {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
self.assertResponseNoErrors(response)
|
||||
self.assertEqual(
|
||||
len(json.loads(response.content)["data"]["games"]),
|
||||
Game.objects.count(),
|
||||
)
|
||||
@@ -0,0 +1,106 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase, Client
|
||||
|
||||
from games.models import Device, Game, Platform, Purchase, Session
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class MiddlewareIntegrationTest(TestCase):
|
||||
"""Integration tests for HTMXMessagesMiddleware.
|
||||
|
||||
These tests hit real endpoints that use messages.success() to verify
|
||||
the full chain: API endpoint → messages → middleware → HX-Trigger header.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def _create_user():
|
||||
return User.objects.create_user(
|
||||
username="testuser", password="testpass123"
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
self.user = self._create_user()
|
||||
self.client.force_login(self.user)
|
||||
pl = Platform(name="Test Platform")
|
||||
pl.save()
|
||||
self.game = Game(name="Test Game", platform=pl)
|
||||
self.game.save()
|
||||
|
||||
def test_non_htmx_request_with_message_gets_hx_trigger(self):
|
||||
"""
|
||||
Regression test: vanilla fetch() requests that set Django messages
|
||||
must receive HX-Trigger so fetchWithHtmxTriggers can read them.
|
||||
"""
|
||||
response = self.client.patch(
|
||||
f"/api/games/{self.game.id}/status",
|
||||
data=json.dumps({"status": "played"}),
|
||||
content_type="application/json",
|
||||
)
|
||||
self.assertEqual(response.status_code, 204)
|
||||
self.assertIn("HX-Trigger", response)
|
||||
data = json.loads(response["HX-Trigger"])
|
||||
self.assertIn("show-toast", data)
|
||||
self.assertEqual(data["show-toast"]["type"], "success")
|
||||
|
||||
def test_session_device_api_endpoint_sends_hx_trigger(self):
|
||||
"""
|
||||
Verify the session device API endpoint also produces HX-Trigger.
|
||||
This is the exact endpoint used by sessiondevice_selector.html.
|
||||
"""
|
||||
device = Device(name="Test Device")
|
||||
device.save()
|
||||
zt = ZoneInfo(settings.TIME_ZONE)
|
||||
session = Session(
|
||||
game=self.game,
|
||||
device=device,
|
||||
timestamp_start=datetime(2022, 9, 26, 14, 58, tzinfo=zt),
|
||||
)
|
||||
session.save()
|
||||
|
||||
response = self.client.patch(
|
||||
f"/api/session/{session.id}/device",
|
||||
data=json.dumps({"device_id": device.id}),
|
||||
content_type="application/json",
|
||||
)
|
||||
self.assertEqual(response.status_code, 204)
|
||||
self.assertIn("HX-Trigger", response)
|
||||
data = json.loads(response["HX-Trigger"])
|
||||
self.assertIn("show-toast", data)
|
||||
self.assertEqual(data["show-toast"]["message"], "Device updated")
|
||||
|
||||
def test_refund_purchase_returns_updated_row_with_hx_trigger(
|
||||
self,
|
||||
):
|
||||
"""
|
||||
Verify the refund endpoint returns the updated row HTML so the page
|
||||
swaps it in place without navigating away (preserving URL/query params).
|
||||
"""
|
||||
purchase = Purchase.objects.create(
|
||||
date_purchased=datetime(2023, 1, 1),
|
||||
platform=Platform.objects.first() or pl,
|
||||
)
|
||||
purchase.games.set([self.game])
|
||||
response = self.client.post(
|
||||
f"/tracker/purchase/{purchase.id}/refund",
|
||||
data={"set_abandoned": ""},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotIn("HX-Redirect", response)
|
||||
self.assertIn("HX-Trigger", response)
|
||||
data = json.loads(response["HX-Trigger"])
|
||||
self.assertIn("show-toast", data)
|
||||
self.assertEqual(data["show-toast"]["message"], "Purchase refunded")
|
||||
# Verify the row HTML contains the updated row id
|
||||
body = response.content.decode()
|
||||
self.assertIn(f'purchase-row-{purchase.id}', body)
|
||||
# Verify OoO modal close element
|
||||
self.assertIn('hx-swap-oob', body)
|
||||
self.assertIn('refund-confirmation-modal', body)
|
||||
# Verify the purchase is actually refunded
|
||||
purchase.refresh_from_db()
|
||||
self.assertIsNotNone(purchase.date_refunded)
|
||||
@@ -1,14 +1,10 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import django
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "timetracker.settings")
|
||||
django.setup()
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from games.models import Game, Platform, Purchase, Session
|
||||
|
||||
@@ -17,67 +13,50 @@ ZONEINFO = ZoneInfo(settings.TIME_ZONE)
|
||||
|
||||
class PathWorksTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
pl = Platform(name="Test Platform")
|
||||
pl.save()
|
||||
g = Game(name="The Test Game")
|
||||
g.save()
|
||||
p = Purchase(
|
||||
games=[e],
|
||||
platform=pl,
|
||||
self.user = User.objects.create_superuser(
|
||||
username="testuser", email="test@example.com", password="testpass"
|
||||
)
|
||||
self.client.force_login(self.user)
|
||||
self.platform = Platform.objects.create(name="Test Platform", icon="test")
|
||||
self.game = Game.objects.create(name="Test Game", platform=self.platform)
|
||||
self.purchase = Purchase.objects.create(
|
||||
date_purchased=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO),
|
||||
platform=self.platform,
|
||||
)
|
||||
p.save()
|
||||
s = Session(
|
||||
purchase=p,
|
||||
timestamp_start=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO),
|
||||
timestamp_end=datetime(2022, 9, 26, 17, 38, tzinfo=ZONEINFO),
|
||||
)
|
||||
s.save()
|
||||
self.testSession = s
|
||||
return super().setUp()
|
||||
self.purchase.games.add(self.game)
|
||||
|
||||
def test_add_device_returns_200(self):
|
||||
url = reverse("add_device")
|
||||
response = self.client.get(url)
|
||||
def test_index_redirects_to_tracker(self):
|
||||
response = self.client.get("/")
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
def test_tracker_page_returns_200(self):
|
||||
response = self.client.get("/tracker/", follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_add_platform_returns_200(self):
|
||||
url = reverse("add_platform")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_add_game_returns_200(self):
|
||||
url = reverse("add_game")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_add_purchase_returns_200(self):
|
||||
url = reverse("add_purchase")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_add_session_returns_200(self):
|
||||
url = reverse("add_session")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_edit_session_returns_200(self):
|
||||
id = self.testSession.id
|
||||
url = reverse("edit_session", args=[id])
|
||||
response = self.client.get(url)
|
||||
def test_game_list_returns_200(self):
|
||||
response = self.client.get(reverse("games:list_games"), follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_view_game_returns_200(self):
|
||||
url = reverse("view_game", args=[1])
|
||||
response = self.client.get(url)
|
||||
response = self.client.get(reverse("games:view_game", args=[self.game.id]))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_edit_game_returns_200(self):
|
||||
url = reverse("edit_game", args=[1])
|
||||
response = self.client.get(url)
|
||||
def test_add_game_returns_200(self):
|
||||
response = self.client.get(reverse("games:add_game"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_stats_returns_200(self):
|
||||
response = self.client.get(reverse("games:stats_alltime"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_list_sessions_returns_200(self):
|
||||
url = reverse("list_sessions")
|
||||
response = self.client.get(url)
|
||||
response = self.client.get(reverse("games:list_sessions"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_list_playevents_returns_200(self):
|
||||
response = self.client.get(reverse("games:list_playevents"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_list_purchases_returns_200(self):
|
||||
response = self.client.get(reverse("games:list_purchases"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import django
|
||||
from django.test import TestCase
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "timetracker.settings")
|
||||
django.setup()
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
|
||||
from games.models import Game, Purchase, Session
|
||||
|
||||
@@ -22,16 +17,18 @@ class FormatDurationTest(TestCase):
|
||||
g = Game(name="The Test Game")
|
||||
g.save()
|
||||
p = Purchase(
|
||||
game=g, date_purchased=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO)
|
||||
date_purchased=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO)
|
||||
)
|
||||
p.save()
|
||||
p.games.add(g)
|
||||
p.save()
|
||||
s = Session(
|
||||
purchase=p,
|
||||
game=g,
|
||||
timestamp_start=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO),
|
||||
timestamp_end=datetime(2022, 9, 26, 17, 38, tzinfo=ZONEINFO),
|
||||
)
|
||||
s.save()
|
||||
self.assertEqual(
|
||||
s.duration_formatted(),
|
||||
"02:40",
|
||||
"2.7",
|
||||
)
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import django
|
||||
from django.test import TestCase
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "timetracker.settings")
|
||||
django.setup()
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
|
||||
from games.models import Game, Session
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ from common.time import daterange, streak_bruteforce
|
||||
|
||||
|
||||
class StreakTest(unittest.TestCase):
|
||||
streak = streak_bruteforce
|
||||
|
||||
def test_daterange_exclusive(self):
|
||||
d = daterange(date(2024, 8, 1), date(2024, 8, 3))
|
||||
@@ -22,14 +21,14 @@ class StreakTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_1day_streak(self):
|
||||
self.assertEqual(streak([date(2024, 8, 1)])["days"], 1)
|
||||
self.assertEqual(streak_bruteforce([date(2024, 8, 1)])["days"], 1)
|
||||
|
||||
def test_2day_streak(self):
|
||||
self.assertEqual(streak([date(2024, 8, 1), date(2024, 8, 2)])["days"], 2)
|
||||
self.assertEqual(streak_bruteforce([date(2024, 8, 1), date(2024, 8, 2)])["days"], 2)
|
||||
|
||||
def test_31day_streak(self):
|
||||
self.assertEqual(
|
||||
streak(daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True))[
|
||||
streak_bruteforce(daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True))[
|
||||
"days"
|
||||
],
|
||||
31,
|
||||
@@ -39,14 +38,14 @@ class StreakTest(unittest.TestCase):
|
||||
d = daterange(
|
||||
date(2024, 8, 1), date(2024, 8, 5), end_inclusive=True
|
||||
) + daterange(date(2024, 8, 7), date(2024, 8, 10), end_inclusive=True)
|
||||
self.assertEqual(streak(d)["days"], 5)
|
||||
self.assertEqual(streak_bruteforce(d)["days"], 5)
|
||||
|
||||
def test_10day_streak_in_31_days(self):
|
||||
d = daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True)
|
||||
d.remove(date(2024, 8, 8))
|
||||
d.remove(date(2024, 8, 15))
|
||||
d.remove(date(2024, 8, 21))
|
||||
self.assertEqual(streak(d)["days"], 10)
|
||||
self.assertEqual(streak_bruteforce(d)["days"], 10)
|
||||
|
||||
def test_10day_streak_in_31_days_with_consecutive_missing(self):
|
||||
d = daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True)
|
||||
@@ -57,4 +56,4 @@ class StreakTest(unittest.TestCase):
|
||||
d.remove(date(2024, 8, 8))
|
||||
d.remove(date(2024, 8, 15))
|
||||
d.remove(date(2024, 8, 21))
|
||||
self.assertEqual(streak(d)["days"], 10)
|
||||
self.assertEqual(streak_bruteforce(d)["days"], 10)
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
import json
|
||||
from django.contrib.messages import constants as message_constants
|
||||
from django.contrib.messages.storage.fallback import FallbackStorage
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from games.htmx_middleware import HTMXMessagesMiddleware
|
||||
|
||||
|
||||
def get_response_ok(request):
|
||||
return HttpResponse("OK")
|
||||
|
||||
|
||||
class HtmxDetails:
|
||||
boosted = False
|
||||
current_url = ""
|
||||
target_id = ""
|
||||
|
||||
|
||||
class HTMXMessagesMiddlewareTest(TestCase):
|
||||
def _build_request(self, htmx=True, message_level=None):
|
||||
"""Build a request with FallbackStorage message backend."""
|
||||
request = HttpRequest()
|
||||
request.method = "GET"
|
||||
request.path = "/test"
|
||||
request.META = {"SERVER_NAME": "localhost", "SERVER_PORT": "80"}
|
||||
request.session = {}
|
||||
|
||||
storage = FallbackStorage(request)
|
||||
if message_level is not None:
|
||||
storage._set_level(message_level)
|
||||
request._messages = storage
|
||||
|
||||
if htmx:
|
||||
request.htmx = HtmxDetails()
|
||||
|
||||
return request
|
||||
|
||||
def test_htmx_request_with_messages_sends_hx_trigger(self):
|
||||
"""HTMX request with messages should include HX-Trigger header."""
|
||||
request = self._build_request(htmx=True)
|
||||
request._messages.add(message_constants.SUCCESS, "Item saved")
|
||||
middleware = HTMXMessagesMiddleware(get_response_ok)
|
||||
|
||||
response = middleware(request)
|
||||
|
||||
self.assertIn("HX-Trigger", response)
|
||||
data = json.loads(response["HX-Trigger"])
|
||||
self.assertIn("show-toast", data)
|
||||
self.assertEqual(data["show-toast"]["message"], "Item saved")
|
||||
self.assertEqual(data["show-toast"]["type"], "success")
|
||||
|
||||
def test_htmx_request_with_error_message(self):
|
||||
"""Error messages should map to 'error' toast type."""
|
||||
request = self._build_request(htmx=True)
|
||||
request._messages.add(message_constants.ERROR, "Something failed")
|
||||
middleware = HTMXMessagesMiddleware(get_response_ok)
|
||||
|
||||
response = middleware(request)
|
||||
|
||||
data = json.loads(response["HX-Trigger"])
|
||||
self.assertEqual(data["show-toast"]["type"], "error")
|
||||
|
||||
def test_htmx_request_with_success_message(self):
|
||||
"""Success messages should map to 'success' toast type."""
|
||||
request = self._build_request(htmx=True)
|
||||
request._messages.add(message_constants.SUCCESS, "Saved successfully")
|
||||
middleware = HTMXMessagesMiddleware(get_response_ok)
|
||||
|
||||
response = middleware(request)
|
||||
|
||||
data = json.loads(response["HX-Trigger"])
|
||||
self.assertEqual(data["show-toast"]["type"], "success")
|
||||
|
||||
def test_non_htmx_request_also_sends_hx_trigger(self):
|
||||
"""Non-HTMX requests should also include HX-Trigger header."""
|
||||
request = self._build_request(htmx=False)
|
||||
request._messages.add(message_constants.SUCCESS, "Hello")
|
||||
middleware = HTMXMessagesMiddleware(get_response_ok)
|
||||
|
||||
response = middleware(request)
|
||||
|
||||
self.assertIn("HX-Trigger", response)
|
||||
data = json.loads(response["HX-Trigger"])
|
||||
self.assertIn("show-toast", data)
|
||||
self.assertEqual(data["show-toast"]["message"], "Hello")
|
||||
|
||||
def test_htmx_request_without_messages_no_hx_trigger(self):
|
||||
"""HTMX request without messages should not include HX-Trigger header."""
|
||||
request = self._build_request(htmx=True)
|
||||
middleware = HTMXMessagesMiddleware(get_response_ok)
|
||||
|
||||
response = middleware(request)
|
||||
|
||||
self.assertNotIn("HX-Trigger", response)
|
||||
|
||||
def test_warning_message_maps_to_warning(self):
|
||||
"""Warning messages should map to 'warning' toast type."""
|
||||
request = self._build_request(htmx=True)
|
||||
request._messages.add(message_constants.WARNING, "Warning message")
|
||||
middleware = HTMXMessagesMiddleware(get_response_ok)
|
||||
|
||||
response = middleware(request)
|
||||
|
||||
data = json.loads(response["HX-Trigger"])
|
||||
self.assertEqual(data["show-toast"]["type"], "warning")
|
||||
|
||||
@override_settings(DEBUG=True)
|
||||
def test_debug_message_maps_to_debug(self):
|
||||
"""Debug messages should map to 'debug' toast type."""
|
||||
request = self._build_request(htmx=True, message_level=message_constants.DEBUG)
|
||||
request._messages.add(message_constants.DEBUG, "Debug info")
|
||||
middleware = HTMXMessagesMiddleware(get_response_ok)
|
||||
|
||||
response = middleware(request)
|
||||
|
||||
data = json.loads(response["HX-Trigger"])
|
||||
self.assertEqual(data["show-toast"]["type"], "debug")
|
||||
@@ -39,7 +39,6 @@ INSTALLED_APPS = [
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"template_partials",
|
||||
"graphene_django",
|
||||
"django_htmx",
|
||||
"django_cotton",
|
||||
"django_q",
|
||||
@@ -54,8 +53,6 @@ Q_CLUSTER = {
|
||||
"orm": "default",
|
||||
}
|
||||
|
||||
GRAPHENE = {"SCHEMA": "games.schema.schema"}
|
||||
|
||||
if DEBUG:
|
||||
INSTALLED_APPS.append("django_extensions")
|
||||
INSTALLED_APPS.append("django.contrib.admin")
|
||||
@@ -70,6 +67,7 @@ MIDDLEWARE = [
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
"django_htmx.middleware.HtmxMiddleware",
|
||||
"games.htmx_middleware.HTMXMessagesMiddleware",
|
||||
]
|
||||
|
||||
if DEBUG:
|
||||
|
||||
@@ -18,16 +18,13 @@ from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.urls import include, path
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import RedirectView
|
||||
from graphene_django.views import GraphQLView
|
||||
|
||||
from games.api import api
|
||||
|
||||
urlpatterns = [
|
||||
path("", RedirectView.as_view(url="/tracker")),
|
||||
path("api/", api.urls),
|
||||
path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True))),
|
||||
path("login/", auth_views.LoginView.as_view(), name="login"),
|
||||
path("logout/", auth_views.LogoutView.as_view(), name="logout"),
|
||||
path("tracker/", include("games.urls")),
|
||||
|
||||
@@ -202,15 +202,15 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "django-ninja"
|
||||
version = "1.5.3"
|
||||
version = "1.6.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "django" },
|
||||
{ name = "pydantic" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/02/84/27a5fceac29bd85eb8dc8a6697e93019a8742d626180f0d67b894e20a8a1/django_ninja-1.5.3.tar.gz", hash = "sha256:974803944965ad0566071633ffd4999a956f2ad1ecbed815c0de37c1c969592b", size = 3658996, upload-time = "2026-01-10T20:02:23.821Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d5/7c/3307e17b872f545c88314b2737a22f965785dfb5a120d739b0131d0492c3/django_ninja-1.6.2.tar.gz", hash = "sha256:d56ae5aa4791068ef4ac9a66cfdf2fc11f507413ded35abb79c51d0d52ad6412", size = 3685599, upload-time = "2026-03-18T20:06:47.284Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/f4/b3/30600696c2532fcf026259f2f4980b364cb6847518bb4b3365d42a4a3afe/django_ninja-1.5.3-py3-none-any.whl", hash = "sha256:0a6ead5b4e57ec1050b584eb6f36f105f256b8f4ac70d12e774d8b6dd91e2198", size = 2365685, upload-time = "2026-01-10T20:02:21.484Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/21/0c/25f72060a39632fbd2d90e9c8b6052a09cd45b0598fc06c0758d313f0052/django_ninja-1.6.2-py3-none-any.whl", hash = "sha256:20095f5900bada22ea00cf1a58af50bdb285b2354c61a9d9b47d0dc89ac462d6", size = 2374994, upload-time = "2026-03-18T20:06:45.676Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -301,59 +301,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/b5/36/7fb70f04bf00bc646cd5bb45aa9eddb15e19437a28b8fb2b4a5249fac770/filelock-3.20.3-py3-none-any.whl", hash = "sha256:4b0dda527ee31078689fc205ec4f1c1bf7d56cf88b6dc9426c4f230e46c2dce1", size = 16701, upload-time = "2026-01-09T17:55:04.334Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphene"
|
||||
version = "3.4.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "graphql-core" },
|
||||
{ name = "graphql-relay" },
|
||||
{ name = "python-dateutil" },
|
||||
{ name = "typing-extensions" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/cc/f6/bf62ff950c317ed03e77f3f6ddd7e34aaa98fe89d79ebd660c55343d8054/graphene-3.4.3.tar.gz", hash = "sha256:2a3786948ce75fe7e078443d37f609cbe5bb36ad8d6b828740ad3b95ed1a0aaa", size = 44739, upload-time = "2024-11-09T20:44:25.757Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/66/e0/61d8e98007182e6b2aca7cf65904721fb2e4bce0192272ab9cb6f69d8812/graphene-3.4.3-py2.py3-none-any.whl", hash = "sha256:820db6289754c181007a150db1f7fff544b94142b556d12e3ebc777a7bf36c71", size = 114894, upload-time = "2024-11-09T20:44:23.851Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphene-django"
|
||||
version = "3.2.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "django" },
|
||||
{ name = "graphene" },
|
||||
{ name = "graphql-core" },
|
||||
{ name = "graphql-relay" },
|
||||
{ name = "promise" },
|
||||
{ name = "text-unidecode" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/6f/7a/8aef131349329dcd167578720f6364412f1728bfda14bba22c1e7b5d8365/graphene-django-3.2.3.tar.gz", hash = "sha256:d831bfe8e9a6e77e477b7854faef4addb318f386119a69ee4c57b74560f3e07d", size = 88393, upload-time = "2025-03-13T08:33:03.949Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/18/35/ab9c668222f6271a0b71efb147c46816229dbb9fa5d15ee6b025eb08d4b2/graphene_django-3.2.3-py2.py3-none-any.whl", hash = "sha256:0c673a4dad315b26b4d18eb379ad0c7027fd6a36d23a1848b7c7c09a14a9271e", size = 114959, upload-time = "2025-03-13T08:33:02.453Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphql-core"
|
||||
version = "3.2.7"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ac/9b/037a640a2983b09aed4a823f9cf1729e6d780b0671f854efa4727a7affbe/graphql_core-3.2.7.tar.gz", hash = "sha256:27b6904bdd3b43f2a0556dad5d579bdfdeab1f38e8e8788e555bdcb586a6f62c", size = 513484, upload-time = "2025-11-01T22:30:40.436Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/0a/14/933037032608787fb92e365883ad6a741c235e0ff992865ec5d904a38f1e/graphql_core-3.2.7-py3-none-any.whl", hash = "sha256:17fc8f3ca4a42913d8e24d9ac9f08deddf0a0b2483076575757f6c412ead2ec0", size = 207262, upload-time = "2025-11-01T22:30:38.912Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphql-relay"
|
||||
version = "3.2.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "graphql-core" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d1/13/98fbf8d67552f102488ffc16c6f559ce71ea15f6294728d33928ab5ff14d/graphql-relay-3.2.0.tar.gz", hash = "sha256:1ff1c51298356e481a0be009ccdff249832ce53f30559c1338f22a0e0d17250c", size = 50027, upload-time = "2022-04-16T11:03:45.447Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/74/16/a4cf06adbc711bd364a73ce043b0b08d8fa5aae3df11b6ee4248bcdad2e0/graphql_relay-3.2.0-py3-none-any.whl", hash = "sha256:c9b22bd28b170ba1fe674c74384a8ff30a76c8e26f88ac3aa1584dd3179953e5", size = 16940, upload-time = "2022-04-16T11:03:43.895Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gunicorn"
|
||||
version = "23.0.0"
|
||||
@@ -580,15 +527,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/07/92/caae8c86e94681b42c246f0bca35c059a2f0529e5b92619f6aba4cf7e7b6/pre_commit-3.8.0-py2.py3-none-any.whl", hash = "sha256:9a90a53bf82fdd8778d58085faf8d83df56e40dfe18f45b19446e26bf1b3a63f", size = 204643, upload-time = "2024-07-28T19:58:59.335Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "promise"
|
||||
version = "2.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "six" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/cf/9c/fb5d48abfe5d791cd496e4242ebcf87a4bb2e0c3dcd6e0ae68c11426a528/promise-2.3.tar.gz", hash = "sha256:dfd18337c523ba4b6a58801c164c1904a9d4d1b1747c7d5dbf45b693a49d93d0", size = 19534, upload-time = "2019-12-18T07:31:43.07Z" }
|
||||
|
||||
[[package]]
|
||||
name = "pydantic"
|
||||
version = "2.12.5"
|
||||
@@ -682,6 +620,18 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/a8/a4/20da314d277121d6534b3a980b29035dcd51e6744bd79075a6ce8fa4eb8d/pytest-8.4.2-py3-none-any.whl", hash = "sha256:872f880de3fc3a5bdc88a11b39c9710c3497a547cfa9320bc3c5e62fbf272e79", size = 365750, upload-time = "2025-09-04T14:34:20.226Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pytest-django"
|
||||
version = "4.12.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "pytest" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/13/2b/db9a193df89e5660137f5428063bcc2ced7ad790003b26974adf5c5ceb3b/pytest_django-4.12.0.tar.gz", hash = "sha256:df94ec819a83c8979c8f6de13d9cdfbe76e8c21d39473cfe2b40c9fc9be3c758", size = 91156, upload-time = "2026-02-14T18:40:49.235Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/83/a5/41d091f697c09609e7ef1d5d61925494e0454ebf51de7de05f0f0a728f1d/pytest_django-4.12.0-py3-none-any.whl", hash = "sha256:3ff300c49f8350ba2953b90297d23bf5f589db69545f56f1ec5f8cff5da83e85", size = 26123, upload-time = "2026-02-14T18:40:47.381Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-dateutil"
|
||||
version = "2.9.0.post0"
|
||||
@@ -870,15 +820,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/49/4b/359f28a903c13438ef59ebeee215fb25da53066db67b305c125f1c6d2a25/sqlparse-0.5.5-py3-none-any.whl", hash = "sha256:12a08b3bf3eec877c519589833aed092e2444e68240a3577e8e26148acc7b1ba", size = 46138, upload-time = "2025-12-19T07:17:46.573Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "text-unidecode"
|
||||
version = "1.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ab/e2/e9a00f0ccb71718418230718b3d900e71a5d16e701a3dae079a21e9cd8f8/text-unidecode-1.3.tar.gz", hash = "sha256:bad6603bb14d279193107714b288be206cac565dfa49aa5b105294dd5c4aab93", size = 76885, upload-time = "2019-08-30T21:36:45.405Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/a6/a5/c0b6468d3824fe3fde30dbb5e1f687b291608f9473681bbf7dabbf5a87d7/text_unidecode-1.3-py2.py3-none-any.whl", hash = "sha256:1311f10e8b895935241623731c2ba64f4c455287888b18189350b67134a822e8", size = 78154, upload-time = "2019-08-30T21:37:03.543Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "timetracker"
|
||||
version = "1.6.1"
|
||||
@@ -891,7 +832,6 @@ dependencies = [
|
||||
{ name = "django-ninja" },
|
||||
{ name = "django-q2" },
|
||||
{ name = "django-template-partials" },
|
||||
{ name = "graphene-django" },
|
||||
{ name = "gunicorn" },
|
||||
{ name = "markdown" },
|
||||
{ name = "pyyaml" },
|
||||
@@ -909,6 +849,7 @@ dev = [
|
||||
{ name = "mypy" },
|
||||
{ name = "pre-commit" },
|
||||
{ name = "pytest" },
|
||||
{ name = "pytest-django" },
|
||||
{ name = "pyyaml" },
|
||||
{ name = "ruff" },
|
||||
]
|
||||
@@ -919,10 +860,9 @@ requires-dist = [
|
||||
{ name = "django", specifier = ">6.0" },
|
||||
{ name = "django-cotton", specifier = "==2.3" },
|
||||
{ name = "django-htmx", specifier = ">=1.18.0,<2" },
|
||||
{ name = "django-ninja", specifier = ">1.5" },
|
||||
{ name = "django-ninja", specifier = ">=1.6.2" },
|
||||
{ name = "django-q2", specifier = ">=1.7.4,<2" },
|
||||
{ name = "django-template-partials", specifier = ">=24.2,<25" },
|
||||
{ name = "graphene-django", specifier = ">=3.2.0,<4" },
|
||||
{ name = "gunicorn", specifier = ">=23.0.0,<24" },
|
||||
{ name = "markdown", specifier = ">=3.6,<4" },
|
||||
{ name = "pyyaml", specifier = ">=6.0.2,<7" },
|
||||
@@ -940,6 +880,7 @@ dev = [
|
||||
{ name = "mypy", specifier = ">=1.10.1,<2" },
|
||||
{ name = "pre-commit", specifier = ">=3.7.1,<4" },
|
||||
{ name = "pytest", specifier = ">=8.2.2,<9" },
|
||||
{ name = "pytest-django", specifier = ">=4.12.0" },
|
||||
{ name = "pyyaml", specifier = ">=6.0.1,<7" },
|
||||
{ name = "ruff" },
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user