espenmn
(Espen)
1
tmassman
(Thomas Massmann #BlackLivesMatter)
2
I just took a brief look at https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/resources/browser/styles.py and https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/resources/browser/scripts.py which seems to be the places where the resources are collected. There is the ResourceBase class which can be used as a mixin for your own view which has the required methods (get_resources() and anonymous()).
The anonymous() method is used to attach logged-in.css and logged-in.js when the user is logged in. You could just exclude those entries
There is also the ordered_bundles_result() method which might be helpful.
1 Like
espenmn
(Espen)
3
I am not sure if it can be done that way in Plone 5.0.7 + (I have been struggling with it for a few hours)
The ResourceView is now a viewlet
class ResourceView(ViewletBase):
"""Information for script rendering.
"""
tmassman
(Thomas Massmann #BlackLivesMatter)
4
But then you can still redefine the required methods from that viewlet in your view
espenmn
(Espen)
5
Do you mean "copying all the code" ?
.... would be quite a lot(?), since the styles viewlet is based on the resorce viewlet (and the same with scripts viewlet)
tmassman
(Thomas Massmann #BlackLivesMatter)
6
No, I think all you would need is:
def get_resources(self):
return self.registry.collectionOfInterface(
IResourceRegistry, prefix="plone.resources", check=False)
and
@property
@memoize
def anonymous(self):
return _getAuthenticatedUser(
self.context).getUserName() == 'Anonymous User'
and then
def get_scripts(self):
result = [{
'src': '%s/++plone++%s' % (
self.site_url,
self.production_path + '/default.js'
),
'conditionalcomment': None,
'bundle': 'production'
}, ]
# no need for logged-in resources for you
# ...
# Add manual added resources
if hasattr(self.request, 'enabled_resources'):
resources = self.get_resources()
for resource in self.request.enabled_resources:
if resource in resources:
data = resources[resource]
if data.js:
url = urlparse(data.js)
if url.netloc == '':
# Local
src = "%s/%s" % (self.site_url, data.js)
else:
src = "%s" % (data.js)
data = {
'bundle': 'none',
'conditionalcomment': '', # noqa
'src': src}
result.append(data)
# Add diazo url
origin = None
if self.diazo_production_js and self.development is False:
origin = self.diazo_production_js
if self.diazo_development_js and self.development is True:
origin = self.diazo_development_js
if origin:
result.append({
'bundle': 'diazo',
'conditionalcomment': '',
'src': '%s/%s' % (
self.site_url, origin)
})
return result
Same applied then for the CSS. If you don't need the diazo resources, you can skip that as well.
Edit: You don't need the def anonymous(self)
method.
espenmn
(Espen)
7
Thanks for you help.
I needed to add a bit more.
Got it kind of working... the code looks a bit ugly... but...