Permalink
Browse files

added a context processor to expose the current site

  • Loading branch information...
1 parent c0e3388 commit 8b31b6d3d26ef7d52689b8ccf0ce8d5dbbd9a357 @sontek sontek committed Oct 31, 2010
Showing with 14 additions and 0 deletions.
  1. +14 −0 tekextensions/context_processors.py
@@ -1,4 +1,18 @@
from django.conf import settings
+from django.contrib.sites.models import Site, RequestSite
def admin_media_prefix(request):
return {'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX }
+
+def current_site(request):
+ '''
+ A context processor to add the "current_site" to the current Context
+ '''
+ context_name = 'CURRENT_SITE'
+
+ try:
+ current_site = Site.objects.get_current()
+ return { name: current_site, }
+ except Site.DoesNotExist:
+ # always return a dict, no matter what!
+ return {name: RequestSite(request)}

0 comments on commit 8b31b6d

Please sign in to comment.