list platforms, fix editing platform
This commit is contained in:
parent
c61adad180
commit
74b9d0421c
|
@ -1,8 +1,11 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/psf/black
|
# disable due to incomaptible formatting between
|
||||||
rev: 24.8.0
|
# black and ruff
|
||||||
hooks:
|
# TODO: replace with ruff when it works on NixOS
|
||||||
- id: black
|
# - repo: https://github.com/psf/black
|
||||||
|
# rev: 24.8.0
|
||||||
|
# hooks:
|
||||||
|
# - id: black
|
||||||
- repo: https://github.com/pycqa/isort
|
- repo: https://github.com/pycqa/isort
|
||||||
rev: 5.13.2
|
rev: 5.13.2
|
||||||
hooks:
|
hooks:
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.core.paginator import Paginator
|
||||||
|
from django.http import HttpRequest, HttpResponse
|
||||||
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
|
from django.template.loader import render_to_string
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from games.forms import PlatformForm
|
||||||
|
from games.models import Platform
|
||||||
|
from games.views import dateformat
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def list_platforms(request: HttpRequest) -> HttpResponse:
|
||||||
|
context: dict[Any, Any] = {}
|
||||||
|
page_number = request.GET.get("page", 1)
|
||||||
|
limit = request.GET.get("limit", 10)
|
||||||
|
platforms = Platform.objects.order_by("-created_at")
|
||||||
|
page_obj = None
|
||||||
|
if int(limit) != 0:
|
||||||
|
paginator = Paginator(platforms, limit)
|
||||||
|
page_obj = paginator.get_page(page_number)
|
||||||
|
platforms = page_obj.object_list
|
||||||
|
|
||||||
|
context = {
|
||||||
|
"title": "Manage platforms",
|
||||||
|
"page_obj": page_obj or None,
|
||||||
|
"elided_page_range": (
|
||||||
|
page_obj.paginator.get_elided_page_range(
|
||||||
|
page_number, on_each_side=1, on_ends=1
|
||||||
|
)
|
||||||
|
if page_obj
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
"data": {
|
||||||
|
"columns": [
|
||||||
|
"Name",
|
||||||
|
"Group",
|
||||||
|
"Created",
|
||||||
|
"Actions",
|
||||||
|
],
|
||||||
|
"rows": [
|
||||||
|
[
|
||||||
|
platform.name,
|
||||||
|
platform.group,
|
||||||
|
platform.created_at.strftime(dateformat),
|
||||||
|
render_to_string(
|
||||||
|
"components/button_group_sm.html",
|
||||||
|
{
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"href": reverse(
|
||||||
|
"edit_platform", args=[platform.pk]
|
||||||
|
),
|
||||||
|
"text": "Edit",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"href": reverse(
|
||||||
|
"delete_platform", args=[platform.pk]
|
||||||
|
),
|
||||||
|
"text": "Delete",
|
||||||
|
"color": "red",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
for platform in platforms
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return render(request, "list_purchases.html", context)
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@
|
||||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Editions</a>
|
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Editions</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'add_platform' %}"
|
<a href="{% url 'list_platforms' %}"
|
||||||
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Platforms</a>
|
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Platforms</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from games import deviceviews, gameviews, purchaseviews, sessionviews, views
|
from games import (
|
||||||
|
deviceviews,
|
||||||
|
gameviews,
|
||||||
|
platformviews,
|
||||||
|
purchaseviews,
|
||||||
|
sessionviews,
|
||||||
|
views,
|
||||||
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.index, name="index"),
|
path("", views.index, name="index"),
|
||||||
|
@ -24,6 +31,12 @@ urlpatterns = [
|
||||||
path("game/list", gameviews.list_games, name="list_games"),
|
path("game/list", gameviews.list_games, name="list_games"),
|
||||||
path("platform/add", views.add_platform, name="add_platform"),
|
path("platform/add", views.add_platform, name="add_platform"),
|
||||||
path("platform/<int:platform_id>/edit", views.edit_platform, name="edit_platform"),
|
path("platform/<int:platform_id>/edit", views.edit_platform, name="edit_platform"),
|
||||||
|
path(
|
||||||
|
"platform/<int:platform_id>/delete",
|
||||||
|
platformviews.delete_platform,
|
||||||
|
name="delete_platform",
|
||||||
|
),
|
||||||
|
path("platform/list", platformviews.list_platforms, name="list_platforms"),
|
||||||
path("purchase/add", views.add_purchase, name="add_purchase"),
|
path("purchase/add", views.add_purchase, name="add_purchase"),
|
||||||
path("purchase/<int:purchase_id>/edit", views.edit_purchase, name="edit_purchase"),
|
path("purchase/<int:purchase_id>/edit", views.edit_purchase, name="edit_purchase"),
|
||||||
path(
|
path(
|
||||||
|
|
|
@ -224,11 +224,11 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||||
@use_custom_redirect
|
@use_custom_redirect
|
||||||
def edit_platform(request: HttpRequest, platform_id: int) -> HttpResponse:
|
def edit_platform(request: HttpRequest, platform_id: int) -> HttpResponse:
|
||||||
context = {}
|
context = {}
|
||||||
purchase = get_object_or_404(Purchase, id=platform_id)
|
platform = get_object_or_404(Platform, id=platform_id)
|
||||||
form = PlatformForm(request.POST or None, instance=purchase)
|
form = PlatformForm(request.POST or None, instance=platform)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
return redirect("list_sessions")
|
return redirect("list_platforms")
|
||||||
context["title"] = "Edit Platform"
|
context["title"] = "Edit Platform"
|
||||||
context["form"] = form
|
context["form"] = form
|
||||||
return render(request, "add.html", context)
|
return render(request, "add.html", context)
|
||||||
|
@ -750,15 +750,11 @@ def stats(request: HttpRequest, year: int = 0) -> HttpResponse:
|
||||||
"all_finished_this_year_count": purchases_finished_this_year.count(),
|
"all_finished_this_year_count": purchases_finished_this_year.count(),
|
||||||
"this_year_finished_this_year": purchases_finished_this_year_released_this_year.select_related(
|
"this_year_finished_this_year": purchases_finished_this_year_released_this_year.select_related(
|
||||||
"edition"
|
"edition"
|
||||||
).order_by(
|
).order_by("date_finished"),
|
||||||
"date_finished"
|
|
||||||
),
|
|
||||||
"this_year_finished_this_year_count": purchases_finished_this_year_released_this_year.count(),
|
"this_year_finished_this_year_count": purchases_finished_this_year_released_this_year.count(),
|
||||||
"purchased_this_year_finished_this_year": purchased_this_year_finished_this_year.select_related(
|
"purchased_this_year_finished_this_year": purchased_this_year_finished_this_year.select_related(
|
||||||
"edition"
|
"edition"
|
||||||
).order_by(
|
).order_by("date_finished"),
|
||||||
"date_finished"
|
|
||||||
),
|
|
||||||
"total_sessions": this_year_sessions.count(),
|
"total_sessions": this_year_sessions.count(),
|
||||||
"unique_days": unique_days["dates"],
|
"unique_days": unique_days["dates"],
|
||||||
"unique_days_percent": int(unique_days["dates"] / 365 * 100),
|
"unique_days_percent": int(unique_days["dates"] / 365 * 100),
|
||||||
|
|
Loading…
Reference in New Issue