Add songlist and release date
This commit is contained in:
@@ -25,14 +25,14 @@ 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", "notes", "cpu", "ram", "gpu", "storage", "media_format",
|
||||
"checkout_date", "purchase_date", "release_date", "notes", "song_list", "cpu", "ram", "gpu", "storage", "media_format",
|
||||
}
|
||||
DEFAULT_TYPES = {
|
||||
"Computer": ["brand", "model", "serial_number", "asset_tag", "location", "purchase_date", "cpu", "ram", "gpu", "storage", "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", "media_format", "notes"],
|
||||
"CD": ["brand", "model", "asset_tag", "location", "purchase_date", "media_format", "notes"],
|
||||
"Long play disk": ["brand", "model", "asset_tag", "location", "purchase_date", "release_date", "media_format", "song_list", "notes"],
|
||||
"CD": ["brand", "model", "asset_tag", "location", "purchase_date", "release_date", "media_format", "song_list", "notes"],
|
||||
"Display": ["brand", "model", "serial_number", "asset_tag", "location", "purchase_date", "notes"],
|
||||
"Peripheral": ["brand", "model", "serial_number", "asset_tag", "location", "purchase_date", "notes"],
|
||||
"Other": ["brand", "model", "serial_number", "asset_tag", "location", "purchase_date", "notes"],
|
||||
@@ -65,7 +65,9 @@ def initialize_db():
|
||||
destination TEXT,
|
||||
checkout_date TEXT,
|
||||
purchase_date TEXT,
|
||||
release_date TEXT,
|
||||
notes TEXT,
|
||||
song_list TEXT,
|
||||
cpu TEXT,
|
||||
ram TEXT,
|
||||
gpu TEXT,
|
||||
@@ -105,6 +107,8 @@ def initialize_db():
|
||||
"image_filename": "ALTER TABLE inventory_items ADD COLUMN image_filename TEXT",
|
||||
"destination": "ALTER TABLE inventory_items ADD COLUMN destination TEXT",
|
||||
"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",
|
||||
}
|
||||
for column, statement in migrations.items():
|
||||
if column not in columns:
|
||||
@@ -118,6 +122,13 @@ def initialize_db():
|
||||
"INSERT OR IGNORE INTO inventory_types (name, fields) VALUES (?, ?)",
|
||||
(name, json.dumps(fields)),
|
||||
)
|
||||
for name in ("CD", "Long play disk"):
|
||||
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]
|
||||
if updated_fields != fields:
|
||||
connection.execute("UPDATE inventory_types SET fields = ? WHERE name = ? COLLATE NOCASE", (json.dumps(updated_fields), name))
|
||||
connection.execute(
|
||||
"""INSERT INTO inventory_images (item_id, filename, original_name, created_at)
|
||||
SELECT id, image_filename, image_filename, COALESCE(updated_at, datetime('now'))
|
||||
@@ -257,7 +268,9 @@ def item_payload(data):
|
||||
"destination": clean(data.get("destination")),
|
||||
"checkout_date": clean(data.get("checkout_date")) or None,
|
||||
"purchase_date": clean(data.get("purchase_date")) or None,
|
||||
"release_date": clean(data.get("release_date")) or None,
|
||||
"notes": clean(data.get("notes")),
|
||||
"song_list": clean(data.get("song_list")),
|
||||
"cpu": clean(data.get("cpu")),
|
||||
"ram": clean(data.get("ram")),
|
||||
"gpu": clean(data.get("gpu")),
|
||||
@@ -540,8 +553,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, notes, 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, media_format, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(*data.values(), now, now),
|
||||
)
|
||||
for filename, original_name in images:
|
||||
@@ -574,7 +587,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=?, notes=?, 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=?, media_format=?, updated_at=? WHERE id=?""",
|
||||
(*data.values(), item_id),
|
||||
)
|
||||
for filename, original_name in saved_images:
|
||||
|
||||
Reference in New Issue
Block a user