Skip to content

Commit

Permalink
Fix bootstrap.clean_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
neoformit committed Jan 16, 2025
1 parent ed17518 commit 3372146
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions app/labs/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def create_logo(data, output_dir):

def clean_dir(directory):
"""Delete directories that were created more than 7 days ago."""
for path in directory.iterdir():
if path.is_dir() and path.stat().st_ctime < time.time() - HOURS_1:
shutil.rmtree(path)
if directory.exists():
for path in directory.iterdir():
if path.is_dir() and path.stat().st_ctime < time.time() - HOURS_1:
shutil.rmtree(path)
return directory
7 changes: 4 additions & 3 deletions app/labs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ def post(self, request):
return self.force_download(
request,
zipfile_relpath,
slugify(form.cleaned_data['lab_name']) + '.zip',
filename=slugify(form.cleaned_data['lab_name']) + '.zip',
)
return render(request, 'labs/bootstrap.html', {
'form': form,
}, status=400)

def force_download(self, request, relpath: Path, fname=None):
def force_download(self, request, relpath: Path, filename=None):
if settings.DEBUG:
logger.debug('Returning Django static serve (DEBUG mode)')
logger.debug('Serving file %s' % relpath)
Expand All @@ -118,7 +118,8 @@ def force_download(self, request, relpath: Path, fname=None):
relpath,
settings.INTERNAL_ROOT,
)
response['Content-Disposition'] = "attachment; filename=%s" % fname
response['Content-Disposition'] = (
f"attachment; filename={filename}")
return response

url = settings.INTERNAL_URL + str(relpath).strip('/')
Expand Down

0 comments on commit 3372146

Please sign in to comment.