Skip to content

Commit

Permalink
auto create working directory from field
Browse files Browse the repository at this point in the history
  • Loading branch information
scream4ik committed Nov 6, 2016
1 parent 7c0ffe0 commit 2cfb1fe
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion filebrowser/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

# filebrowser imports
from filebrowser.settings import (
URL_FILEBROWSER_MEDIA, ADMIN_THUMBNAIL, DEBUG, EXTENSIONS
URL_FILEBROWSER_MEDIA, ADMIN_THUMBNAIL, DEBUG, EXTENSIONS, MEDIA_ROOT,
DIRECTORY
)
from filebrowser.base import FileObject
from filebrowser.functions import url_to_path, _template
Expand All @@ -29,6 +30,10 @@ def __init__(self, attrs=None):
self.extensions = attrs.get('extensions', '')
self.format = attrs.get('format', '')
super(FileBrowseWidget, self).__init__(attrs)
# if field have a directory - create it
dir_path = os.path.join(MEDIA_ROOT, DIRECTORY, self.directory)
if not os.path.exists(dir_path):
os.makedirs(dir_path)

def render(self, name, value, attrs=None):
if value is None:
Expand Down

0 comments on commit 2cfb1fe

Please sign in to comment.