1. Dan Connolly
  2. quacken

Commits

Dan Connolly http://www.w3.org/People/Connolly/  committed 968dc22

provide MEDIA_URL to templates from views

  • Participants
  • Parent commits 22a34f9
  • Branches default

Comments (0)

Files changed (2)

File qfm/urls.py

View file
  • Ignore whitespace
-from django.conf.urls.defaults import * #@@ ew import *
+from django.conf.urls.defaults import patterns
+from django.conf import settings
 
 urlpatterns = patterns('',
     (r'^$', 'dm93data.qfm.views.accounts'),
     (r'^register/(?P<acct_id>\d+)', 'dm93data.qfm.views.register'),
     (r'^export', 'dm93data.qfm.views.export'),
 )
+
+if settings.DEBUG:
+    urlpatterns += patterns('',
+        (r'^media/(?P<path>.*)$', 'django.views.static.serve',
+         {'document_root': settings.MEDIA_ROOT}),
+    )

File qfm/views.py

View file
  • Ignore whitespace
 from django.shortcuts import render_to_response
 from dm93data.qfm.models import Account, Transaction
 from django.http import HttpResponse
-from django.template import loader
+from django.template import loader, RequestContext
+from django.utils import simplejson
 
 def accounts(request):
     accounts = Account.objects.filter(kind="AL")
         return a.modified
     accounts = sorted(accounts, key=byDate, reverse=True)
     return render_to_response('accounts.html',
-                              {'accounts': accounts})
+                              {'accounts': accounts},
+                              context_instance=media_too(request)
+                              )
+
+
+def media_too(request):
+    # django 0.96 doesn't yet have django.core.context_processors.media
+    # so we do it manually..
+
+    from django.conf import settings
+    return RequestContext(request, {"MEDIA_URL": settings.MEDIA_URL})
 
 def register(request, acct_id):
     account = Account.objects.get(id=int(acct_id))
         bal += amount
         t.amount = amount
         t.balance = bal
+
     return render_to_response('register.html',
                               {'account': account,
                                'balance': bal,
-                               'transactions': transactions})
+                               'transactions': transactions},
+                              context_instance=media_too(request)
+                              )
 
 def asDate(s):
     y = int(s[:4])