5 from django
.conf
import settings
7 localdata
= threading
.local()
8 localdata
.TEMPLATES
= tuple()
9 TEMPLATES
= localdata
.TEMPLATES
12 def autodiscover_templates():
14 Autodiscovers cmsplugin_contact_plus templates the way
15 'django.template.loaders.filesystem.Loader' and
16 'django.template.loaders.app_directories.Loader' work.
18 def sorted_templates(templates
):
22 TEMPLATES
= sorted(templates
, key
=lambda template
: template
[1])
25 # obviously, cache for better performance
30 # override templates from settings
31 override_dir
= getattr(settings
, 'CMSPLUGIN_CONTACT_PLUS_TEMPLATES', None)
33 return sorted_templates(override_dir
)
37 # ('cmsplugin_contact_plus/hello.html', 'hello.html'),
41 if 'django.template.loaders.app_directories.Loader' in settings
.TEMPLATE_LOADERS
:
42 for app
in settings
.INSTALLED_APPS
:
44 dir = os
.path
.dirname(_
.__file__
)
45 if not dir in dirs_to_scan
:
46 # append 'templates' for app directories
47 dirs_to_scan
.append(os
.path
.join(dir, 'templates'))
49 if 'django.template.loaders.filesystem.Loader' in settings
.TEMPLATE_LOADERS
:
50 for dir in settings
.TEMPLATE_DIRS
:
51 if not dir in dirs_to_scan
:
52 # filesystem loader assumes our templates in 'templates'
54 dirs_to_scan
.append(dir)
56 for dir in dirs_to_scan
:
57 found
= glob
.glob(os
.path
.join(dir, 'cmsplugin_contact_plus/*.html'))
59 dir, file = os
.path
.split(file)
60 key
, value
= os
.path
.join(dir.split('/')[-1], file), file
62 for _
, template
in templates
:
66 templates
.append((key
, value
,))
67 # print os.path.basename(file)
69 return sorted_templates(templates
)