Skip to content
This repository was archived by the owner on Jun 20, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nexus/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

if getattr(settings, 'NEXUS_USE_DJANGO_MEDIA_URL', False):
MEDIA_PREFIX = getattr(settings, 'MEDIA_URL', MEDIA_PREFIX)

USE_STATICFILES = getattr(settings, 'NEXUS_USE_STATICFILES', False)
3 changes: 3 additions & 0 deletions nexus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
raise ImproperlyConfigured("Put '%s' in your "
"INSTALLED_APPS setting in order to use the nexus application." % r)

# XXX but we needed registered nexus modules to update
# STATICFILES_DIRS setting for collectstatic command
__import__(settings.ROOT_URLCONF)
18 changes: 18 additions & 0 deletions nexus/sites.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Core site concept heavily inspired by django.contrib.sites

from django.conf import settings
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseNotModified, Http404
Expand All @@ -12,6 +13,10 @@
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.views.static import was_modified_since
try:
from django.contrib.staticfiles.views import serve
except ImportError: # django<1.3
serve = None

from nexus import conf

Expand Down Expand Up @@ -73,6 +78,16 @@ def register(self, module, namespace=None, category=None):
namespace = module.get_namespace()
if namespace:
module.app_name = module.name = namespace
if conf.USE_STATICFILES and os.path.exists(module.media_root):
static_prefix = namespace if namespace != 'admin' else 'nexus'
nexus_static = (
(static_prefix, module.media_root),
)
if isinstance(settings.STATICFILES_DIRS, tuple):
settings.STATICFILES_DIRS += nexus_static
else:
settings.STATICFILES_DIRS.extends(nexus_static)

self._registry[namespace] = (module, category)
return module

Expand Down Expand Up @@ -205,6 +220,9 @@ def media(self, request, module, path):
"""
Serve static files below a given point in the directory structure.
"""
if conf.USE_STATICFILES and serve:
return serve(path='%s/%s' % (module, path))

if module == 'nexus':
document_root = os.path.join(NEXUS_ROOT, 'media')
else:
Expand Down
3 changes: 3 additions & 0 deletions nexus/templatetags/nexus_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django import template
from django.conf import settings
from django.utils.datastructures import SortedDict

import nexus
Expand All @@ -9,6 +10,8 @@


def nexus_media_prefix():
if conf.USE_STATICFILES:
return settings.STATIC_URL.rstrip('/')
return conf.MEDIA_PREFIX.rstrip('/')
register.simple_tag(nexus_media_prefix)

Expand Down