Compare commits
4 Commits
c6b1badf39
...
f61cde180f
Author | SHA1 | Date |
---|---|---|
Lukáš Kucharczyk | f61cde180f | |
Lukáš Kucharczyk | a53818257c | |
Lukáš Kucharczyk | 2d3ea714c4 | |
Lukáš Kucharczyk | 832bb48983 |
|
@ -0,0 +1,18 @@
|
|||
# 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),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,33 @@
|
|||
# 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):
|
||||
PC = "pc"
|
||||
CONSOLE = "co"
|
||||
HANDHELD = "ha"
|
||||
MOBILE = "mo"
|
||||
SBC = "sbc"
|
||||
UNKNOWN = "un"
|
||||
PC = "PC"
|
||||
CONSOLE = "Console"
|
||||
HANDHELD = "Handheld"
|
||||
MOBILE = "Mobile"
|
||||
SBC = "Single-board computer"
|
||||
UNKNOWN = "Unknown"
|
||||
DEVICE_TYPES = [
|
||||
(PC, "PC"),
|
||||
(CONSOLE, "Console"),
|
||||
|
@ -274,8 +274,8 @@ class Device(models.Model):
|
|||
(UNKNOWN, "Unknown"),
|
||||
]
|
||||
name = models.CharField(max_length=255)
|
||||
type = models.CharField(max_length=3, choices=DEVICE_TYPES, default=UNKNOWN)
|
||||
type = models.CharField(max_length=255, choices=DEVICE_TYPES, default=UNKNOWN)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.get_type_display()})"
|
||||
return f"{self.name} ({self.type})"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<c-vars placeholder="Search" :name="id" />
|
||||
<c-vars :name="id" />
|
||||
<div class="pb-4 bg-white dark:bg-gray-900">
|
||||
<label for="table-search" class="sr-only">Search</label>
|
||||
<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"/>
|
||||
</svg>
|
||||
</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="{{ placeholder }}">
|
||||
<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>
|
|
@ -2,6 +2,7 @@ from typing import Any
|
|||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models import Q
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.template.loader import render_to_string
|
||||
|
@ -39,7 +40,13 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
|||
sessions = Session.objects.order_by("-timestamp_start")
|
||||
search_string = request.GET.get("search_string", search_string)
|
||||
if search_string != "":
|
||||
sessions = sessions.filter(purchase__edition__name__icontains=search_string)
|
||||
sessions = sessions.filter(
|
||||
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()
|
||||
page_obj = None
|
||||
if int(limit) != 0:
|
||||
|
@ -63,7 +70,11 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
|
|||
Form(
|
||||
children=[
|
||||
render_to_string(
|
||||
"cotton/search_field.html", {"id": "search_string"}
|
||||
"cotton/search_field.html",
|
||||
{
|
||||
"id": "search_string",
|
||||
"search_string": search_string,
|
||||
},
|
||||
)
|
||||
]
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue