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'`
This commit is contained in:
augustin64 2023-08-30 19:50:00 +02:00
parent 08908ffdf7
commit 92db6efebf
6 changed files with 32 additions and 4 deletions

View File

@ -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()

View File

@ -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

View File

@ -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 (

View File

@ -603,6 +603,7 @@ table {
}
td {
height: 35px; /* will grow automatically */
min-width: 178px;
border: thin solid var(--color-surface0);
text-align: center;

View File

@ -24,6 +24,18 @@
{% endif %}
</td>
</tr>
<tr>
<td>
Type d'ajout
</td>
<td>
{% if partition.source == "unknown" or partition.source == "upload" %}
{{ partition.source }}
{% else %}
<a href="{{ partition.source }}">search</a>
{% endif %}
</td>
</tr>
<tr>
<td>
Albums

View File

@ -13,6 +13,16 @@
<td>Fichier</td>
<td><a href="/partition/{{ partition.uuid }}"><img class="partition-thumbnail" src="/static/thumbnails/{{ partition.uuid }}.jpg"></a></td>
</tr>
{% if partition.source != "unknown" and partition.source != "upload" %}
<tr>
<td>
Source
</td>
<td class="partition-source">
<a href="{{ partition.source }}">{{ partition.source.split("/")[2] }}</a>
</td>
</tr>
{% endif %}
<tr>
<td>Titre</td>
<td><input name="name" type="text" value="{{ partition.name }}" placeholder="Titre" required /><br/></td>