Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cms_example: working file browser+dynamicsites

  • Loading branch information...
commit ad36c701be1df19edd1d933b1e796282f0d01c74 1 parent 951706e
@wardi authored
View
0  cms_example/media/uploads/.placeholder
No changes.
View
23 cms_example/middleware.py
@@ -0,0 +1,23 @@
+import os
+
+from filebrowser.conf import FileBrowserSettings, fb_settings
+from filebrowser.settings import DIRECTORY
+from dynamicsiteslite.utils import make_tls_property
+
+FB_DIR = FileBrowserSettings.DIRECTORY = make_tls_property(DIRECTORY)
+
+class DynamicFileBrowserMiddleware(object):
+ """
+ Add the dynamicsites directory to the uploads directory setting
+
+ e.g. 'uploads/' becomes 'uploads/some_host_example_com/'
+
+ if this directory doesn't exist then create it.
+ """
+ def process_request(self, request):
+ FB_DIR.value = DIRECTORY + request.dynamicsites_folder_name + '/'
+
+ abs_path = os.path.join(fb_settings.MEDIA_ROOT, fb_settings.DIRECTORY)
+ if not os.path.isdir(abs_path):
+ os.mkdir(abs_path)
+
View
9 cms_example/settings.py
@@ -49,22 +49,22 @@
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
-MEDIA_ROOT = ''
+MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
-MEDIA_URL = ''
+MEDIA_URL = '/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
-STATIC_ROOT = ''
+STATIC_ROOT = os.path.join(PROJECT_DIR, 'media/static/')
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
-STATIC_URL = '/static/'
+STATIC_URL = '/media/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
@@ -114,6 +114,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'dynamicsiteslite.middleware.DynamicSitesMiddleware',
+ 'cms_example.middleware.DynamicFileBrowserMiddleware',
)
ROOT_URLCONF = 'cms_example.urls'
View
2  cms_example/urls.py
@@ -1,7 +1,7 @@
from django.conf.urls.defaults import patterns, include, url
-
from django.contrib import admin
+# make filebrowser item appear in admin index:
admin.site.index_template = 'admin/index_filebrowser.html'
admin.autodiscover()
View
1  dynamicsiteslite/middleware.py
@@ -99,6 +99,7 @@ def process_request(self, request):
os.path.join(settings.SITES_DIR, folder_name, 'templates'))
TEMPLATE_DIRS.value = (os.path.join(settings.SITES_DIR,
folder_name, 'templates'),) + TEMPLATE_DIRS.value
+ request.dynamicsites_folder_name = folder_name
return res
Please sign in to comment.
Something went wrong with that request. Please try again.