Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant cache refreshing on ZMI-JS changes #345

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.egg-info/
*.pyc
Products/zms/plugins/www/zms-all.min.js
Products/zms/plugins/www/zms-all.min.js.hash
Products/zms/plugins/www/i18n/*.js
Products/zms/overrides.zcml
.vscode/
Expand Down
12 changes: 12 additions & 0 deletions Products/zms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ def initialize(context):
standard.writeStdout(context, "add %s (Packed: %i -> %i Bytes)"%(fn, l0, l1))
fileobj.write(fc)
fileobj.close()
# Finally create hash value of packed file content:
# a. write it into separate file and
# b. create a configuration parameter
min_fileobj = open(fileobj.name, 'r')
min_hash = standard.encrypt_password(min_fileobj.read(),hex=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use the python builtin hash()-function and hexlify the result?
Password encryption maybe misleading and change its behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min_hash_fileobj = open(fileobj.name + '.hash', 'w')
min_hash_fileobj.write(min_hash)
OFS.misc_.misc_.zms['confdict']['js_min.hash'] = min_hash
standard.writeStdout(context, "add %s" % min_hash_fileobj.name)
min_hash_fileobj.close()
min_fileobj.close()


# automated generation of language JavaScript
from xml.dom import minidom
Expand Down
1 change: 1 addition & 0 deletions Products/zms/_confmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ def getConfPropertiesDefaults(self):
{'key':'jquery.ui','title':'JQuery UI version','desc':'JQuery UI version.','datatype':'string'},
{'key':'jquery.plugin.version','title':'JQuery plugin version','desc':'JQuery plugin version','datatype':'string'},
{'key':'jquery.plugin.extensions','title':'JQuery plugin extensions','desc':'JQuery plugin extensions','datatype':'string'},
{'key':'js_min.hash','title':'Hash value of minified ZMI-Javascript aggregate','desc':'Use hash-value of the minified ZMI-Javascript aggregate file for cache bustering','datatype':'string'},
{'key':'ZMS.blobfields.grant_public_access','title':'Grant public access to blob-fields','desc':'Blob-fields in restricted nodes are not visible. You may grant public access to blob-fields by activating this option.','datatype':'boolean'},
{'key':'ZMS.blobfields.accept_ranges','title':'Http-Header Accept-Ranges for blob-fields','desc':'Http-Header Accept-Ranges for blob-fields.','datatype':'string','default':'bytes'},
{'key':'ZMS.locale.amount.unit','title':'Currency unit for amount-types','desc':'The currency unit used for amount-types.','datatype':'string','default':'EUR'},
Expand Down
4 changes: 3 additions & 1 deletion Products/zms/zpt/common/zmi_html_head.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
</tal:block>
<script type="text/javascript" charset="UTF-8" tal:attributes="src python:'/++resource++zms_/i18n/%s.js'%here.get_manage_lang()"></script>
<tal:block tal:repeat="src python:list(zmi_paths['js_paths'])+[here.getConfProperty(x) for x in here.getConfProperty('bootstrap.libs').split(',')]"
><script type="text/javascript" charset="UTF-8" tal:condition="src" tal:attributes="src src"></script>
><script type="text/javascript" charset="UTF-8" tal:condition="src"
tal:attributes="src python:src.endswith('-all.min.js') and '%s?cache=%s'%(src,here.getConfProperty('js_min.hash')) or src">
</script>
</tal:block>
<script tal:condition="python:here.restrictedTraverse(zmi_js, None)" tal:attributes="src zmi_js" type="text/javascript" charset="UTF-8" defer="defer"></script>
<tal:block tal:condition="python:not standard.get_session_value(here,'did_update_userdata') and 'Manager' not in request.get('AUTHENTICATED_USER').getRoles()">
Expand Down
Loading