1 from django.conf import settings
 
   2 from django.template import loader
 
   3 from django.template.loaders import filesystem 
 
   4 from django.http import HttpResponse
 
   8 #module for skinning osqa
 
   9 #at this point skin can be changed only in settings file
 
  10 #via OSQA_DEFAULT_SKIN variable
 
  12 #note - Django template loaders use method django.utils._os.safe_join
 
  13 #to work on unicode file paths
 
  14 #here it is ignored because it is assumed that we won't use unicode paths
 
  16 def load_template_source(name, dirs=None):
 
  18         tname = os.path.join(settings.OSQA_DEFAULT_SKIN,'templates',name)
 
  19         return filesystem.load_template_source(tname,dirs)
 
  21         tname = os.path.join('default','templates',name)
 
  22         return filesystem.load_template_source(tname,dirs)
 
  23 load_template_source.is_usable = True
 
  25 def find_media_source(url):
 
  26     """returns url prefixed with the skin name
 
  27     of the first skin that contains the file 
 
  28     directories are searched in this order:
 
  29     settings.OSQA_DEFAULT_SKIN, then 'default', then 'commmon'
 
  30     if file is not found - returns None
 
  31     and logs an error message
 
  33     while url[0] == '/': url = url[1:]
 
  38     skins = n(j(d(d(__file__)),'skins'))
 
  40         media = os.path.join(skins, settings.OSQA_DEFAULT_SKIN, url)
 
  42         use_skin = settings.OSQA_DEFAULT_SKIN
 
  45             media = j(skins, 'default', url)
 
  49             media = j(skins, 'common', url)
 
  54                 logging.error('could not find media for %s' % url)
 
  57     return use_skin + '/' + url