adjustment

This commit is contained in:
d0c 2023-01-23 17:30:13 +01:00
parent 1be0dfa7c4
commit bc12a30f1c
4 changed files with 18 additions and 11 deletions

View file

@ -139,4 +139,4 @@ REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'] 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
} }
LINEAGEWIKI = '/home/d0c/Code/lineage_wiki' LINEAGEWIKI = '/home/francesco/Code/lineage_wiki'

View file

@ -39,13 +39,17 @@ class Command(BaseCommand):
devicesdir = settings.LINEAGEWIKI + "/_data/devices/" devicesdir = settings.LINEAGEWIKI + "/_data/devices/"
# import pdb; pdb.set_trace() # import pdb; pdb.set_trace()
for filename in os.listdir(devicesdir): for filename in os.listdir(devicesdir):
dev = Device()
cameras = []
bluetooth = {}
peripherals = []
with open(os.path.join(devicesdir, filename), "r") as stream: with open(os.path.join(devicesdir, filename), "r") as stream:
try: try:
data = yaml.safe_load(stream) data = yaml.safe_load(stream)
print(data['codename']) print(data['codename'])
dev = Device()
for key, value in data.items(): for key, value in data.items():
# if key == "architecture": # if key == "architecture":
# if type(value) == dict(): # if type(value) == dict():
# setattr(dev, key, value) # setattr(dev, key, value)
@ -66,16 +70,14 @@ class Command(BaseCommand):
if not hasattr(value, 'profiles'): if not hasattr(value, 'profiles'):
setattr(bt, 'profiles', None) setattr(bt, 'profiles', None)
setattr(bt, subkey, subvalue) setattr(bt, subkey, subvalue)
bt.save() bt.save()
else: else:
bt = bt.get(spec=value['spec'], profiles=value['profiles']) bt = bt.get(spec=value['spec'], profiles=value['profiles'])
dev.bluetooth = bt bluetooth = bt
dev.save()
elif key == "cameras": elif key == "cameras":
dev.save()
for c in value: for c in value:
cam = set_camera(c) cam = set_camera(c)
dev.cameras.add(cam) cameras.append(cam)
elif key == "peripherals": elif key == "peripherals":
if str(value) == "None": if str(value) == "None":
value = None value = None
@ -84,8 +86,12 @@ class Command(BaseCommand):
value = None value = None
else: else:
setattr(dev, key, value) setattr(dev, key, value)
dev.save()
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
print(exc) print(exc)
stream.close() stream.close()
dev.save()
dev.bluetooth = bluetooth
for camera in cameras:
dev.cameras.add(cam)
dev.save()

View file

@ -20,7 +20,7 @@ class Camera(models.Model):
info = models.CharField(max_length=100, null=True) info = models.CharField(max_length=100, null=True)
def __str__(self): def __str__(self):
return f" {self.flash - self.megapixel - self.info}" return f" {self.flash} - {str(self.megapixel)} - {self.info}"
class Device(models.Model): class Device(models.Model):

View file

@ -15,6 +15,7 @@ class BluetoothSerializer(serializers.ModelSerializer):
exclude = [] exclude = []
class DeviceSerializer(serializers.ModelSerializer): class DeviceSerializer(serializers.ModelSerializer):
bluetooth = BluetoothSerializer(many=False, read_only=True) bluetooth = BluetoothSerializer(many=False, read_only=True)
cameras = CameraSerializer(many=True, read_only=True) cameras = CameraSerializer(many=True, read_only=True)