Make it possible to add a tag from the Tag Browser
All checks were successful
CI / test (push) Successful in 3m46s
Lint / test (push) Successful in 17s
Trivy / test (push) Successful in 21s

This commit is contained in:
Miguel Jacq 2025-11-15 11:22:40 +11:00
parent b1ae56270a
commit b1ba599e99
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
7 changed files with 63 additions and 4 deletions

View file

@ -561,6 +561,30 @@ class DBManager:
).fetchall()
return [(r[0], r[1], r[2]) for r in rows]
def add_tag(self, name: str, color: str) -> None:
"""
Update a tag's name and colour.
"""
name = name.strip()
color = color.strip() or "#CCCCCC"
try:
with self.conn:
cur = self.conn.cursor()
cur.execute(
"""
INSERT INTO tags
(name, color)
VALUES (?, ?);
""",
(name, color),
)
except sqlite.IntegrityError as e:
if "UNIQUE constraint failed: tags.name" in str(e):
raise sqlite.IntegrityError(
strings._("tag_already_exists_with_that_name")
) from e
def update_tag(self, tag_id: int, name: str, color: str) -> None:
"""
Update a tag's name and colour.