From 92db6efebfa2600e229d2ed387c30418d4c28184 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 30 Aug 2023 19:50:00 +0200 Subject: [PATCH] Add 'source' to partition table scheme possible values:unknown,upload,_any url_ run this command against your DB before pulling: `ALTER TABLE partition ADD source TEXT DEFAULT 'unknown'` --- partitioncloud/modules/albums.py | 9 ++++++--- partitioncloud/modules/utils.py | 1 + partitioncloud/schema.sql | 3 ++- partitioncloud/static/style.css | 1 + partitioncloud/templates/partition/details.html | 12 ++++++++++++ partitioncloud/templates/partition/edit.html | 10 ++++++++++ 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/partitioncloud/modules/albums.py b/partitioncloud/modules/albums.py index 805b8fb..91f2eb8 100644 --- a/partitioncloud/modules/albums.py +++ b/partitioncloud/modules/albums.py @@ -232,6 +232,7 @@ def add_partition(album_uuid): db = get_db() user = User(user_id=session.get("user_id")) album = Album(uuid=album_uuid) + source = "upload" # source type: upload, unknown or url if (not user.is_participant(album.uuid)) and (user.access_level != 1): flash("Vous ne participez pas à cet album.") @@ -256,6 +257,8 @@ def add_partition(album_uuid): ).fetchone() if data is None: error = "Les résultats de la recherche ont expiré." + else: + source = data["url"] else: partition_type = "file" @@ -278,10 +281,10 @@ def add_partition(album_uuid): db.execute( """ - INSERT INTO partition (uuid, name, author, body, user_id) - VALUES (?, ?, ?, ?, ?) + INSERT INTO partition (uuid, name, author, body, user_id, source) + VALUES (?, ?, ?, ?, ?, ?) """, - (partition_uuid, request.form["name"], author, body, user.id), + (partition_uuid, request.form["name"], author, body, user.id, source), ) db.commit() diff --git a/partitioncloud/modules/utils.py b/partitioncloud/modules/utils.py index be31edd..1cd3b48 100644 --- a/partitioncloud/modules/utils.py +++ b/partitioncloud/modules/utils.py @@ -314,6 +314,7 @@ class Partition(): self.author = data["author"] self.body = data["body"] self.user_id = data["user_id"] + self.source = data["source"] else: raise LookupError diff --git a/partitioncloud/schema.sql b/partitioncloud/schema.sql index 1fb6909..c0ede36 100644 --- a/partitioncloud/schema.sql +++ b/partitioncloud/schema.sql @@ -17,7 +17,8 @@ CREATE TABLE partition ( name TEXT NOT NULL, author TEXT, body TEXT, - user_id INTEGER + user_id INTEGER, + source TEXT DEFAULT 'unknown' ); CREATE TABLE album ( diff --git a/partitioncloud/static/style.css b/partitioncloud/static/style.css index d5d861f..9fd6292 100644 --- a/partitioncloud/static/style.css +++ b/partitioncloud/static/style.css @@ -603,6 +603,7 @@ table { } td { + height: 35px; /* will grow automatically */ min-width: 178px; border: thin solid var(--color-surface0); text-align: center; diff --git a/partitioncloud/templates/partition/details.html b/partitioncloud/templates/partition/details.html index f872eee..a38669c 100644 --- a/partitioncloud/templates/partition/details.html +++ b/partitioncloud/templates/partition/details.html @@ -24,6 +24,18 @@ {% endif %} + + + Type d'ajout + + + {% if partition.source == "unknown" or partition.source == "upload" %} + {{ partition.source }} + {% else %} + search + {% endif %} + + Albums diff --git a/partitioncloud/templates/partition/edit.html b/partitioncloud/templates/partition/edit.html index e58b59b..e822cc3 100644 --- a/partitioncloud/templates/partition/edit.html +++ b/partitioncloud/templates/partition/edit.html @@ -13,6 +13,16 @@ Fichier + {% if partition.source != "unknown" and partition.source != "upload" %} + + + Source + + + {{ partition.source.split("/")[2] }} + + + {% endif %} Titre