diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5762804..f251f3e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,11 @@ repos: -- repo: https://github.com/psf/black - rev: 24.8.0 - hooks: - - id: black +# disable due to incomaptible formatting between +# black and ruff +# TODO: replace with ruff when it works on NixOS +# - repo: https://github.com/psf/black +# rev: 24.8.0 +# hooks: +# - id: black - repo: https://github.com/pycqa/isort rev: 5.13.2 hooks: diff --git a/games/platformviews.py b/games/platformviews.py new file mode 100644 index 0000000..d46c74f --- /dev/null +++ b/games/platformviews.py @@ -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) + + diff --git a/games/templates/navbar.html b/games/templates/navbar.html index c4eb33e..8e4a760 100644 --- a/games/templates/navbar.html +++ b/games/templates/navbar.html @@ -107,7 +107,7 @@ class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Editions