Add battery to items, add Pink Floyd and Helloween albums to database + some fixes to manage types
This commit is contained in:
@@ -25,10 +25,10 @@ ROLE_ADMIN = "admin"
|
||||
VALID_ROLES = {ROLE_READ_ONLY, ROLE_READ_WRITE, ROLE_ADMIN}
|
||||
CONFIGURABLE_FIELDS = {
|
||||
"brand", "model", "serial_number", "asset_tag", "location", "destination",
|
||||
"checkout_date", "purchase_date", "release_date", "notes", "song_list", "cpu", "ram", "gpu", "storage", "media_format",
|
||||
"checkout_date", "purchase_date", "release_date", "notes", "song_list", "cpu", "ram", "gpu", "storage", "battery", "media_format",
|
||||
}
|
||||
DEFAULT_TYPES = {
|
||||
"Computer": ["brand", "model", "serial_number", "asset_tag", "location", "purchase_date", "cpu", "ram", "gpu", "storage", "notes"],
|
||||
"Computer": ["brand", "model", "serial_number", "asset_tag", "location", "purchase_date", "cpu", "ram", "gpu", "storage", "battery", "notes"],
|
||||
"Audio": ["brand", "model", "serial_number", "asset_tag", "location", "purchase_date", "media_format", "notes"],
|
||||
"Graphics": ["brand", "model", "serial_number", "asset_tag", "location", "purchase_date", "gpu", "storage", "notes"],
|
||||
"Long play disk": ["brand", "model", "asset_tag", "location", "purchase_date", "release_date", "media_format", "song_list", "notes"],
|
||||
@@ -72,6 +72,7 @@ def initialize_db():
|
||||
ram TEXT,
|
||||
gpu TEXT,
|
||||
storage TEXT,
|
||||
battery TEXT,
|
||||
media_format TEXT,
|
||||
image_filename TEXT,
|
||||
created_at TEXT NOT NULL,
|
||||
@@ -109,6 +110,7 @@ def initialize_db():
|
||||
"checkout_date": "ALTER TABLE inventory_items ADD COLUMN checkout_date TEXT",
|
||||
"release_date": "ALTER TABLE inventory_items ADD COLUMN release_date TEXT",
|
||||
"song_list": "ALTER TABLE inventory_items ADD COLUMN song_list TEXT",
|
||||
"battery": "ALTER TABLE inventory_items ADD COLUMN battery TEXT",
|
||||
}
|
||||
for column, statement in migrations.items():
|
||||
if column not in columns:
|
||||
@@ -122,11 +124,15 @@ def initialize_db():
|
||||
"INSERT OR IGNORE INTO inventory_types (name, fields) VALUES (?, ?)",
|
||||
(name, json.dumps(fields)),
|
||||
)
|
||||
for name in ("CD", "Long play disk"):
|
||||
for name, additional_fields in {
|
||||
"CD": ("release_date", "song_list"),
|
||||
"Long play disk": ("release_date", "song_list"),
|
||||
"Computer": ("battery",),
|
||||
}.items():
|
||||
row = connection.execute("SELECT fields FROM inventory_types WHERE name = ? COLLATE NOCASE", (name,)).fetchone()
|
||||
if row:
|
||||
fields = json.loads(row["fields"])
|
||||
updated_fields = fields + [field for field in ("release_date", "song_list") if field not in fields]
|
||||
updated_fields = fields + [field for field in additional_fields if field not in fields]
|
||||
if updated_fields != fields:
|
||||
connection.execute("UPDATE inventory_types SET fields = ? WHERE name = ? COLLATE NOCASE", (json.dumps(updated_fields), name))
|
||||
connection.execute(
|
||||
@@ -275,6 +281,7 @@ def item_payload(data):
|
||||
"ram": clean(data.get("ram")),
|
||||
"gpu": clean(data.get("gpu")),
|
||||
"storage": clean(data.get("storage")),
|
||||
"battery": clean(data.get("battery")),
|
||||
"media_format": clean(data.get("media_format")),
|
||||
}
|
||||
return payload
|
||||
@@ -553,8 +560,8 @@ def create_item():
|
||||
with get_db() as connection:
|
||||
cursor = connection.execute(
|
||||
"""INSERT INTO inventory_items
|
||||
(name, item_type, brand, model, serial_number, asset_tag, status, location, destination, checkout_date, purchase_date, release_date, notes, song_list, cpu, ram, gpu, storage, media_format, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(name, item_type, brand, model, serial_number, asset_tag, status, location, destination, checkout_date, purchase_date, release_date, notes, song_list, cpu, ram, gpu, storage, battery, media_format, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(*data.values(), now, now),
|
||||
)
|
||||
for filename, original_name in images:
|
||||
@@ -587,7 +594,7 @@ def update_item(item_id):
|
||||
return jsonify({"error": "Each inventory item can have up to 5 pictures."}), 400
|
||||
saved_images = save_images(new_images)
|
||||
result = connection.execute(
|
||||
"""UPDATE inventory_items SET name=?, item_type=?, brand=?, model=?, serial_number=?, asset_tag=?, status=?, location=?, destination=?, checkout_date=?, purchase_date=?, release_date=?, notes=?, song_list=?, cpu=?, ram=?, gpu=?, storage=?, media_format=?, updated_at=? WHERE id=?""",
|
||||
"""UPDATE inventory_items SET name=?, item_type=?, brand=?, model=?, serial_number=?, asset_tag=?, status=?, location=?, destination=?, checkout_date=?, purchase_date=?, release_date=?, notes=?, song_list=?, cpu=?, ram=?, gpu=?, storage=?, battery=?, media_format=?, updated_at=? WHERE id=?""",
|
||||
(*data.values(), item_id),
|
||||
)
|
||||
for filename, original_name in saved_images:
|
||||
|
||||
Reference in New Issue
Block a user