Permalink
Browse files

Support server static media from other applications

  • Loading branch information...
1 parent 315a449 commit 9723689f224c65ed522d5eb9be2fc623165e7e98 @dcramer dcramer committed Aug 29, 2012
@@ -6,7 +6,7 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="robots" content="NONE,NOARCHIVE">
- <link href="{% url sentry-media "styles/global.min.css" %}" rel="stylesheet" type="text/css"/>
+ <link href="{% url sentry-media "sentry" "styles/global.min.css" %}" rel="stylesheet" type="text/css"/>
<title>{% block title %}Sentry{% endblock %}</title>
{% block meta %}
{% endblock %}
@@ -7,13 +7,13 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="robots" content="NONE,NOARCHIVE">
- <link href="{% url sentry-media "styles/global.min.css" %}" rel="stylesheet" type="text/css"/>
- <link href="{% url sentry-media "images/favicon.png" %}" rel="shortcut icon" type="image/png"/>
+ <link href="{% url sentry-media "sentry" "styles/global.min.css" %}" rel="stylesheet" type="text/css"/>
+ <link href="{% url sentry-media "sentry" "images/favicon.png" %}" rel="shortcut icon" type="image/png"/>
<title>{% block title %}Sentry{% endblock %}</title>
{% if USE_JS_CLIENT %}
- <script type="text/javascript" src="{% url sentry-media "scripts/client.js" %}"></script>
+ <script type="text/javascript" src="{% url sentry-media "sentry" "scripts/client.js" %}"></script>
<script type="text/javascript">
Sentry.client.config({
server: '{% url sentry-api-store %}',
@@ -25,19 +25,19 @@
{% endif %}
<!--[if lt IE 9]>
- <script type="text/javascript" src="{% url sentry-media "scripts/html5shiv.js" %}"></script>
+ <script type="text/javascript" src="{% url sentry-media "sentry" "scripts/html5shiv.js" %}"></script>
<![endif]-->
- <script type="text/javascript" src="{% url sentry-media "scripts/jquery.js" %}"></script>
- <script type="text/javascript" src="{% url sentry-media "scripts/jquery.clippy.min.js" %}"></script>
- <script type="text/javascript" src="{% url sentry-media "scripts/jquery.flot.min.js" %}"></script>
- <script type="text/javascript" src="{% url sentry-media "scripts/jquery.animate-colors-min.js" %}"></script>
- <script type="text/javascript" src="{% url sentry-media "scripts/global.min.js" %}"></script>
+ <script type="text/javascript" src="{% url sentry-media "sentry" "scripts/jquery.js" %}"></script>
+ <script type="text/javascript" src="{% url sentry-media "sentry" "scripts/jquery.clippy.min.js" %}"></script>
+ <script type="text/javascript" src="{% url sentry-media "sentry" "scripts/jquery.flot.min.js" %}"></script>
+ <script type="text/javascript" src="{% url sentry-media "sentry" "scripts/jquery.animate-colors-min.js" %}"></script>
+ <script type="text/javascript" src="{% url sentry-media "sentry" "scripts/global.min.js" %}"></script>
<script type="text/javascript">
Sentry.config({
urlPrefix: {{ URL_PREFIX|to_json|safe }},
- mediaUrl: '{% url sentry-media '' %}',
- defaultImage: '{% url sentry-media 'images/sentry.png' %}',
- popupCss: '{% url sentry-media 'styles/popup.css' %}'
+ mediaUrl: '{% url sentry-media "sentry" '' %}',
+ defaultImage: '{% url sentry-media "sentry" 'images/sentry.png' %}',
+ popupCss: '{% url sentry-media "sentry" 'styles/popup.css' %}'
});
</script>
@@ -110,11 +110,11 @@ <h3></h3>
</div>
</div>
- <script type="text/javascript" src="{% url sentry-media "scripts/bootstrap.min.js" %}"></script>
+ <script type="text/javascript" src="{% url sentry-media "sentry" "scripts/bootstrap.min.js" %}"></script>
<script type="text/javascript">
$(function(){
$('.clippy').clippy({
- clippy_path: '{% url sentry-media "clippy.swf" %}',
+ clippy_path: '{% url sentry-media "sentry" "clippy.swf" %}',
keep_text: true
});
$('.tip').tooltip();
@@ -3,7 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="robots" content="NONE,NOARCHIVE">
- <link href="{% url sentry-media "images/sentry.png" %}" rel="shortcut icon"/>
+ <link href="{% url sentry-media "sentry" "images/sentry.png" %}" rel="shortcut icon"/>
<style type="text/css">
html * { padding:0; margin:0; }
body * * { padding:0; }
@@ -10,7 +10,7 @@
<p>{% blocktrans %}Add the any URLs which will be logging errors in your project's settings under <a href="{{ project_link }}#client-security">Client Security</a>:{% endblocktrans %}</p>
-<div class="image"><img src="{% url sentry-media "images/client_security.png" %}"></div>
+<div class="image"><img src="{% url sentry-media "sentry" "images/client_security.png" %}"></div>
<p>{% trans "Configure the client:" %}</p>
@@ -15,6 +15,8 @@
from sentry.web.helpers import get_login_url, get_project_list, \
render_to_response
+STATIC_PATH_CACHE = {}
+
@login_required
def dashboard(request):
@@ -31,7 +33,7 @@ def dashboard(request):
return render_to_response('sentry/dashboard.html', {}, request)
-def static_media(request, path, root=None):
+def static_media(request, module, path, root=None):
"""
Serve static files below a given point in the directory structure.
"""
@@ -43,7 +45,21 @@ def static_media(request, path, root=None):
import stat
import urllib
- document_root = root or os.path.join(settings.MODULE_ROOT, 'static')
+ if root:
+ document_root = root
+ elif module == 'sentry':
+ document_root = os.path.join(settings.MODULE_ROOT, 'static')
+ elif module not in settings.INSTALLED_APPS:
+ raise Http404('Invalid module provided.')
+ else:
+ if module not in STATIC_PATH_CACHE:
+ try:
+ STATIC_PATH_CACHE[module] = __import__(module)
+ except ImportError:
+ raise Http404('Import error raised while fetching module')
+
+ mod = STATIC_PATH_CACHE[module]
+ document_root = os.path.normpath(os.path.join(os.path.dirname(mod.__file__), 'media'))
path = posixpath.normpath(urllib.unquote(path))
path = path.lstrip('/')
@@ -62,7 +78,7 @@ def static_media(request, path, root=None):
return HttpResponseRedirect(newpath)
fullpath = os.path.join(document_root, newpath)
if os.path.isdir(fullpath):
- raise Http404("Directory indexes are not allowed here.")
+ raise Http404('Directory indexes are not allowed here.')
if not os.path.exists(fullpath):
raise Http404('"%s" does not exist' % fullpath)
# Respect the If-Modified-Since header.
@@ -73,6 +89,6 @@ def static_media(request, path, root=None):
return HttpResponseNotModified(mimetype=mimetype)
contents = open(fullpath, 'rb').read()
response = HttpResponse(contents, mimetype=mimetype)
- response["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
- response["Content-Length"] = len(contents)
+ response['Last-Modified'] = http_date(statobj[stat.ST_MTIME])
+ response['Content-Length'] = len(contents)
return response
View
@@ -32,7 +32,7 @@ def init_all_applications():
init_all_applications()
urlpatterns = patterns('',
- url(r'^_static/(?P<path>.*)$', generic.static_media, name='sentry-media'),
+ url(r'^_static/(?P<module>[^/]+)/(?P<path>.*)$', generic.static_media, name='sentry-media'),
# Legacy API
url(r'^store/$', api.store),

0 comments on commit 9723689

Please sign in to comment.