screen model with search to fix

This commit is contained in:
d0c 2023-02-05 17:42:15 +01:00
parent 2ccf6c0cd3
commit e2c79cf698
4 changed files with 65 additions and 4 deletions

View file

@ -1,6 +1,6 @@
from django.contrib import admin
from suitablephones.models import Bluetooth, Camera, Device
from suitablephones.models import Bluetooth, Camera, Device, Screen
@admin.register(Camera)
@ -16,3 +16,7 @@ class AdminBluetooth(admin.ModelAdmin):
@admin.register(Device)
class AdminDevice(admin.ModelAdmin):
pass
@admin.register(Screen)
class AdminScreen(admin.ModelAdmin):
pass

View file

@ -4,10 +4,39 @@ import yaml
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from suitablephones.models import Bluetooth, Camera, Device
from suitablephones.models import Bluetooth, Camera, Device, Screen
import subprocess
import logging
def update_repo():
devicesdir = settings.LINEAGEWIKI
pull_status = subprocess.run(["git", "pull"], cwd=devicesdir)
if pull_status.returncode != 0:
logging.error("Error pulling repo")
def set_screen(args):
#if type(args)
screen = Screen.objects.filter(**args)
if not screen.exists():
screen = Screen()
for subkey, subvalue in args.items():
if subkey == 'size':
size_mm = subvalue.split(' ')[0]
setattr(screen, 'size_mm', size_mm)
size_inch = subvalue.split(' ')[2].replace('(', '')
setattr(screen, 'size_in', size_inch)
setattr(screen, subkey, subvalue)
#elif subkey == 'technology':
# setattr(screen, 'type', subvalue)
setattr(screen, subkey, subvalue)
screen.save()
else:
screen = screen.get()
return screen
def set_camera(args):
cam = Camera.objects.filter(**args)
if not cam.exists():
@ -36,12 +65,14 @@ class Command(BaseCommand):
Device.objects.all().delete()
Bluetooth.objects.all().delete()
Camera.objects.all().delete()
update_repo()
devicesdir = settings.LINEAGEWIKI + "/_data/devices/"
# import pdb; pdb.set_trace()
for filename in os.listdir(devicesdir):
dev = Device()
cameras = []
bluetooth = {}
screen = []
peripherals = []
with open(os.path.join(devicesdir, filename), "r") as stream:
@ -84,6 +115,13 @@ class Command(BaseCommand):
elif key == "storage":
if str(value) == "None":
value = None
elif key == "screen":
if type(value) is list:
for s in value:
for k,v in s.items():
screen.append(set_screen(v))
elif type(value) is dict:
screen.append(set_screen(value))
else:
setattr(dev, key, value)
except yaml.YAMLError as exc:

View file

@ -22,6 +22,16 @@ class Camera(models.Model):
def __str__(self):
return f" {self.flash} - {str(self.megapixel)} - {self.info}"
class Screen(models.Model):
size = models.CharField(max_length=500, null=True)
size_mm = models.DecimalField(max_digits=5, decimal_places=1)
size_in = models.DecimalField(max_digits=5, decimal_places=1)
resolution = models.CharField(max_length=100)
density = models.CharField(max_length=100)
technology = models.CharField(max_length=100)
def __str__(self):
return f"{self.size_in} - {self.density} - {self.technology}"
class Device(models.Model):
#architecture = models.JSONField(default=dict)
@ -51,7 +61,7 @@ class Device(models.Model):
recovery_boot = models.CharField(max_length=1000)
recovery_reboot = models.CharField(max_length=100)
#release = models.DateField()
#screen = models.JSONField(default=dict) # dict or str
screen = models.ManyToManyField(Screen)
#sdcard = models.JSONField(default=dict) # dict or str{1}
soc = models.CharField(max_length=1000)
storage = models.CharField(max_length=100, blank=True)

View file

@ -17,6 +17,9 @@ class DeviceViewSet(viewsets.ModelViewSet):
def get_queryset(self):
name = self.request.query_params.get('name')
megapixel = self.request.query_params.get('megapixel')
size_in = self.request.query_params.get('size_in')
resolution = self.request.query_params.get('resolution')
screen_type = self.request.query_params.get('screen_type')
#maintainers = self.request.query_params.getlist('maintainers')
version = self.request.query_params.get('version')
if name:
@ -24,7 +27,13 @@ class DeviceViewSet(viewsets.ModelViewSet):
if megapixel:
self.queryset = self.queryset.filter(cameras__megapixel__gt=Decimal(megapixel))
if version:
self.queryset = self.queryset.filter(versions__icontains=version)
self.queryset = self.queryset.filter(versions__icontains=version)
if size_in:
self.queryset = self.queryset.filter(screen__size_in__gt=Decimal(size_in))
if resolution:
self.queryset = self.queryset.filter(screen__resolution__icontains=resolution)
if screen_type:
self.queryset = self.queryset.filter(screen__technology__icontains=screen_type)
#if maintainers:
self.queryset = self.queryset.filter(maintainers__len__gt=0)
return self.queryset