Skip to content

Commit

Permalink
add setting to include date in upload path
Browse files Browse the repository at this point in the history
  • Loading branch information
goapunk committed Nov 9, 2023
1 parent fc64e17 commit 588ef95
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions django_ckeditor_5/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pathlib

from datetime import datetime
from django import get_version
from django.http import Http404
from django.utils.module_loading import import_string
Expand Down Expand Up @@ -56,9 +57,13 @@ def image_verify(f):

def handle_uploaded_file(user, f):
fs = storage()
path = f.name
path = ''
if getattr(settings, "CKEDITOR_5_PATH_FROM_USERNAME", False):
path = pathlib.PurePath(user.username, f.name)
path = pathlib.PurePath(path, user.username)
if getattr(settings, "CKEDITOR5_RESTRICT_BY_DATE", True):
date_path = datetime.now().strftime("%Y/%m/%d")
path = pathlib.PurePath(path, date_path)
path = pathlib.PurePath(path, f.name)
filename = fs.save(path, f)
return fs.url(filename)

Expand Down

0 comments on commit 588ef95

Please sign in to comment.