Compare commits
No commits in common. "f61cde180ff8d01cc18c9c2f6c146c412dd3ea3d" and "c6b1badf3911f6fdfe8b09712cb42e60e82c9394" have entirely different histories.
f61cde180f
...
c6b1badf39
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 5.1.2 on 2024-11-09 22:38
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('games', '0038_alter_purchase_price'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='device',
|
|
||||||
name='type',
|
|
||||||
field=models.CharField(choices=[('PC', 'PC'), ('Console', 'Console'), ('Handheld', 'Handheld'), ('Mobile', 'Mobile'), ('Single-board computer', 'Single-board computer'), ('Unknown', 'Unknown')], default='Unknown', max_length=255),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,33 +0,0 @@
|
||||||
# Generated by Django 5.1.2 on 2024-11-09 22:39
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
def update_device_types(apps, schema_editor):
|
|
||||||
Device = apps.get_model("games", "Device")
|
|
||||||
|
|
||||||
# Mapping of short names to long names
|
|
||||||
type_map = {
|
|
||||||
"pc": "PC",
|
|
||||||
"co": "Console",
|
|
||||||
"ha": "Handheld",
|
|
||||||
"mo": "Mobile",
|
|
||||||
"sbc": "Single-board computer",
|
|
||||||
"un": "Unknown",
|
|
||||||
}
|
|
||||||
|
|
||||||
# Loop through all devices and update the type field
|
|
||||||
for device in Device.objects.all():
|
|
||||||
if device.type in type_map:
|
|
||||||
device.type = type_map[device.type]
|
|
||||||
device.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
dependencies = [
|
|
||||||
("games", "0039_alter_device_type"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RunPython(update_device_types),
|
|
||||||
]
|
|
|
@ -259,12 +259,12 @@ class Session(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Device(models.Model):
|
class Device(models.Model):
|
||||||
PC = "PC"
|
PC = "pc"
|
||||||
CONSOLE = "Console"
|
CONSOLE = "co"
|
||||||
HANDHELD = "Handheld"
|
HANDHELD = "ha"
|
||||||
MOBILE = "Mobile"
|
MOBILE = "mo"
|
||||||
SBC = "Single-board computer"
|
SBC = "sbc"
|
||||||
UNKNOWN = "Unknown"
|
UNKNOWN = "un"
|
||||||
DEVICE_TYPES = [
|
DEVICE_TYPES = [
|
||||||
(PC, "PC"),
|
(PC, "PC"),
|
||||||
(CONSOLE, "Console"),
|
(CONSOLE, "Console"),
|
||||||
|
@ -274,8 +274,8 @@ class Device(models.Model):
|
||||||
(UNKNOWN, "Unknown"),
|
(UNKNOWN, "Unknown"),
|
||||||
]
|
]
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
type = models.CharField(max_length=255, choices=DEVICE_TYPES, default=UNKNOWN)
|
type = models.CharField(max_length=3, choices=DEVICE_TYPES, default=UNKNOWN)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name} ({self.type})"
|
return f"{self.name} ({self.get_type_display()})"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<c-vars :name="id" />
|
<c-vars placeholder="Search" :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>
|
<label for="table-search" class="sr-only">Search</label>
|
||||||
<div class="relative mt-1">
|
<div class="relative mt-1">
|
||||||
|
@ -7,6 +7,6 @@
|
||||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z"/>
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z"/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</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 %}">
|
<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="{{ placeholder }}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -2,7 +2,6 @@ from typing import Any
|
||||||
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.db.models import Q
|
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
@ -40,13 +39,7 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||||
sessions = Session.objects.order_by("-timestamp_start")
|
sessions = Session.objects.order_by("-timestamp_start")
|
||||||
search_string = request.GET.get("search_string", search_string)
|
search_string = request.GET.get("search_string", search_string)
|
||||||
if search_string != "":
|
if search_string != "":
|
||||||
sessions = sessions.filter(
|
sessions = sessions.filter(purchase__edition__name__icontains=search_string)
|
||||||
Q(purchase__edition__name__icontains=search_string)
|
|
||||||
| Q(purchase__edition__game__name__icontains=search_string)
|
|
||||||
| Q(purchase__platform__name__icontains=search_string)
|
|
||||||
| Q(device__name__icontains=search_string)
|
|
||||||
| Q(device__type__icontains=search_string)
|
|
||||||
)
|
|
||||||
last_session = sessions.latest()
|
last_session = sessions.latest()
|
||||||
page_obj = None
|
page_obj = None
|
||||||
if int(limit) != 0:
|
if int(limit) != 0:
|
||||||
|
@ -70,11 +63,7 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
||||||
Form(
|
Form(
|
||||||
children=[
|
children=[
|
||||||
render_to_string(
|
render_to_string(
|
||||||
"cotton/search_field.html",
|
"cotton/search_field.html", {"id": "search_string"}
|
||||||
{
|
|
||||||
"id": "search_string",
|
|
||||||
"search_string": search_string,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue