Skip to content

Commit

Permalink
Revert "S1158 - Nom des documents téléchargés (#1478)"
Browse files Browse the repository at this point in the history
This reverts commit f858ebd.
  • Loading branch information
syldb committed Jul 18, 2024
1 parent 4abdceb commit e631c50
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 114 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ SHELL := /bin/bash
server:
@python manage.py runserver 0.0.0.0:8001

worker:
@python -m celery -A core.worker worker -B -l INFO

fmt:
@pre-commit run --all-files

Expand Down
12 changes: 4 additions & 8 deletions conventions/services/avenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from conventions.services.search import AvenantListSearchService
from upload.services import UploadService

from .utils import convention_upload_filename

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -143,16 +141,14 @@ def complete_avenants_for_avenant(
if avenant_form.is_valid():
file = request.FILES["nom_fichier_signe"]
if file:
upload_filename = convention_upload_filename(avenant)

now = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")
filename = f"{now}_convention_{avenant.uuid}_signed.pdf"
upload_service = UploadService(
convention_dirpath=f"conventions/{avenant.uuid}/convention_docs",
filename=upload_filename,
filename=filename,
)

upload_service.upload_file(file)
avenant.nom_fichier_signe = upload_filename

avenant.nom_fichier_signe = filename
for avenant_type in avenant_form.cleaned_data["avenant_types"]:
avenanttype = AvenantType.objects.get(nom=avenant_type)
avenant.avenant_types.add(avenanttype)
Expand Down
10 changes: 4 additions & 6 deletions conventions/services/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from core.storage import client
from upload.services import UploadService

from .utils import convention_upload_filename

logger = logging.getLogger(__name__)


Expand All @@ -18,19 +16,19 @@ class ConventionFileService:
def upload_convention_file(
cls, convention: Convention, file: File, update_statut: bool = True
):
upload_filename = convention_upload_filename(convention)

now = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")
filename = f"{now}_convention_{convention.uuid}_signed.pdf"
upload_service = UploadService(
convention_dirpath=f"conventions/{convention.uuid}/convention_docs",
filename=upload_filename,
filename=filename,
)
upload_service.upload_file(file)

if update_statut and not convention.statut == ConventionStatut.DENONCEE.label:
convention.statut = ConventionStatut.SIGNEE.label
convention.televersement_convention_signee_le = datetime.date.today()

convention.nom_fichier_signe = upload_filename
convention.nom_fichier_signe = filename
convention.save()

@classmethod
Expand Down
27 changes: 0 additions & 27 deletions conventions/services/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from datetime import datetime
from enum import Enum

from django.http import HttpRequest
Expand Down Expand Up @@ -148,29 +147,3 @@ def set_from_form_or_object(field, form, obj):
else getattr(obj, field)
),
)


def convention_upload_filename(convention: Convention) -> str:

def _normalize(numero: str | None) -> str | None:
if numero:
return numero.replace(" ", "_")

parts = []

if convention.parent:
parts += [
f"convention_{_normalize(convention.parent.numero)}",
f"avenant_{_normalize(convention.numero) or 'N'}",
]
else:
parts += [
f"convention_{_normalize(convention.numero) or 'NUM'}",
]

if convention.statut == ConventionStatut.PROJET.label:
parts.append("projet")

parts.append(datetime.now().strftime("%Y-%m-%d_%H-%M"))

return f"{'_'.join(parts)}.pdf"
70 changes: 0 additions & 70 deletions conventions/tests/services/test_utils.py

This file was deleted.

0 comments on commit e631c50

Please sign in to comment.