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

Use libreoffice to generate pdf file from docx #1202

Merged
merged 29 commits into from
Apr 30, 2024
Merged

Use libreoffice to generate pdf file from docx #1202

merged 29 commits into from
Apr 30, 2024

Conversation

kolok
Copy link
Collaborator

@kolok kolok commented Feb 5, 2024

To do

  • cleanup de convertapi
  • use libpath to manage path
  • retry pdf generation on exception
  • divide generate_and_send to generate and send
  • retry send email during 24 hours
  • add a command to generate doc files locally
  • fix font issues in docx templates

Copy link

github-actions bot commented Feb 5, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
8452 6864 81% 80% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
conventions/services/convention_generator.py 79% 🟢
conventions/services/recapitulatif.py 52% 🟢
conventions/tasks.py 81% 🟢
conventions/views/conventions.py 64% 🟢
core/settings.py 83% 🟢
upload/services.py 77% 🟢
TOTAL 72% 🟢

updated for commit: c31b5a4 by action🐍

@kolok kolok force-pushed the poc_libreoffice branch 3 times, most recently from e41fe05 to 58d869b Compare March 5, 2024 11:05
@kolok kolok force-pushed the poc_libreoffice branch from efb651b to ffbaf02 Compare March 19, 2024 09:39
@kolok kolok force-pushed the poc_libreoffice branch 2 times, most recently from 29ee271 to bca4e9d Compare March 27, 2024 17:36
@etchegom etchegom force-pushed the poc_libreoffice branch 2 times, most recently from 4fd8a42 to 9c85e38 Compare April 4, 2024 16:12
@etchegom etchegom changed the title POC which generate pdf file from docx locally using libreoffice Use libreoffice to generate pdf file from docx Apr 4, 2024
@@ -82,7 +83,7 @@ def _compute_total_locaux_collectifs(convention):
)


def generate_convention_doc(convention: Convention, save_data=False):
def generate_convention_doc(convention: Convention, save_data=False) -> DocxTemplate:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ca me parait mieux que generate_convention_doc retourne une instance de doc plutôt que des bytes.
Ca simplifie également par la suite ici, pour l'écriture dans un fichier local.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

Comment on lines +284 to +306
def get_tmp_local_path() -> Path:
local_path = Path(settings.MEDIA_ROOT, "tmp")
local_path.mkdir(parents=True, exist_ok=True)
return local_path
Copy link
Contributor

Choose a reason for hiding this comment

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

Proposition: écrire les fichiers locaux temporaire dans un répertoire "tmp" plutôt qu'à la racine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

Comment on lines +323 to +355
except (subprocess.CalledProcessError, OSError) as err:
raise PDFConversionError from err
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: il y a sûrement d'autres exceptions à catcher ici

Comment on lines +30 to +37
chain(
task_generate_pdf.s(convention_uuid),
task_send_email_to_bailleur.si(
convention_uuid,
convention_url,
convention_email_validator,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

La feature Celery chain permet de lier les deux tâches et d'ajuster ainsi les paramètre de retry à chacune d'elle.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

core/settings.py Outdated
@@ -575,6 +575,7 @@ def get_env_variable(name, cast=str, default=""):
CELERY_SEND_EVENTS = True
CELERY_ACKS_LATE = True
CELERY_WORKER_MAX_TASKS_PER_CHILD = 5000
CELERY_ALWAYS_EAGER = get_env_variable("CELERY_ALWAYS_EAGER", cast=bool, default=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

@etchegom etchegom marked this pull request as ready for review April 4, 2024 16:28
@etchegom etchegom requested a review from a team as a code owner April 4, 2024 16:28
@etchegom etchegom requested review from etchegom and syldb and removed request for a team April 4, 2024 16:28
Copy link
Collaborator Author

@kolok kolok left a comment

Choose a reason for hiding this comment

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

Ca me parait très bien tout ça, il n'y a plus qu'à faire des tests et résoudre les problèmes de mise en page :)

@etchegom etchegom force-pushed the poc_libreoffice branch 2 times, most recently from fe1f084 to cb64a55 Compare April 5, 2024 07:45
@etchegom etchegom self-assigned this Apr 9, 2024
@kolok kolok force-pushed the poc_libreoffice branch from cb64a55 to fd17de0 Compare April 16, 2024 10:10
@kolok kolok force-pushed the poc_libreoffice branch from 2fa620b to c759b02 Compare April 19, 2024 09:55
@kolok kolok force-pushed the poc_libreoffice branch from c759b02 to 1727bd7 Compare April 23, 2024 07:10
@kolok kolok merged commit f0bf020 into main Apr 30, 2024
6 checks passed
@kolok kolok deleted the poc_libreoffice branch April 30, 2024 06:35
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants