Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppression de la suppression logique des médias #538

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""drop t_medias.supprime column

Revision ID: 44447746cacc
Revises: 0db13d65cb27
Create Date: 2023-08-04 14:04:28.235799

"""

import os
import shutil
from pathlib import Path
from flask import current_app
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import false


# revision identifiers, used by Alembic.
revision = "44447746cacc"
down_revision = "0db13d65cb27"
branch_labels = None
depends_on = None


def upgrade():
# Suppression des fichiers médias
conn = op.get_bind()
res = conn.execute(
"""SELECT id_media, chemin
FROM taxonomie.t_medias
WHERE NOT NULLIF(chemin , '') IS NULL AND supprime = TRUE;"""
)

media_path = Path(current_app.config["MEDIA_FOLDER"], "taxhub").absolute()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

si les gens passe la migration avant d'avoir changer le paramètre UPLOAD_FOLDER en MEDIA_FOLDER ça va pas marcher ?
Et le /taxhub ne marche pas dans le contexte de taxhub standalone ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je pense que c'est bon
Pour MEDIA_FOLDER c'est géré par défaut avec le schema toml.
Pour /taxhub même dans standalone le chemin est MEDIA_FOLDER/taxhub


for m in res:
# Fichier principal
try:
os.remove(media_path / Path(m[1]))
except FileNotFoundError:
pass
# Thumbnail
try:
shutil.rmtree(f"{media_path}/thumb/{m[0]}")
except FileNotFoundError:
pass

# Suppression des enregistrements médias supprimés logiquement
op.execute("DELETE FROM taxonomie.t_medias AS tm WHERE supprime = TRUE;")
op.drop_column(table_name="t_medias", column_name="supprime", schema="taxonomie")


def downgrade():
op.add_column(
table_name="t_medias",
column=sa.Column("supprime", sa.Boolean, nullable=False, server_default=false()),
schema="taxonomie",
)
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def populate_data(sample_data):
url="https://upload.wikimedia.org/wikipedia/commons/f/f0/Taxa-4x35-tagskilt.jpg",
id_type=1,
is_public=True,
supprime=False,
)
db.session.add(media)

Expand Down
1 change: 0 additions & 1 deletion apptax/taxonomie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ class TMedias(db.Model):
source = db.Column(db.Unicode)
licence = db.Column(db.Unicode)
is_public = db.Column(db.BOOLEAN)
supprime = db.Column(db.BOOLEAN)
id_type = db.Column(
db.Integer,
ForeignKey(BibTypesMedia.id_type),
Expand Down
1 change: 0 additions & 1 deletion apptax/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def nom_with_media():
titre="test",
url="http://photo.com",
is_public=True,
supprime=False,
types=BibTypesMedia.query.first(),
)
taxon.medias.append(media)
Expand Down
1 change: 0 additions & 1 deletion apptax/utils/taxref_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def import_inpn_media(cd_ref, cd_nom, logger=None):
m_obj.desc_media = m_inpn["title"]
m_obj.licence = m_inpn["licence"]
m_obj.is_public = True
m_obj.supprime = False
m_obj.source = "INPN"
m_obj.id_type = type.id_type
db.session.add(m_obj)
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Remplacement du fichier de configuration `config.py` par une fichier toml : `taxhub_config.toml` (#517)
- Création d'une commande de récupération des médias de l'inpn et suppression des anciens scripts. Pour spécifier les taxons à traiter la commande prend comme paramètre un fichier contenant une liste de cd_nom
`flask taxref import-inpn-media list_cd_ref.csv`
- Suppression de la colonne supprime des médias qui effectuait une suppression logique et non physique des médias.

**⚠️ Notes de version**
- Les données de la table "bib_nom" on été sauvegardées dans une liste nommée "Save bib_nom". Le champs "nom_français" ainsi que "commentaire" de cette table ne sont pas conservés dans la version 2.0.0 (ils n'étaient plus utilisés dans les recherche de taxons depuis plusieurs versions).
Expand Down
Loading