~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/template/loaders/eggs.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
    resource_string = None
7
7
 
8
8
from django.template import TemplateDoesNotExist
 
9
from django.template.loader import BaseLoader
9
10
from django.conf import settings
10
11
 
 
12
class Loader(BaseLoader):
 
13
    is_usable = resource_string is not None
 
14
 
 
15
    def load_template_source(self, template_name, template_dirs=None):
 
16
        """
 
17
        Loads templates from Python eggs via pkg_resource.resource_string.
 
18
 
 
19
        For every installed app, it tries to get the resource (app, template_name).
 
20
        """
 
21
        if resource_string is not None:
 
22
            pkg_name = 'templates/' + template_name
 
23
            for app in settings.INSTALLED_APPS:
 
24
                try:
 
25
                    return (resource_string(app, pkg_name).decode(settings.FILE_CHARSET), 'egg:%s:%s' % (app, pkg_name))
 
26
                except:
 
27
                    pass
 
28
        raise TemplateDoesNotExist(template_name)
 
29
 
 
30
_loader = Loader()
 
31
 
11
32
def load_template_source(template_name, template_dirs=None):
12
 
    """
13
 
    Loads templates from Python eggs via pkg_resource.resource_string.
14
 
 
15
 
    For every installed app, it tries to get the resource (app, template_name).
16
 
    """
17
 
    if resource_string is not None:
18
 
        pkg_name = 'templates/' + template_name
19
 
        for app in settings.INSTALLED_APPS:
20
 
            try:
21
 
                return (resource_string(app, pkg_name).decode(settings.FILE_CHARSET), 'egg:%s:%s' % (app, pkg_name))
22
 
            except:
23
 
                pass
24
 
    raise TemplateDoesNotExist, template_name
 
33
    import warnings
 
34
    warnings.warn(
 
35
        "'django.template.loaders.eggs.load_template_source' is deprecated; use 'django.template.loaders.eggs.Loader' instead.",
 
36
        PendingDeprecationWarning
 
37
    )
 
38
    return _loader.load_template_source(template_name, template_dirs)
25
39
load_template_source.is_usable = resource_string is not None