本文整理汇总了Python中plone.portlets.interfaces.IPortletAssignmentSettings类的典型用法代码示例。如果您正苦于以下问题:Python IPortletAssignmentSettings类的具体用法?Python IPortletAssignmentSettings怎么用?Python IPortletAssignmentSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPortletAssignmentSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: toggle_visibility
def toggle_visibility(self, name):
self.authorize()
assignments = aq_inner(self.context)
settings = IPortletAssignmentSettings(assignments[name])
visible = settings.get('visible', True)
settings['visible'] = not visible
return self.finish_portlet_change()
示例2: getPortlets
def getPortlets(self):
if IPortletContext.providedBy(self.context):
pcontext = self.context
else:
pcontext = queryAdapter(self.context, IPortletContext)
if pcontext is None:
return []
assignments = []
for category, key in pcontext.globalPortletCategories(True):
mapping = self.storage.get(category, None)
if mapping is not None:
for assignment in mapping.get(key, {}).values():
try:
settings = IPortletAssignmentSettings(assignment)
except Exception:
logException(u'Error during retrieving assignment '
'settings. Context: "%s", Category: "%s", Key: '
'"%s", Assignment Class: "%s", Assignment ID: "%s"'
% ('/'.join(self.context.getPhysicalPath()),
category, key, str(assignment.__class__),
assignment.__name__), context=self.context)
continue
if not settings.get('visible', True):
continue
assignments.append({'category': category,
'key': key,
'name': assignment.__name__,
'assignment': assignment
})
return assignments
示例3: test_should_remove_tag_if_context_can_not_be_found
def test_should_remove_tag_if_context_can_not_be_found(self):
portal = self.layer['portal']
rightcol = getUtility(IPortletManager, name=u'plone.rightcolumn', context=portal)
right = getMultiAdapter((portal, rightcol,), IPortletAssignmentMapping, context=portal)
staticportlet = static.Assignment(header=u"Static Portlet", text=u"TEXT INPUT")
right[u'staticportlet'] = staticportlet
settings = IPortletAssignmentSettings(staticportlet)
visible = settings.get('visible', True)
settings['visible'] = False
class FakeContent:
def UID(self): return '1'
page = portal[portal.invokeFactory('Document', 'testpage')]
hash = portletHash(rightcol, staticportlet, FakeContent())
field = page.getField('text')
portletmarkup = portletMarkup(hash)
field.set(page, portletmarkup, mimetype='text/html')
page.setTitle('Blah')
page.reindexObject()
transaction.commit()
self.browser.open('http://nohost/plone/testpage')
self.failUnless("TEXT INPUT" not in self.browser.contents)
self.failUnless('<img class="TINYMCEPORTLET mce-only' not in self.browser.contents)
示例4: extractMapping
def extractMapping(manager_name, category, key, mapping):
for name, assignment in mapping.items():
type_ = None
for schema in providedBy(assignment).flattened():
type_ = portletSchemata.get(schema, None)
if type_ is not None:
break
if type_ is not None:
child = self._doc.createElement('assignment')
child.setAttribute('manager', manager_name)
child.setAttribute('category', category)
child.setAttribute('key', key)
child.setAttribute('type', type_)
child.setAttribute('name', name)
assignment = assignment.__of__(mapping)
settings = IPortletAssignmentSettings(assignment)
visible = settings.get('visible', True)
child.setAttribute('visible', repr(visible))
handler = IPortletAssignmentExportImportHandler(assignment)
handler.export_assignment(schema, self._doc, child)
fragment.appendChild(child)
示例5: getPortlets
def getPortlets(self):
if IPortletContext.providedBy(self.context):
pcontext = self.context
else:
pcontext = queryAdapter(self.context, IPortletContext)
if pcontext is None:
return []
assignments = []
for category, key in pcontext.globalPortletCategories(True):
mapping = self.storage.get(category, None)
if mapping is not None:
for assignment in mapping.get(key, {}).values():
try:
settings = IPortletAssignmentSettings(assignment)
except TypeError:
# Portlet does not exist any longer
continue
else:
if not settings.get('visible', True):
continue
assignments.append({'category': category,
'key': key,
'name': assignment.__name__,
'assignment': assignment
})
return assignments
示例6: toggle_visibility
def toggle_visibility(self, name):
assignments = aq_inner(self.context)
settings = IPortletAssignmentSettings(assignments[name])
visible = settings.get('visible', True)
settings['visible'] = not visible
self.request.response.redirect(self._nextUrl())
return ''
示例7: testAssignmentSettings
def testAssignmentSettings(self):
mapping = assignment_mapping_from_key(self.portal,
manager_name=u"test.testcolumn", category=CONTEXT_CATEGORY, key="/")
assignment = mapping['test.portlet1']
settings = IPortletAssignmentSettings(assignment)
self.assertTrue(settings.get('visible', True))
assignment = mapping['test.portlet2']
settings = IPortletAssignmentSettings(assignment)
self.assertFalse(settings.get('visible', True))
示例8: toggle_visibility
def toggle_visibility(self, portlethash, viewname):
info = unhashPortletInfo(portlethash)
assignments = assignment_mapping_from_key(self.context,
info['manager'], info['category'], info['key'])
IPortletPermissionChecker(assignments.__of__(aq_inner(self.context)))()
assignment = assignments[info['name']]
settings = IPortletAssignmentSettings(assignment)
visible = settings.get('visible', True)
settings['visible'] = not visible
return self._render_column(info, viewname)
示例9: portlets
def portlets(self):
data = {}
portlet_managers = getUtilitiesFor(IPortletManager, context=self.context)
for (name, manager) in portlet_managers:
mapping = getMultiAdapter((self.context, manager), IPortletAssignmentMapping)
for (id, assignment) in mapping.items():
renderer = getMultiAdapter(
(
self.context,
self.request,
self,
manager,
assignment
),
IPortletRenderer
)
if renderer.__of__(self.context).available:
try:
settings = IPortletAssignmentSettings(assignment)
visible = settings.get('visible', True)
except TypeError:
visible = False
if visible:
if not data.has_key(name):
data[name] = []
config = dict(assignment.__dict__)
for k in config.keys():
if k.startswith('__') or k in ('assignment_context_path',):
del config[k]
data[name].append({
'id' : id,
'klass' : assignment.__class__.__module__,
'title' : assignment.title,
'config' : config,
})
return data
示例10: test_invoke_edit_form
def test_invoke_edit_form(self):
mapping = PortletAssignmentMapping()
request = self.folder.REQUEST
mapping['foo'] = news.Assignment(count=5)
editview = getMultiAdapter((mapping['foo'], request), name='edit')
editview.update()
editview.applyChanges(data={'count': 6,
EXTENDER_PREFIX+'.css_class': 'my-class'})
portlet_assignment = mapping.values()[0]
settings = IPortletAssignmentSettings(portlet_assignment)
self.assertEqual(portlet_assignment.count, 6)
# We have not extended our storage adapter, so nothing gets saved:
self.assertIsNone(settings.get('css_class', None))
# Register our schemaextender
gsm = getGlobalSiteManager()
gsm.registerAdapter(PortletCssClassAdapter,
(IPortletAssignment,))
gsm.registerAdapter(PortletCssClassFormExtender,
(Interface,
IDefaultBrowserLayer,
IPortletEditForm),
IFormExtender,
'portletcssclass.extender')
mapping = PortletAssignmentMapping()
request = self.folder.REQUEST
mapping['foo'] = news.Assignment(count=5)
editview = getMultiAdapter((mapping['foo'], request), name='edit')
editview.update()
editview.applyChanges(data={'count': 6,
EXTENDER_PREFIX+'.css_class': 'my-class'})
portlet_assignment = mapping.values()[0]
settings = IPortletAssignmentSettings(portlet_assignment)
gsm.unregisterAdapter(PortletCssClassFormExtender,
(Interface,
IDefaultBrowserLayer,
IPortletEditForm),
IFormExtender,
'portletcssclass.extender')
gsm.unregisterAdapter(PortletCssClassAdapter,
(IPortletAssignment,))
self.assertEqual(portlet_assignment.count, 6)
# The prefix is used for the form field, not for the stored data:
self.assertEqual(settings.get('css_class'), 'my-class')
示例11: test_invoke_add_form
def test_invoke_add_form(self):
portlet = getUtility(IPortletType, name='portlets.News')
mapping = self.portal.restrictedTraverse(
'++contextportlets++plone.leftcolumn')
for m in mapping.keys():
del mapping[m]
addview = mapping.restrictedTraverse('+/' + portlet.addview)
addview.update()
addview.createAndAdd(data={'count': 5,
EXTENDER_PREFIX+'.css_class': 'my-class'})
portlet_assignment = mapping.values()[0]
settings = IPortletAssignmentSettings(portlet_assignment)
self.assertEqual(portlet_assignment.count, 5)
# We have not extended our storage adapter, so nothing gets saved:
self.assertIsNone(settings.get('css_class', None))
# Register our schemaextender
gsm = getGlobalSiteManager()
gsm.registerAdapter(PortletCssClassAdapter,
(IPortletAssignment,))
gsm.registerAdapter(PortletCssClassFormExtender,
(Interface,
IDefaultBrowserLayer,
IPortletAddForm),
IFormExtender,
'portletcssclass.extender')
for m in mapping.keys():
del mapping[m]
addview = mapping.restrictedTraverse('+/' + portlet.addview)
addview.update()
addview.createAndAdd(data={'count': 5,
EXTENDER_PREFIX+'.css_class': 'my-class'})
portlet_assignment = mapping.values()[0]
settings = IPortletAssignmentSettings(portlet_assignment)
gsm.unregisterAdapter(PortletCssClassFormExtender,
(Interface,
IDefaultBrowserLayer,
IPortletAddForm),
IFormExtender,
'portletcssclass.extender')
gsm.unregisterAdapter(PortletCssClassAdapter,
(IPortletAssignment,))
self.assertEqual(portlet_assignment.count, 5)
# The prefix is used for the form field, not for the stored data:
self.assertEqual(settings.get('css_class'), 'my-class')
示例12: portlets_for_assignments
def portlets_for_assignments(self, assignments, manager, base_url):
category = self.__parent__.category
key = self.__parent__.key
data = []
for idx in range(len(assignments)):
name = assignments[idx].__name__
if hasattr(assignments[idx], '__Broken_state__'):
name = assignments[idx].__Broken_state__['__name__']
editview = queryMultiAdapter(
(assignments[idx], self.request), name='edit', default=None)
if editview is None:
editviewName = ''
else:
editviewName = '%s/%s/edit' % (base_url, name)
settingsviewName = '%s/%s/edit-portlet-metadata' % (base_url, name)
portlet_hash = hashPortletInfo(
dict(manager=manager.__name__, category=category,
key=key, name=name,))
try:
settings = IPortletAssignmentSettings(assignments[idx])
visible = settings.get('visible', True)
except TypeError:
visible = False
data.append({
'title': assignments[idx].title,
'editview': editviewName,
'hash': portlet_hash,
'name': name,
'up_url': '%s/@@move-portlet-up' % (base_url),
'down_url': '%s/@@move-portlet-down' % (base_url),
'delete_url': '%s/@@delete-portlet' % (base_url),
'metadata_url': settingsviewName,
'hide_url': '%s/@@toggle-visibility' % (base_url),
'show_url': '%s/@@toggle-visibility' % (base_url),
'visible': visible,
})
if len(data) > 0:
data[0]['up_url'] = data[-1]['down_url'] = None
return data
示例13: portlets_for_assignments
def portlets_for_assignments(self, assignments, manager, base_url):
category = self.__parent__.category
key = self.__parent__.key
portal = self.context.portal_url.getPortalObject()
view = portal.restrictedTraverse('@@plone')
data = []
for idx in range(len(assignments)):
name = assignments[idx].__name__
editview = queryMultiAdapter(
(assignments[idx], self.request), name='edit', default=None)
if editview is None:
editviewName = ''
else:
editviewName = '%s/%s/edit' % (base_url, name)
portlet_hash = hashPortletInfo(
dict(manager=manager.__name__, category=category,
key=key, name=name,))
settings = IPortletAssignmentSettings(assignments[idx])
renderer = getMultiAdapter(
(self.context, self.request, view,
manager, assignments[idx]),
IPortletRenderer)
data.append({
'title' : assignments[idx].title,
'editview' : editviewName,
'hash' : portlet_hash,
'renderer' : renderer.__of__(self.context),
'up_url' : '%s/@@move-portlet-up?name=%s' % (base_url, name),
'down_url' : '%s/@@move-portlet-down?name=%s' % (base_url, name),
'delete_url' : '%s/@@delete-portlet?name=%s' % (base_url, name),
'hide_url' : '%s/@@toggle-visibility?name=%s' % (base_url, name),
'show_url' : '%s/@@toggle-visibility?name=%s' % (base_url, name),
'visible' : settings.get('visible', True),
})
if len(data) > 0:
data[0]['up_url'] = data[-1]['down_url'] = None
return data
示例14: __call__
def __call__(self):
# The parent object is the Plone content object here; we get
# it from the acquisition chain.
parent = self.context.aq_inner.aq_parent.aq_parent
panel = self.context
portlets = []
for assignment in panel:
settings = IPortletAssignmentSettings(assignment)
if not settings.get('visible', True):
continue
try:
portlet = getMultiAdapter(
(parent,
self.request,
self,
panel,
assignment), IPortletRenderer)
except ComponentLookupError:
logging.getLogger("panels").info(
"unable to look up renderer for '%s.%s'." % (
assignment.__class__.__module__,
assignment.__class__.__name__
)
)
continue
info = {
'manager': panel.__name__,
'category': CONTEXT_CATEGORY,
'key': '/'.join(parent.getPhysicalPath()),
'name': assignment.__name__,
'renderer': portlet,
}
hashPortletInfo(info)
portlet.update()
if portlet.available:
result = self.portlet(**info)
portlets.append(result)
return render(portlets, self.context.layout, self.request)
示例15: portlets_for_assignments
def portlets_for_assignments(self, assignments, manager, base_url):
category = self.__parent__.category
key = self.__parent__.key
data = []
for idx in range(len(assignments)):
name = assignments[idx].__name__
if hasattr(assignments[idx], "__Broken_state__"):
name = assignments[idx].__Broken_state__["__name__"]
editview = queryMultiAdapter((assignments[idx], self.request), name="edit", default=None)
if editview is None:
editviewName = ""
else:
editviewName = "%s/%s/edit" % (base_url, name)
portlet_hash = hashPortletInfo(dict(manager=manager.__name__, category=category, key=key, name=name))
try:
settings = IPortletAssignmentSettings(assignments[idx])
visible = settings.get("visible", True)
except TypeError:
visible = False
data.append(
{
"title": assignments[idx].title,
"editview": editviewName,
"hash": portlet_hash,
"name": name,
"up_url": "%s/@@move-portlet-up" % (base_url),
"down_url": "%s/@@move-portlet-down" % (base_url),
"delete_url": "%s/@@delete-portlet" % (base_url),
"hide_url": "%s/@@toggle-visibility" % (base_url),
"show_url": "%s/@@toggle-visibility" % (base_url),
"visible": visible,
}
)
if len(data) > 0:
data[0]["up_url"] = data[-1]["down_url"] = None
return data