diff --git a/partitioncloud/modules/classes/partition.py b/partitioncloud/modules/classes/partition.py
index ce36cf5..8e0ca1a 100644
--- a/partitioncloud/modules/classes/partition.py
+++ b/partitioncloud/modules/classes/partition.py
@@ -75,6 +75,16 @@ class Partition():
)
db.commit()
+ def update_file(self, file, instance_path):
+ partition_path = os.path.join(
+ instance_path,
+ "partitions",
+ f"{self.uuid}.pdf"
+ )
+ file.save(partition_path)
+ if os.path.exists(f"{instance_path}/cache/thumbnails/{self.uuid}.jpg"):
+ os.remove(f"{instance_path}/cache/thumbnails/{self.uuid}.jpg")
+
def get_user(self):
db = get_db()
user = db.execute(
diff --git a/partitioncloud/modules/partition.py b/partitioncloud/modules/partition.py
index d560f0c..298ae92 100644
--- a/partitioncloud/modules/partition.py
+++ b/partitioncloud/modules/partition.py
@@ -3,6 +3,7 @@
Partition module
"""
import os
+import pypdf
from uuid import uuid4
from flask import (Blueprint, abort, send_file, render_template,
request, redirect, flash, session, current_app)
@@ -160,6 +161,17 @@ def edit(uuid):
flash(error)
return redirect(f"/partition/{ uuid }/edit")
+ if request.files.get('file', None):
+ new_file = request.files["file"]
+ try:
+ pypdf.PdfReader(new_file)
+ new_file.seek(0)
+ except (pypdf.errors.PdfReadError, pypdf.errors.PdfStreamError):
+ flash(_("Invalid PDF file"))
+ return redirect(request.referrer)
+
+ partition.update_file(new_file, current_app.instance_path)
+
partition.update(
name=request.form["name"],
author=request.form["author"],
diff --git a/partitioncloud/static/style/style.css b/partitioncloud/static/style/style.css
index 53eb692..86b56bd 100644
--- a/partitioncloud/static/style/style.css
+++ b/partitioncloud/static/style/style.css
@@ -734,7 +734,7 @@ midi-player {
cursor: pointer;
}
-.file-area .file-dummy {
+.file-area .inner-file-area {
padding: 30px;
background: var(--color-mantle);
border: 2px dashed var(--color-red);
@@ -742,20 +742,32 @@ midi-player {
transition: background 0.3s ease-in-out;
}
-.file-area .file-dummy .success {
+.file-area .inner-file-area .success {
display: none;
}
-.file-area:hover > .file-dummy {
+.file-area:hover > .inner-file-area {
background: var(--color-surface0);
}
-.file-area input[type=file]:valid + .file-dummy {
+.file-area input[type=file]:valid + .inner-file-area {
border-color: var(--color-green);
}
-.file-area input[type=file]:valid + .file-dummy .success {
+.file-area input[type=file]:not(:required) + .inner-file-area {
+ border-color: var(--color-blue);
+}
+
+.file-area input[type=file]:valid + .inner-file-area .success {
display: inline-block;
}
-.file-area input[type=file]:valid + .file-dummy .default {
+.file-area input[type=file]:valid + .inner-file-area .default {
display: none;
+}
+
+.file-area input[type=file]:not(:required) + .inner-file-area .success {
+ display: none;
+}
+
+.file-area input[type=file]:not(:required) + .inner-file-area .default {
+ display: inline-block;
}
\ No newline at end of file
diff --git a/partitioncloud/templates/components/add_partition.html b/partitioncloud/templates/components/add_partition.html
index b59f95e..b5fab2f 100644
--- a/partitioncloud/templates/components/add_partition.html
+++ b/partitioncloud/templates/components/add_partition.html
@@ -7,7 +7,11 @@
{% if partition_uuid %}
{% else %}
- {% include 'components/input_file.html' %}
+ {% block input_file %}
+ {% set required=true %}
+ {% set filetype=".pdf" %}
+ {% include 'components/input_file.html' %}
+ {% endblock %}
{% endif %}
\ No newline at end of file
diff --git a/partitioncloud/templates/components/input_file.html b/partitioncloud/templates/components/input_file.html
index 669bc5d..98196d0 100644
--- a/partitioncloud/templates/components/input_file.html
+++ b/partitioncloud/templates/components/input_file.html
@@ -1,7 +1,7 @@
-
-
+
+
{{ _("Your file is selected.") }}
-
{{ _("Select or drag & drop your file (pdf).") }}
+
{{ _("Select or drag & drop your file") }} ({{ filetype }}).
\ No newline at end of file
diff --git a/partitioncloud/templates/partition/attachments.html b/partitioncloud/templates/partition/attachments.html
index 934d791..4373168 100644
--- a/partitioncloud/templates/partition/attachments.html
+++ b/partitioncloud/templates/partition/attachments.html
@@ -9,7 +9,11 @@
{{ _("Add an attachment to %(name)s", name=partition.name) }}
Close
@@ -55,7 +59,7 @@
{% endif %}
-{% if user %}
+{% if g.user %}
diff --git a/partitioncloud/templates/partition/details.html b/partitioncloud/templates/partition/details.html
index f637f52..e5e18e6 100644
--- a/partitioncloud/templates/partition/details.html
+++ b/partitioncloud/templates/partition/details.html
@@ -52,7 +52,13 @@
{{ _("File") }}
-
+
+ {% block input_file %}
+ {% set required=false %}
+ {% set filetype=".pdf" %}
+ {% include 'components/input_file.html' %}
+ {% endblock %}
+
{{ _("Title") }}
diff --git a/partitioncloud/templates/partition/edit.html b/partitioncloud/templates/partition/edit.html
index b5179a6..040f868 100644
--- a/partitioncloud/templates/partition/edit.html
+++ b/partitioncloud/templates/partition/edit.html
@@ -13,7 +13,13 @@
{{ _("File") }}
-
+
+ {% block input_file %}
+ {% set required=false %}
+ {% set filetype=".pdf" %}
+ {% include 'components/input_file.html' %}
+ {% endblock %}
+
{% if partition.source != "unknown" and partition.source != "upload" %}
diff --git a/partitioncloud/translations/en/LC_MESSAGES/messages.po b/partitioncloud/translations/en/LC_MESSAGES/messages.po
index 9930bc2..fbd4d5f 100644
--- a/partitioncloud/translations/en/LC_MESSAGES/messages.po
+++ b/partitioncloud/translations/en/LC_MESSAGES/messages.po
@@ -75,12 +75,12 @@ msgstr "You don't own this album."
msgid "Album deleted."
msgstr "Album deleted."
-#: partitioncloud/modules/albums.py:278 partitioncloud/modules/partition.py:153
-#: partitioncloud/modules/partition.py:199
+#: partitioncloud/modules/albums.py:278 partitioncloud/modules/partition.py:154
+#: partitioncloud/modules/partition.py:211
msgid "Missing title"
msgstr "Missing title"
-#: partitioncloud/modules/albums.py:280 partitioncloud/modules/partition.py:63
+#: partitioncloud/modules/albums.py:280 partitioncloud/modules/partition.py:64
msgid "Missing file"
msgstr "Missing file"
@@ -88,7 +88,7 @@ msgstr "Missing file"
msgid "Search results expired"
msgstr "Search results expired"
-#: partitioncloud/modules/albums.py:302
+#: partitioncloud/modules/albums.py:302 partitioncloud/modules/partition.py:170
msgid "Invalid PDF file"
msgstr ""
@@ -183,43 +183,43 @@ msgstr "Group deleted."
msgid "You are not admin of this group."
msgstr "You are not admin of this group."
-#: partitioncloud/modules/partition.py:58
+#: partitioncloud/modules/partition.py:59
msgid "You don't own this score."
msgstr "You don't own this score."
-#: partitioncloud/modules/partition.py:71
+#: partitioncloud/modules/partition.py:72
msgid "Missing filename."
msgstr "Missing filename."
-#: partitioncloud/modules/partition.py:76
+#: partitioncloud/modules/partition.py:77
msgid "Unsupported file type."
msgstr "Unsupported file type."
-#: partitioncloud/modules/partition.py:144
+#: partitioncloud/modules/partition.py:145
msgid "You are not allowed to edit this file."
msgstr "You are not allowed to edit this file."
-#: partitioncloud/modules/partition.py:155
-#: partitioncloud/modules/partition.py:201
+#: partitioncloud/modules/partition.py:156
+#: partitioncloud/modules/partition.py:213
msgid "Missing author in request body (can be null)."
msgstr "Missing author in request body (can be null)."
-#: partitioncloud/modules/partition.py:157
-#: partitioncloud/modules/partition.py:203
+#: partitioncloud/modules/partition.py:158
+#: partitioncloud/modules/partition.py:215
msgid "Missing lyrics (can be null)."
msgstr "Missing lyrics (can be null)."
-#: partitioncloud/modules/partition.py:169
-#: partitioncloud/modules/partition.py:215
+#: partitioncloud/modules/partition.py:181
+#: partitioncloud/modules/partition.py:227
#, python-format
msgid "Successfully modified %(name)s"
msgstr "Successfully modified %(name)s"
-#: partitioncloud/modules/partition.py:230
+#: partitioncloud/modules/partition.py:242
msgid "You are not allowed to delete this score."
msgstr "You are not allowed to delete this score."
-#: partitioncloud/modules/partition.py:238
+#: partitioncloud/modules/partition.py:250
msgid "Score deleted."
msgstr "Score deleted."
@@ -411,8 +411,8 @@ msgstr "Do you really want to delete this album?"
#: partitioncloud/templates/groupe/index.html:20
#: partitioncloud/templates/groupe/index.html:57
#: partitioncloud/templates/partition/delete.html:10
-#: partitioncloud/templates/partition/details.html:86
-#: partitioncloud/templates/partition/edit.html:57
+#: partitioncloud/templates/partition/details.html:92
+#: partitioncloud/templates/partition/edit.html:63
#: partitioncloud/templates/settings/index.html:19
msgid "Delete"
msgstr "Delete"
@@ -526,9 +526,9 @@ msgstr "author"
msgid "lyrics"
msgstr "lyrics"
-#: partitioncloud/templates/components/add_partition.html:12
+#: partitioncloud/templates/components/add_partition.html:16
#: partitioncloud/templates/groupe/index.html:11
-#: partitioncloud/templates/partition/attachments.html:13
+#: partitioncloud/templates/partition/attachments.html:17
msgid "Add"
msgstr "Add"
@@ -537,8 +537,8 @@ msgid "Your file is selected."
msgstr "Your file is selected."
#: partitioncloud/templates/components/input_file.html:5
-msgid "Select or drag & drop your file (pdf)."
-msgstr "Select or drag & drop your file (pdf)."
+msgid "Select or drag & drop your file"
+msgstr "Select or drag & drop your file"
#: partitioncloud/templates/groupe/index.html:8
#, python-format
@@ -576,7 +576,7 @@ msgstr "Attachments of %(name)s"
msgid "Add an attachment to %(name)s"
msgstr "Add an attachment to %(name)s"
-#: partitioncloud/templates/partition/attachments.html:22
+#: partitioncloud/templates/partition/attachments.html:26
msgid ""
"No pdf viewer available in this browser.\n"
" You can use Firefox on Android."
@@ -584,11 +584,11 @@ msgstr ""
"No pdf viewer available in this browser.\n"
" You can use Firefox on Android."
-#: partitioncloud/templates/partition/attachments.html:46
+#: partitioncloud/templates/partition/attachments.html:50
msgid "JavaScript is mandatory to read MIDI files"
msgstr "JavaScript is mandatory to read MIDI files"
-#: partitioncloud/templates/partition/attachments.html:60
+#: partitioncloud/templates/partition/attachments.html:64
msgid "Add an attachment"
msgstr "Add an attachment"
@@ -618,45 +618,45 @@ msgstr "Type"
msgid "File"
msgstr "File"
-#: partitioncloud/templates/partition/details.html:58
-#: partitioncloud/templates/partition/details.html:59
-#: partitioncloud/templates/partition/edit.html:29
-#: partitioncloud/templates/partition/edit.html:30
+#: partitioncloud/templates/partition/details.html:64
+#: partitioncloud/templates/partition/details.html:65
+#: partitioncloud/templates/partition/edit.html:35
+#: partitioncloud/templates/partition/edit.html:36
msgid "Title"
msgstr "Title"
-#: partitioncloud/templates/partition/details.html:62
-#: partitioncloud/templates/partition/details.html:63
-#: partitioncloud/templates/partition/edit.html:33
-#: partitioncloud/templates/partition/edit.html:34
+#: partitioncloud/templates/partition/details.html:68
+#: partitioncloud/templates/partition/details.html:69
+#: partitioncloud/templates/partition/edit.html:39
+#: partitioncloud/templates/partition/edit.html:40
msgid "Author"
msgstr "Author"
-#: partitioncloud/templates/partition/details.html:66
-#: partitioncloud/templates/partition/details.html:67
-#: partitioncloud/templates/partition/edit.html:37
-#: partitioncloud/templates/partition/edit.html:38
+#: partitioncloud/templates/partition/details.html:72
+#: partitioncloud/templates/partition/details.html:73
+#: partitioncloud/templates/partition/edit.html:43
+#: partitioncloud/templates/partition/edit.html:44
msgid "Lyrics"
msgstr "Lyrics"
-#: partitioncloud/templates/partition/details.html:70
-#: partitioncloud/templates/partition/edit.html:41
+#: partitioncloud/templates/partition/details.html:76
+#: partitioncloud/templates/partition/edit.html:47
msgid "Attachments"
msgstr "Attachments"
-#: partitioncloud/templates/partition/details.html:75
-#: partitioncloud/templates/partition/edit.html:46
+#: partitioncloud/templates/partition/details.html:81
+#: partitioncloud/templates/partition/edit.html:52
#, python-format
msgid "Yes, %(number)s"
msgstr "Yes, %(number)s"
-#: partitioncloud/templates/partition/details.html:77
-#: partitioncloud/templates/partition/edit.html:48
+#: partitioncloud/templates/partition/details.html:83
+#: partitioncloud/templates/partition/edit.html:54
msgid "Add one"
msgstr "Add one"
-#: partitioncloud/templates/partition/details.html:83
-#: partitioncloud/templates/partition/edit.html:54
+#: partitioncloud/templates/partition/details.html:89
+#: partitioncloud/templates/partition/edit.html:60
msgid "Update"
msgstr "Update"
@@ -665,7 +665,7 @@ msgstr "Update"
msgid "Modify \"%(name)s\""
msgstr "Modify \"%(name)s\""
-#: partitioncloud/templates/partition/edit.html:21
+#: partitioncloud/templates/partition/edit.html:27
msgid "Source"
msgstr "Source"
diff --git a/partitioncloud/translations/fr/LC_MESSAGES/messages.po b/partitioncloud/translations/fr/LC_MESSAGES/messages.po
index f9a4bc0..7a9635a 100644
--- a/partitioncloud/translations/fr/LC_MESSAGES/messages.po
+++ b/partitioncloud/translations/fr/LC_MESSAGES/messages.po
@@ -75,12 +75,12 @@ msgstr "Vous ne possédez pas cet album."
msgid "Album deleted."
msgstr "Album supprimé."
-#: partitioncloud/modules/albums.py:278 partitioncloud/modules/partition.py:153
-#: partitioncloud/modules/partition.py:199
+#: partitioncloud/modules/albums.py:278 partitioncloud/modules/partition.py:154
+#: partitioncloud/modules/partition.py:211
msgid "Missing title"
msgstr "Un titre est requis."
-#: partitioncloud/modules/albums.py:280 partitioncloud/modules/partition.py:63
+#: partitioncloud/modules/albums.py:280 partitioncloud/modules/partition.py:64
msgid "Missing file"
msgstr "Aucun fichier n'a été fourni."
@@ -88,7 +88,7 @@ msgstr "Aucun fichier n'a été fourni."
msgid "Search results expired"
msgstr "Les résultats de la recherche ont expiré."
-#: partitioncloud/modules/albums.py:302
+#: partitioncloud/modules/albums.py:302 partitioncloud/modules/partition.py:170
msgid "Invalid PDF file"
msgstr "Fichier PDF invalide"
@@ -185,43 +185,43 @@ msgstr "Groupe supprimé."
msgid "You are not admin of this group."
msgstr "Vous n'êtes pas administrateur de ce groupe"
-#: partitioncloud/modules/partition.py:58
+#: partitioncloud/modules/partition.py:59
msgid "You don't own this score."
msgstr "Cette partition ne vous appartient pas"
-#: partitioncloud/modules/partition.py:71
+#: partitioncloud/modules/partition.py:72
msgid "Missing filename."
msgstr "Pas de nom de fichier"
-#: partitioncloud/modules/partition.py:76
+#: partitioncloud/modules/partition.py:77
msgid "Unsupported file type."
msgstr "Extension de fichier non supportée"
-#: partitioncloud/modules/partition.py:144
+#: partitioncloud/modules/partition.py:145
msgid "You are not allowed to edit this file."
msgstr "Vous n'êtes pas autorisé à modifier cette partition."
-#: partitioncloud/modules/partition.py:155
-#: partitioncloud/modules/partition.py:201
+#: partitioncloud/modules/partition.py:156
+#: partitioncloud/modules/partition.py:213
msgid "Missing author in request body (can be null)."
msgstr "Un nom d'auteur est requis (à minima nul)"
-#: partitioncloud/modules/partition.py:157
-#: partitioncloud/modules/partition.py:203
+#: partitioncloud/modules/partition.py:158
+#: partitioncloud/modules/partition.py:215
msgid "Missing lyrics (can be null)."
msgstr "Des paroles sont requises (à minima nulles)"
-#: partitioncloud/modules/partition.py:169
-#: partitioncloud/modules/partition.py:215
+#: partitioncloud/modules/partition.py:181
+#: partitioncloud/modules/partition.py:227
#, python-format
msgid "Successfully modified %(name)s"
msgstr "Partition %(name)s modifiée avec succès."
-#: partitioncloud/modules/partition.py:230
+#: partitioncloud/modules/partition.py:242
msgid "You are not allowed to delete this score."
msgstr "Vous n'êtes pas autorisé à supprimer cette partition."
-#: partitioncloud/modules/partition.py:238
+#: partitioncloud/modules/partition.py:250
msgid "Score deleted."
msgstr "Partition supprimée."
@@ -417,8 +417,8 @@ msgstr "Êtes vous sûr de vouloir supprimer cet album ?"
#: partitioncloud/templates/groupe/index.html:20
#: partitioncloud/templates/groupe/index.html:57
#: partitioncloud/templates/partition/delete.html:10
-#: partitioncloud/templates/partition/details.html:86
-#: partitioncloud/templates/partition/edit.html:57
+#: partitioncloud/templates/partition/details.html:92
+#: partitioncloud/templates/partition/edit.html:63
#: partitioncloud/templates/settings/index.html:19
msgid "Delete"
msgstr "Supprimer"
@@ -532,9 +532,9 @@ msgstr "auteur"
msgid "lyrics"
msgstr "paroles"
-#: partitioncloud/templates/components/add_partition.html:12
+#: partitioncloud/templates/components/add_partition.html:16
#: partitioncloud/templates/groupe/index.html:11
-#: partitioncloud/templates/partition/attachments.html:13
+#: partitioncloud/templates/partition/attachments.html:17
msgid "Add"
msgstr "Ajouter"
@@ -543,8 +543,8 @@ msgid "Your file is selected."
msgstr "Fichier sélectionné."
#: partitioncloud/templates/components/input_file.html:5
-msgid "Select or drag & drop your file (pdf)."
-msgstr "Sélectionner ou déposer un fichier (pdf)."
+msgid "Select or drag & drop your file"
+msgstr "Sélectionner ou déposer un fichier"
#: partitioncloud/templates/groupe/index.html:8
#, python-format
@@ -585,7 +585,7 @@ msgstr "Attachments de %(name)s"
msgid "Add an attachment to %(name)s"
msgstr "Ajouter un attachment à %(name)s"
-#: partitioncloud/templates/partition/attachments.html:22
+#: partitioncloud/templates/partition/attachments.html:26
msgid ""
"No pdf viewer available in this browser.\n"
" You can use Firefox on Android."
@@ -593,11 +593,11 @@ msgstr ""
"Impossible d'afficher le pdf dans ce navigateur.\n"
" Il est conseillé d'utiliser Firefox sur Android."
-#: partitioncloud/templates/partition/attachments.html:46
+#: partitioncloud/templates/partition/attachments.html:50
msgid "JavaScript is mandatory to read MIDI files"
msgstr "JavaScript est nécessaire pour lire les fichiers MIDI"
-#: partitioncloud/templates/partition/attachments.html:60
+#: partitioncloud/templates/partition/attachments.html:64
msgid "Add an attachment"
msgstr "Ajouter un attachment"
@@ -627,45 +627,45 @@ msgstr "Type d'ajout"
msgid "File"
msgstr "Fichier"
-#: partitioncloud/templates/partition/details.html:58
-#: partitioncloud/templates/partition/details.html:59
-#: partitioncloud/templates/partition/edit.html:29
-#: partitioncloud/templates/partition/edit.html:30
+#: partitioncloud/templates/partition/details.html:64
+#: partitioncloud/templates/partition/details.html:65
+#: partitioncloud/templates/partition/edit.html:35
+#: partitioncloud/templates/partition/edit.html:36
msgid "Title"
msgstr "Titre"
-#: partitioncloud/templates/partition/details.html:62
-#: partitioncloud/templates/partition/details.html:63
-#: partitioncloud/templates/partition/edit.html:33
-#: partitioncloud/templates/partition/edit.html:34
+#: partitioncloud/templates/partition/details.html:68
+#: partitioncloud/templates/partition/details.html:69
+#: partitioncloud/templates/partition/edit.html:39
+#: partitioncloud/templates/partition/edit.html:40
msgid "Author"
msgstr "Auteur"
-#: partitioncloud/templates/partition/details.html:66
-#: partitioncloud/templates/partition/details.html:67
-#: partitioncloud/templates/partition/edit.html:37
-#: partitioncloud/templates/partition/edit.html:38
+#: partitioncloud/templates/partition/details.html:72
+#: partitioncloud/templates/partition/details.html:73
+#: partitioncloud/templates/partition/edit.html:43
+#: partitioncloud/templates/partition/edit.html:44
msgid "Lyrics"
msgstr "Paroles"
-#: partitioncloud/templates/partition/details.html:70
-#: partitioncloud/templates/partition/edit.html:41
+#: partitioncloud/templates/partition/details.html:76
+#: partitioncloud/templates/partition/edit.html:47
msgid "Attachments"
msgstr "Pièces jointes"
-#: partitioncloud/templates/partition/details.html:75
-#: partitioncloud/templates/partition/edit.html:46
+#: partitioncloud/templates/partition/details.html:81
+#: partitioncloud/templates/partition/edit.html:52
#, python-format
msgid "Yes, %(number)s"
msgstr "Oui, %(number)s"
-#: partitioncloud/templates/partition/details.html:77
-#: partitioncloud/templates/partition/edit.html:48
+#: partitioncloud/templates/partition/details.html:83
+#: partitioncloud/templates/partition/edit.html:54
msgid "Add one"
msgstr "En rajouter"
-#: partitioncloud/templates/partition/details.html:83
-#: partitioncloud/templates/partition/edit.html:54
+#: partitioncloud/templates/partition/details.html:89
+#: partitioncloud/templates/partition/edit.html:60
msgid "Update"
msgstr "Mettre à jour"
@@ -674,7 +674,7 @@ msgstr "Mettre à jour"
msgid "Modify \"%(name)s\""
msgstr "Modifier \"%(name)s\""
-#: partitioncloud/templates/partition/edit.html:21
+#: partitioncloud/templates/partition/edit.html:27
msgid "Source"
msgstr "Source"