Skip to content

Commit

Permalink
Merge pull request #103 from uclouvain/OSIS-8819
Browse files Browse the repository at this point in the history
OSIS-8819: Suppression des documents physiques après expiration
  • Loading branch information
albrugnetti authored Jan 9, 2024
2 parents 0099098 + b3ddbb7 commit 0da2ae6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions osis_document/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The core business involves the administration of students, teachers,
# courses, programs and so on.
#
# Copyright (C) 2015-2021 Université catholique de Louvain (http://www.uclouvain.be)
# Copyright (C) 2015-2024 Université catholique de Louvain (http://www.uclouvain.be)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -23,6 +23,7 @@
# see http://www.gnu.org/licenses/.
#
# ##############################################################################
import os
from datetime import timedelta

from django.conf import settings
Expand All @@ -44,15 +45,19 @@ def cleanup_old_uploads():
# Clean Upload which are stale 2 case:
# - State "REQUESTED" and delay in temporary storage expired (= Upload not confirm by client)
# - Upload expired (= Storage delay expired - XLS export, PDF one time generation, ...)
Upload.objects.filter(
upload_expired_qs = Upload.objects.filter(
Q(
status=FileStatus.REQUESTED.name,
uploaded_at__lte=now() - timedelta(seconds=settings.OSIS_DOCUMENT_TEMP_UPLOAD_MAX_AGE)
) |
Q(
expires_at__lte=now()
),
).delete()
)
files_expired = [upload_expired.file for upload_expired in upload_expired_qs]
upload_expired_qs.delete()
for file in files_expired:
file.delete(save=False)

# Clean Token expired
Token.objects.filter(expires_at__lte=now()).delete()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The core business involves the administration of students, teachers,
# courses, programs and so on.
#
# Copyright (C) 2015-2023 Université catholique de Louvain (http://www.uclouvain.be)
# Copyright (C) 2015-2024 Université catholique de Louvain (http://www.uclouvain.be)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -27,7 +27,7 @@

setup(
name='OSIS Document',
version='0.9.11',
version='0.9.12',
description='Document management API and widget',
url='http://github.com/uclouvain/osis-document',
author='Université catholique de Louvain',
Expand Down

0 comments on commit 0da2ae6

Please sign in to comment.