replace slippers with django-cotton
Django CI/CD / test (push) Successful in 59s Details
Django CI/CD / build-and-push (push) Successful in 2m4s Details

main reason: slippers cannot pass request via context inside its
components, making it annoying to use template takes that take request.
more reasons: not actively worked on, no named slots, having to define
components in components.yaml + new components do not get registered
without restarting server
This commit is contained in:
Lukáš Kucharczyk 2024-09-02 17:43:41 +02:00
parent 9af4c79947
commit b8258e2937
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
32 changed files with 152 additions and 124 deletions

View File

@ -15,4 +15,6 @@ repos:
rev: v1.34.0 rev: v1.34.0
hooks: hooks:
- id: djlint-reformat-django - id: djlint-reformat-django
args: ["--ignore", "H011"]
- id: djlint-django - id: djlint-django
args: ["--ignore", "H011"]

View File

@ -17,10 +17,10 @@ def Popover(
result = mark_safe( result = mark_safe(
str(content) str(content)
+ render_to_string( + render_to_string(
"components/popover.html", "cotton/popover.html",
{ {
"id": id, "id": id,
"children": popover_content, "slot": popover_content,
}, },
) )
) )

View File

@ -1,10 +0,0 @@
components:
gamelink: "components/game_link.html"
popover: "components/popover.html"
table: "components/table.html"
table_row: "components/table_row.html"
table_td: "components/table_td.html"
simple_table: "components/simple_table.html"
button_group_sm: "components/button_group_sm.html"
button_group_button_sm: "components/button_group_button_sm.html"
h1: "components/h1.html"

View File

@ -1,5 +0,0 @@
<div class="inline-flex rounded-md shadow-sm" role="group">
{% for button in buttons %}
{% button_group_button_sm href=button.href text=button.text color=button.color %}
{% endfor %}
</div>

View File

@ -1,13 +0,0 @@
<a href="{{ edit_url }}">
<button type="button"
title="Edit"
class="ml-1 py-1 px-2 flex justify-center items-center bg-violet-600 hover:bg-violet-700 focus:ring-violet-500 focus:ring-offset-violet-200 text-white transition ease-in duration-200 text-center text-base font-semibold shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 w-7 h-4 rounded-lg">
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-5 h-5">
<path d="M5.433 13.917l1.262-3.155A4 4 0 017.58 9.42l6.92-6.918a2.121 2.121 0 013 3l-6.92 6.918c-.383.383-.84.685-1.343.886l-3.154 1.262a.5.5 0 01-.65-.65z" />
<path d="M3.5 5.75c0-.69.56-1.25 1.25-1.25H10A.75.75 0 0010 3H4.75A2.75 2.75 0 002 5.75v9.5A2.75 2.75 0 004.75 18h9.5A2.75 2.75 0 0017 15.25V10a.75.75 0 00-1.5 0v5.25c0 .69-.56 1.25-1.25 1.25h-9.5c-.69 0-1.25-.56-1.25-1.25v-9.5z" />
</svg>
</button>
</a>

View File

@ -1,15 +0,0 @@
{% fragment as default_content %}
{% 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>
{% else %}
{% #table_td %}
{{ td }}
{% /table_td %}
{% endif %}
{% endfor %}
{% endfragment %}
<tr class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 border-b">
{{ children|default:default_content }}
</tr>

View File

@ -1 +0,0 @@
<td class="px-6 py-4 min-w-20-char max-w-20-char">{{ children }}</td>

View File

@ -0,0 +1,4 @@
<button type="button"
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 mt-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">
{{ text }}
</button>

View File

@ -1,4 +1,4 @@
{% var color=color|default:"gray" %} <c-vars color="gray" />
<a href="{{ href }}" <a href="{{ href }}"
class="[&:first-of-type_button]:rounded-s-lg [&:last-of-type_button]:rounded-e-lg"> class="[&:first-of-type_button]:rounded-s-lg [&:last-of-type_button]:rounded-e-lg">
{% if color == "gray" %} {% if color == "gray" %}

View File

@ -0,0 +1,6 @@
<c-vars color="gray" />
<div class="inline-flex rounded-md shadow-sm" role="group">
{% for button in buttons %}
<c-button-group-button-sm :href=button.href :text=button.text :color=button.color />
{% endfor %}
</div>

View File

@ -1,8 +1,8 @@
<span class="truncate-container"> <span class="truncate-container">
<a class="underline decoration-slate-500 sm:decoration-2" <a class="underline decoration-slate-500 sm:decoration-2"
href="{% url 'view_game' game_id %}"> href="{% url 'view_game' game_id %}">
{% if children %} {% if slot %}
{{ children }} {{ slot }}
{% else %} {% else %}
{{ name }} {{ name }}
{% endif %} {% endif %}

View File

@ -1,5 +1,5 @@
<h1 class="{% if badge %}flex items-center {% endif %}mb-4 text-3xl font-extrabold leading-none tracking-tight text-gray-900 dark:text-white"> <h1 class="{% if badge %}flex items-center {% endif %}mb-4 text-3xl font-extrabold leading-none tracking-tight text-gray-900 dark:text-white">
{{ children }} {{ slot }}
{% if badge %} {% if badge %}
<span class="bg-blue-100 text-blue-800 text-2xl font-semibold me-2 px-2.5 py-0.5 rounded dark:bg-blue-200 dark:text-blue-800 ms-2"> <span class="bg-blue-100 text-blue-800 text-2xl font-semibold me-2 px-2.5 py-0.5 rounded dark:bg-blue-200 dark:text-blue-800 ms-2">
{{ badge }} {{ badge }}

View File

@ -2,6 +2,6 @@
id="{{ id }}" id="{{ id }}"
role="tooltip" role="tooltip"
class="absolute z-10 invisible inline-block text-sm text-white transition-opacity duration-300 bg-white border border-purple-200 rounded-lg shadow-sm opacity-0 dark:text-white dark:border-purple-600 dark:bg-purple-800"> class="absolute z-10 invisible inline-block text-sm text-white transition-opacity duration-300 bg-white border border-purple-200 rounded-lg shadow-sm opacity-0 dark:text-white dark:border-purple-600 dark:bg-purple-800">
<div class="px-3 py-2">{{ children }}</div> <div class="px-3 py-2">{{ slot }}</div>
<div data-popper-arrow></div> <div data-popper-arrow></div>
</div> </div>

View File

@ -1,3 +1,4 @@
{% load param_utils %}
<div class="shadow-md sm:rounded-lg" hx-boost="false"> <div class="shadow-md sm:rounded-lg" hx-boost="false">
<div class="relative overflow-x-auto sm:rounded-lg"> <div class="relative overflow-x-auto sm:rounded-lg">
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400"> <table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
@ -7,9 +8,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for row in rows %} {% for row in rows %}<c-table-row :data=row />{% endfor %}
{% table_row data=row %}
{% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>
@ -20,7 +19,7 @@
<ul class="inline-flex -space-x-px rtl:space-x-reverse text-sm h-8"> <ul class="inline-flex -space-x-px rtl:space-x-reverse text-sm h-8">
<li> <li>
{% if page_obj.has_previous %} {% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}" <a href="?{% param_replace page=page_obj.previous_page_number %}"
class="flex items-center justify-center px-3 h-8 ms-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-s-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">Previous</a> class="flex items-center justify-center px-3 h-8 ms-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-s-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">Previous</a>
{% else %} {% else %}
<a aria-current="page" <a aria-current="page"
@ -29,7 +28,7 @@
{% for page in elided_page_range %} {% for page in elided_page_range %}
<li> <li>
{% if page != page_obj.number %} {% if page != page_obj.number %}
<a href="?page={{ page }}" <a href="?{% param_replace page=page %}"
class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">{{ page }}</a> class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">{{ page }}</a>
{% else %} {% else %}
<a aria-current="page" <a aria-current="page"
@ -38,7 +37,7 @@
</li> </li>
{% endfor %} {% endfor %}
{% if page_obj.has_next %} {% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}" <a href="?{% param_replace page=page_obj.next_page_number %}"
class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 rounded-e-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">Next</a> class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 rounded-e-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">Next</a>
{% else %} {% else %}
<a aria-current="page" <a aria-current="page"

View File

@ -6,7 +6,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{ children }} {{ slot }}
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -0,0 +1,16 @@
<tr class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 border-b">
{% if slot %}
{{ slot }}
{% 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>
{% else %}
<c-table-td>
{{ td }}
</c-table-td>
{% endif %}
{% endfor %}
{% endif %}
</tr>

View File

@ -0,0 +1 @@
<td class="px-6 py-4 min-w-20-char max-w-20-char">{{ slot }}</td>

View File

@ -5,6 +5,6 @@
{% endblock title %} {% endblock title %}
{% block content %} {% block content %}
<div class="2xl:max-w-screen-2xl md:max-w-screen-md sm:max-w-screen-sm self-center"> <div class="2xl:max-w-screen-2xl md:max-w-screen-md sm:max-w-screen-sm self-center">
{% simple_table columns=data.columns rows=data.rows page_obj=page_obj elided_page_range=elided_page_range %} <c-simple-table :columns=data.columns :rows=data.rows :page_obj=page_obj :elided_page_range=elided_page_range />
</div> </div>
{% endblock content %} {% endblock content %}

View File

@ -5,11 +5,11 @@
{% load static %} {% load static %}
{% partialdef purchase-name %} {% partialdef purchase-name %}
{% if purchase.type != 'game' %} {% if purchase.type != 'game' %}
{% #gamelink game_id=purchase.edition.game.id %} <c-gamelink :game_id=purchase.edition.game.id>
{{ purchase.name }} ({{ purchase.edition.name }} {{ purchase.get_type_display }}) {{ purchase.name }} ({{ purchase.edition.name }} {{ purchase.get_type_display }})
{% /gamelink %} </c-gamelink>
{% else %} {% else %}
{% gamelink game_id=purchase.edition.game.id name=purchase.edition.name %} <c-gamelink :game_id=purchase.edition.game.id name=purchase.edition.name />
{% endif %} {% endif %}
{% endpartialdef %} {% endpartialdef %}
{% block content %} {% block content %}
@ -65,31 +65,31 @@
<tr> <tr>
<td class="px-2 sm:px-4 md:px-6 md:py-2">Longest session</td> <td class="px-2 sm:px-4 md:px-6 md:py-2">Longest session</td>
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono"> <td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">
{{ longest_session_time }} ({% gamelink game_id=longest_session_game.id name=longest_session_game.name %}) {{ longest_session_time }} (<c-gamelink :game_id=longest_session_game.id :name=longest_session_game.name />)
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="px-2 sm:px-4 md:px-6 md:py-2">Most sessions</td> <td class="px-2 sm:px-4 md:px-6 md:py-2">Most sessions</td>
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono"> <td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">
{{ highest_session_count }} ({% gamelink game_id=highest_session_count_game.id name=highest_session_count_game.name %}) {{ highest_session_count }} (<c-gamelink :game_id=highest_session_count_game.id :name=highest_session_count_game.name />)
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="px-2 sm:px-4 md:px-6 md:py-2">Highest session average</td> <td class="px-2 sm:px-4 md:px-6 md:py-2">Highest session average</td>
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono"> <td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">
{{ highest_session_average }} ({% gamelink game_id=highest_session_average_game.id name=highest_session_average_game.name %}) {{ highest_session_average }} (<c-gamelink :game_id=highest_session_average_game.id :name=highest_session_average_game.name />)
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="px-2 sm:px-4 md:px-6 md:py-2">First play</td> <td class="px-2 sm:px-4 md:px-6 md:py-2">First play</td>
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono"> <td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">
{% gamelink game_id=first_play_game.id name=first_play_game.name %} ({{ first_play_date }}) <c-gamelink :game_id=first_play_game.id :name=first_play_game.name /> ({{ first_play_date }})
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="px-2 sm:px-4 md:px-6 md:py-2">Last play</td> <td class="px-2 sm:px-4 md:px-6 md:py-2">Last play</td>
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono"> <td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">
{% gamelink game_id=last_play_game.id name=last_play_game.name %} ({{ last_play_date }}) <c-gamelink :game_id=last_play_game.id :name=last_play_game.name /> ({{ last_play_date }})
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -151,7 +151,9 @@
<tbody> <tbody>
{% for game in top_10_games_by_playtime %} {% for game in top_10_games_by_playtime %}
<tr> <tr>
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">{% gamelink game_id=game.id name=game.name %}</td> <td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">
<c-gamelink :game_id=game.id :name=game.name />
</td>
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">{{ game.formatted_playtime }}</td> <td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono">{{ game.formatted_playtime }}</td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -10,9 +10,9 @@
<div class="flex gap-5 mb-3"> <div class="flex gap-5 mb-3">
<span class="text-wrap max-w-80 text-4xl"> <span class="text-wrap max-w-80 text-4xl">
<span class="font-bold font-serif">{{ game.name }}</span>&nbsp;<span data-popover-target="popover-year" class="text-slate-500 text-2xl">{{ game.year_released }}</span> <span class="font-bold font-serif">{{ game.name }}</span>&nbsp;<span data-popover-target="popover-year" class="text-slate-500 text-2xl">{{ game.year_released }}</span>
{% #popover id="popover-year" %} <c-popover id="popover-year">
Original release year Original release year
{% /popover %} </c-popover>
</span> </span>
</div> </div>
<div class="flex gap-4 dark:text-slate-400 mb-3"> <div class="flex gap-4 dark:text-slate-400 mb-3">
@ -26,9 +26,9 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
</svg> </svg>
{{ hours_sum }} {{ hours_sum }}
{% #popover id="popover-hours" %} <c-popover id="popover-hours">
Total hours played Total hours played
{% /popover %} </c-popover>
</span> </span>
<span data-popover-target="popover-sessions" <span data-popover-target="popover-sessions"
class="flex gap-2 items-center"> class="flex gap-2 items-center">
@ -41,9 +41,9 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M5.25 8.25h15m-16.5 7.5h15m-1.8-13.5-3.9 19.5m-2.1-19.5-3.9 19.5" /> <path stroke-linecap="round" stroke-linejoin="round" d="M5.25 8.25h15m-16.5 7.5h15m-1.8-13.5-3.9 19.5m-2.1-19.5-3.9 19.5" />
</svg> </svg>
{{ session_count }} {{ session_count }}
{% #popover id="popover-sessions" %} <c-popover id="popover-sessions">
Number of sessions Number of sessions
{% /popover %} </c-popover>
</span> </span>
<span data-popover-target="popover-average" class="flex gap-2 items-center"> <span data-popover-target="popover-average" class="flex gap-2 items-center">
<svg xmlns="http://www.w3.org/2000/svg" <svg xmlns="http://www.w3.org/2000/svg"
@ -55,9 +55,9 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M7.5 14.25v2.25m3-4.5v4.5m3-6.75v6.75m3-9v9M6 20.25h12A2.25 2.25 0 0 0 20.25 18V6A2.25 2.25 0 0 0 18 3.75H6A2.25 2.25 0 0 0 3.75 6v12A2.25 2.25 0 0 0 6 20.25Z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M7.5 14.25v2.25m3-4.5v4.5m3-6.75v6.75m3-9v9M6 20.25h12A2.25 2.25 0 0 0 20.25 18V6A2.25 2.25 0 0 0 18 3.75H6A2.25 2.25 0 0 0 3.75 6v12A2.25 2.25 0 0 0 6 20.25Z" />
</svg> </svg>
{{ session_average_without_manual }} {{ session_average_without_manual }}
{% #popover id="popover-average" %} <c-popover id="popover-average">
Average playtime per session Average playtime per session
{% /popover %} </c-popover>
</span> </span>
<span data-popover-target="popover-playrange" <span data-popover-target="popover-playrange"
class="flex gap-2 items-center"> class="flex gap-2 items-center">
@ -70,9 +70,9 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5m-9-6h.008v.008H12v-.008ZM12 15h.008v.008H12V15Zm0 2.25h.008v.008H12v-.008ZM9.75 15h.008v.008H9.75V15Zm0 2.25h.008v.008H9.75v-.008ZM7.5 15h.008v.008H7.5V15Zm0 2.25h.008v.008H7.5v-.008Zm6.75-4.5h.008v.008h-.008v-.008Zm0 2.25h.008v.008h-.008V15Zm0 2.25h.008v.008h-.008v-.008Zm2.25-4.5h.008v.008H16.5v-.008Zm0 2.25h.008v.008H16.5V15Z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5m-9-6h.008v.008H12v-.008ZM12 15h.008v.008H12V15Zm0 2.25h.008v.008H12v-.008ZM9.75 15h.008v.008H9.75V15Zm0 2.25h.008v.008H9.75v-.008ZM7.5 15h.008v.008H7.5V15Zm0 2.25h.008v.008H7.5v-.008Zm6.75-4.5h.008v.008h-.008v-.008Zm0 2.25h.008v.008h-.008V15Zm0 2.25h.008v.008h-.008v-.008Zm2.25-4.5h.008v.008H16.5v-.008Zm0 2.25h.008v.008H16.5V15Z" />
</svg> </svg>
{{ playrange }} {{ playrange }}
{% #popover id="popover-playrange" %} <c-popover id="popover-playrange">
Earliest and latest dates played Earliest and latest dates played
{% /popover %} </c-popover>
</span> </span>
</div> </div>
<div class="inline-flex rounded-md shadow-sm mb-3" role="group"> <div class="inline-flex rounded-md shadow-sm mb-3" role="group">
@ -90,15 +90,17 @@
</a> </a>
</div> </div>
</div> </div>
{% #h1 badge=edition_count %}Editions{% /h1 %} <c-h1 :badge=edition_count>Editions</c-h1>
<div class="mb-6">{% simple_table rows=edition_data.rows columns=edition_data.columns %}</div>
<div class="mb-6"> <div class="mb-6">
{% #h1 badge=purchase_count %}Purchases{% /h1 %} <c-simple-table :rows=edition_data.rows :columns=edition_data.columns />
{% simple_table rows=purchase_data.rows columns=purchase_data.columns %}
</div> </div>
<div class="mb-6"> <div class="mb-6">
{% #h1 badge=session_count %}Sessions{% /h1 %} <c-h1 :badge=purchase_count>Purchases</c-h1>
{% simple_table rows=session_data.rows columns=session_data.columns page_obj=session_page_obj elided_page_range=session_elided_page_range %} <c-simple-table :rows=purchase_data.rows :columns=purchase_data.columns />
</div>
<div class="mb-6">
<c-h1 :badge=session_count>Sessions</c-h1>
<c-simple-table :rows=session_data.rows :columns=session_data.columns :page_obj=session_page_obj :elided_page_range=session_elided_page_range />
</div> </div>
</div> </div>
<script> <script>

View File

@ -0,0 +1,18 @@
from typing import Any
from django import template
from django.http import QueryDict
register = template.Library()
@register.simple_tag(takes_context=True)
def param_replace(context: dict[Any, Any], **kwargs):
"""
Return encoded URL parameters that are the same as the current
request's parameters, only with the specified GET parameters added or changed.
"""
d: QueryDict = context["request"].GET.copy()
for k, v in kwargs.items():
d[k] = v
return d.urlencode()

View File

@ -47,12 +47,13 @@ def list_devices(request: HttpRequest) -> HttpResponse:
device.get_type_display(), device.get_type_display(),
device.created_at.strftime(dateformat), device.created_at.strftime(dateformat),
render_to_string( render_to_string(
"components/button_group_sm.html", "cotton/button_group_sm.html",
{ {
"buttons": [ "buttons": [
{ {
"href": reverse("edit_device", args=[device.pk]), "href": reverse("edit_device", args=[device.pk]),
"text": "Edit", "text": "Edit",
"color": "gray",
}, },
{ {
"href": reverse("delete_device", args=[device.pk]), "href": reverse("delete_device", args=[device.pk]),

View File

@ -65,12 +65,13 @@ def list_editions(request: HttpRequest) -> HttpResponse:
edition.wikidata, edition.wikidata,
edition.created_at.strftime(dateformat), edition.created_at.strftime(dateformat),
render_to_string( render_to_string(
"components/button_group_sm.html", "cotton/button_group_sm.html",
{ {
"buttons": [ "buttons": [
{ {
"href": reverse("edit_edition", args=[edition.pk]), "href": reverse("edit_edition", args=[edition.pk]),
"text": "Edit", "text": "Edit",
"color": "gray",
}, },
{ {
"href": reverse( "href": reverse(

View File

@ -65,12 +65,13 @@ def list_games(request: HttpRequest) -> HttpResponse:
game.wikidata, game.wikidata,
game.created_at.strftime(dateformat), game.created_at.strftime(dateformat),
render_to_string( render_to_string(
"components/button_group_sm.html", "cotton/button_group_sm.html",
{ {
"buttons": [ "buttons": [
{ {
"href": reverse("edit_game", args=[game.pk]), "href": reverse("edit_game", args=[game.pk]),
"text": "Edit", "text": "Edit",
"color": "gray",
}, },
{ {
"href": reverse("delete_game", args=[game.pk]), "href": reverse("delete_game", args=[game.pk]),
@ -193,12 +194,13 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
edition.platform, edition.platform,
edition.year_released, edition.year_released,
render_to_string( render_to_string(
"components/button_group_sm.html", "cotton/button_group_sm.html",
{ {
"buttons": [ "buttons": [
{ {
"href": reverse("edit_edition", args=[edition.pk]), "href": reverse("edit_edition", args=[edition.pk]),
"text": "Edit", "text": "Edit",
"color": "gray",
}, },
{ {
"href": reverse("delete_edition", args=[edition.pk]), "href": reverse("delete_edition", args=[edition.pk]),
@ -221,12 +223,13 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
purchase.get_type_display(), purchase.get_type_display(),
f"{purchase.price} {purchase.price_currency}", f"{purchase.price} {purchase.price_currency}",
render_to_string( render_to_string(
"components/button_group_sm.html", "cotton/button_group_sm.html",
{ {
"buttons": [ "buttons": [
{ {
"href": reverse("edit_purchase", args=[purchase.pk]), "href": reverse("edit_purchase", args=[purchase.pk]),
"text": "Edit", "text": "Edit",
"color": "gray",
}, },
{ {
"href": reverse("delete_purchase", args=[purchase.pk]), "href": reverse("delete_purchase", args=[purchase.pk]),
@ -266,12 +269,13 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
else "-" else "-"
), ),
render_to_string( render_to_string(
"components/button_group_sm.html", "cotton/button_group_sm.html",
{ {
"buttons": [ "buttons": [
{ {
"href": reverse("edit_session", args=[session.pk]), "href": reverse("edit_session", args=[session.pk]),
"text": "Edit", "text": "Edit",
"color": "gray",
}, },
{ {
"href": reverse("delete_session", args=[session.pk]), "href": reverse("delete_session", args=[session.pk]),

View File

@ -47,7 +47,7 @@ def list_platforms(request: HttpRequest) -> HttpResponse:
platform.group, platform.group,
platform.created_at.strftime(dateformat), platform.created_at.strftime(dateformat),
render_to_string( render_to_string(
"components/button_group_sm.html", "cotton/button_group_sm.html",
{ {
"buttons": [ "buttons": [
{ {
@ -55,6 +55,7 @@ def list_platforms(request: HttpRequest) -> HttpResponse:
"edit_platform", args=[platform.pk] "edit_platform", args=[platform.pk]
), ),
"text": "Edit", "text": "Edit",
"color": "gray",
}, },
{ {
"href": reverse( "href": reverse(

View File

@ -80,7 +80,7 @@ def list_purchases(request: HttpRequest) -> HttpResponse:
), ),
purchase.created_at.strftime(dateformat), purchase.created_at.strftime(dateformat),
render_to_string( render_to_string(
"components/button_group_sm.html", "cotton/button_group_sm.html",
{ {
"buttons": [ "buttons": [
{ {
@ -88,6 +88,7 @@ def list_purchases(request: HttpRequest) -> HttpResponse:
"edit_purchase", args=[purchase.pk] "edit_purchase", args=[purchase.pk]
), ),
"text": "Edit", "text": "Edit",
"color": "gray",
}, },
{ {
"href": reverse( "href": reverse(

View File

@ -71,12 +71,13 @@ def list_sessions(request: HttpRequest) -> HttpResponse:
session.device, session.device,
session.created_at.strftime(dateformat), session.created_at.strftime(dateformat),
render_to_string( render_to_string(
"components/button_group_sm.html", "cotton/button_group_sm.html",
{ {
"buttons": [ "buttons": [
{ {
"href": reverse("edit_session", args=[session.pk]), "href": reverse("edit_session", args=[session.pk]),
"text": "Edit", "text": "Edit",
"color": "gray",
}, },
{ {
"href": reverse( "href": reverse(

70
poetry.lock generated
View File

@ -28,6 +28,27 @@ files = [
[package.extras] [package.extras]
tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"]
[[package]]
name = "beautifulsoup4"
version = "4.12.3"
description = "Screen-scraping library"
optional = false
python-versions = ">=3.6.0"
files = [
{file = "beautifulsoup4-4.12.3-py3-none-any.whl", hash = "sha256:b80878c9f40111313e55da8ba20bdba06d8fa3969fc68304167741bbf9e082ed"},
{file = "beautifulsoup4-4.12.3.tar.gz", hash = "sha256:74e3d1928edc070d21748185c46e3fb33490f22f52a3addee9aee0f4f7781051"},
]
[package.dependencies]
soupsieve = ">1.2"
[package.extras]
cchardet = ["cchardet"]
chardet = ["chardet"]
charset-normalizer = ["charset-normalizer"]
html5lib = ["html5lib"]
lxml = ["lxml"]
[[package]] [[package]]
name = "cfgv" name = "cfgv"
version = "3.4.0" version = "3.4.0"
@ -110,6 +131,20 @@ tzdata = {version = "*", markers = "sys_platform == \"win32\""}
argon2 = ["argon2-cffi (>=19.1.0)"] argon2 = ["argon2-cffi (>=19.1.0)"]
bcrypt = ["bcrypt"] bcrypt = ["bcrypt"]
[[package]]
name = "django-cotton"
version = "0.9.34"
description = "Bringing component based design to Django templates."
optional = false
python-versions = "<4,>=3.8"
files = [
{file = "django_cotton-0.9.34-py3-none-any.whl", hash = "sha256:9721dd79066d5a28eefb84527bea7f2daa8f1db6111ffdecbc5dd64fe2e300c9"},
{file = "django_cotton-0.9.34.tar.gz", hash = "sha256:3f2d950a9ad0985955ca0fb2d5fbb42be1f07f55239864fe5a1d0e873303f0bd"},
]
[package.dependencies]
beautifulsoup4 = ">=4.12.2,<4.13.0"
[[package]] [[package]]
name = "django-debug-toolbar" name = "django-debug-toolbar"
version = "4.4.6" version = "4.4.6"
@ -788,22 +823,16 @@ files = [
] ]
[[package]] [[package]]
name = "slippers" name = "soupsieve"
version = "0.6.2" version = "2.6"
description = "Build reusable components in Django without writing a single line of Python." description = "A modern CSS selector implementation for Beautiful Soup."
optional = false optional = false
python-versions = ">=3.8.0" python-versions = ">=3.8"
files = [ files = [
{file = "slippers-0.6.2-py3-none-any.whl", hash = "sha256:739e05f85354becbf0a65daab831eea62557d89e7512042209ab629af4378bca"}, {file = "soupsieve-2.6-py3-none-any.whl", hash = "sha256:e72c4ff06e4fb6e4b5a9f0f55fe6e81514581fca1515028625d0f299c602ccc9"},
{file = "slippers-0.6.2.tar.gz", hash = "sha256:4cb555b8822ba0d404e5405723f5d723994022c29046008ee917081031bc0cf1"}, {file = "soupsieve-2.6.tar.gz", hash = "sha256:e2e68417777af359ec65daac1057404a3c8a5455bb8abc36f1a9866ab1a51abb"},
] ]
[package.dependencies]
Django = ">=3.2"
PyYAML = ">=5.4.0"
typeguard = ">=2.13.3,<3.0.0"
typing-extensions = ">=4.4.0"
[[package]] [[package]]
name = "sqlparse" name = "sqlparse"
version = "0.5.1" version = "0.5.1"
@ -850,21 +879,6 @@ notebook = ["ipywidgets (>=6)"]
slack = ["slack-sdk"] slack = ["slack-sdk"]
telegram = ["requests"] telegram = ["requests"]
[[package]]
name = "typeguard"
version = "2.13.3"
description = "Run-time type checker for Python"
optional = false
python-versions = ">=3.5.3"
files = [
{file = "typeguard-2.13.3-py3-none-any.whl", hash = "sha256:5e3e3be01e887e7eafae5af63d1f36c849aaa94e3a0112097312aabfa16284f1"},
{file = "typeguard-2.13.3.tar.gz", hash = "sha256:00edaa8da3a133674796cf5ea87d9f4b4c367d77476e185e80251cc13dfbb8c4"},
]
[package.extras]
doc = ["sphinx-autodoc-typehints (>=1.2.0)", "sphinx-rtd-theme"]
test = ["mypy", "pytest", "typing-extensions"]
[[package]] [[package]]
name = "typing-extensions" name = "typing-extensions"
version = "4.12.2" version = "4.12.2"
@ -928,4 +942,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.11" python-versions = "^3.11"
content-hash = "eb741020e400664070ed1eee24a17b6a9c07a2f2d44103e4947279aa26a40315" content-hash = "f96f55c381f25a4a473be8d53ef83d13c70bb7c731b5132f4ece2af1b3d3afed"

View File

@ -30,7 +30,7 @@ django-template-partials = "^24.2"
markdown = "^3.6" markdown = "^3.6"
slippers = "^0.6.2" django-cotton = "^0.9.34"
[tool.isort] [tool.isort]
profile = "black" profile = "black"

View File

@ -41,7 +41,7 @@ INSTALLED_APPS = [
"template_partials", "template_partials",
"graphene_django", "graphene_django",
"django_htmx", "django_htmx",
"slippers", "django_cotton",
] ]
GRAPHENE = {"SCHEMA": "games.schema.schema"} GRAPHENE = {"SCHEMA": "games.schema.schema"}
@ -87,7 +87,6 @@ TEMPLATES = [
], ],
"builtins": [ "builtins": [
"template_partials.templatetags.partials", "template_partials.templatetags.partials",
"slippers.templatetags.slippers",
], ],
}, },
}, },