Fix various issues with compressed angular templates and plugins

First, retrieve current theme only in cases when it already has been
provided in the context. That should prevent missing 'THEME' errors
when post_compress signal is being processed, for example inside
_stylesheets.html which does not provide THEME var into the rendering
context.

Second, under certain circumstances, offline compression was producing
a different hash for compressed angular templates than runtime
template renderer was expecting. Make the combined template with all
angular templates be a deterministic - convert it from a dictionary to
a list of key-value tuples. Various order of dictionary entries in
offline and online compress phases seemed to produce 'missing compress
hash key' error.

Closed-Bug: #1603307
Change-Id: Idb48c3f68da43bba33033a71e6d69bdc112736de
This commit is contained in:
Timur Sufiev 2016-08-24 15:46:43 +03:00
parent 626f6fc675
commit 9445d15cd1
2 changed files with 7 additions and 4 deletions

View File

@ -33,7 +33,6 @@ def update_angular_template_hash(sender, **kwargs):
clients.
"""
context = kwargs['context'] # context the compressor is working with
theme = context['THEME'] # current theme being compressed
compressed = context['compressed'] # the compressed content
compressed_name = compressed['name'] # name of the compressed content
if compressed_name == 'angular_template_cache_preloads':
@ -43,6 +42,7 @@ def update_angular_template_hash(sender, **kwargs):
# generate the same key as used in _scripts.html when caching the
# preloads
theme = context['THEME'] # current theme being compressed
key = make_template_fragment_key(
"angular",
['template_cache_preloads', theme]
@ -115,6 +115,9 @@ def angular_templates(context):
# there will simply be no pre-loaded version for this template.
pass
templates = [(key, value) for key, value in angular_templates.items()]
templates.sort(key=lambda item: item[0])
return {
'angular_templates': angular_templates
'angular_templates': templates
}

View File

@ -1,5 +1,5 @@
{% for static_path, template_html in angular_templates.items %}
{% for static_path, template_html in angular_templates %}
<script type='text/javascript' id='{{ static_path }}'>
{% include 'angular/angular_templates.js' %}
</script>
{% endfor %}
{% endfor %}