Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
acb973e1
Commit
acb973e1
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite clean up task for PDF files to use PDFFile objects
parent
9066d31a
No related branches found
Branches containing commit
Tags
2.0rc7
Tags containing commit
1 merge request
!464
Resolve "Support PDF generation via a headless Chromium running in the background using celery"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/core/util/pdf.py
+9
-7
9 additions, 7 deletions
aleksis/core/util/pdf.py
with
9 additions
and
7 deletions
aleksis/core/util/pdf.py
+
9
−
7
View file @
acb973e1
import
glob
import
os
import
subprocess
# noqa
from
tempfile
import
TemporaryDirectory
...
...
@@ -12,6 +11,7 @@ from django.shortcuts import get_object_or_404, render
from
django.template.loader
import
render_to_string
from
django.test
import
override_settings
from
django.urls
import
reverse
from
django.utils
import
timezone
from
django.utils.translation
import
get_language
from
django.utils.translation
import
gettext
as
_
...
...
@@ -19,7 +19,6 @@ from celery_progress.backend import ProgressRecorder
from
aleksis.core.celery
import
app
from
aleksis.core.models
import
PDFFile
from
aleksis.core.settings
import
MEDIA_ROOT
from
aleksis.core.util.celery_progress
import
recorded_task
...
...
@@ -117,9 +116,12 @@ def render_pdf(request: HttpRequest, template_name: str, context: dict = None) -
return
render
(
request
,
"
core/pages/progress.html
"
,
context
)
def
clean_up_expired_pdf_files
()
->
None
:
"""
Clean up expired PDF files.
"""
PDFFile
.
objects
.
filter
(
expires_at__lt
=
timezone
.
now
()).
delete
()
@app.task
def
clean_up_pdf_directory
()
->
None
:
"""
Clean up directory with generated PDF files.
"""
files
=
glob
.
glob
(
os
.
path
.
join
(
MEDIA_ROOT
,
"
pdfs
"
,
"
*.pdf
"
))
for
file
in
files
:
os
.
remove
(
file
)
def
clean_up_expired_pdf_files_task
()
->
None
:
"""
Clean up expired PDF files.
"""
return
clean_up_expired_pdf_files
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment