Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a django template loader for embedded files
- Loading branch information
roberto@debian32
committed
Jul 16, 2011
1 parent
e5f5f40
commit 140a1b1
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from django.template.base import TemplateDoesNotExist | ||
from django.template.loader import BaseLoader | ||
from django.conf import settings | ||
|
||
try: | ||
import uwsgi | ||
on_uwsgi = True | ||
except: | ||
on_uwsgi = False | ||
|
||
|
||
|
||
|
||
class Loader(BaseLoader): | ||
|
||
is_usable = on_uwsgi | ||
|
||
def symbolize(self, name): | ||
return name.replace('.','_').replace('/','_') | ||
|
||
def load_template_source(self, template_name, template_dirs=None): | ||
filename = 'templates_' + self.symbolize(template_name) | ||
for app in settings.INSTALLED_APPS: | ||
try: | ||
symbol = "%s_%s" % (self.symbolize(app), filename) | ||
return (uwsgi.embedded_data(symbol), "sym://%s" % symbol) | ||
except: | ||
pass | ||
raise TemplateDoesNotExist(template_name) |