本文整理汇总了Python中bungeni.alchemist.interfaces.IAlchemistContainer类的典型用法代码示例。如果您正苦于以下问题:Python IAlchemistContainer类的具体用法?Python IAlchemistContainer怎么用?Python IAlchemistContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IAlchemistContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
def __new__(cls, context, request, view, manager):
chain = _get_context_chain(context)
chain.pop() # bungeni_app
top_section = chain.pop()
if not chain:
return
# we require the tree to begin with a container object
if not IReadContainer.providedBy(chain[-1]):
return
# remove any views from navigation tree
if not(IAlchemistContent.providedBy(chain[0]) or
IAlchemistContainer.providedBy(chain[0]) or
ISection.providedBy(chain[0])
):
chain.pop(0)
subcontext = chain[-1]
if (len(chain) > 1 or
IReadContainer.providedBy(subcontext) and
not IAlchemistContainer.providedBy(subcontext) and
len(subcontext)
):
inst = object.__new__(cls, context, request, view, manager)
inst.chain = chain
inst.top_section_url = url.absoluteURL(top_section, request)
inst.id_prefix = "nav"
return inst
示例2: _searchresults
def _searchresults(self):
section = get_section_name()
subqueries = []
type_filter = ""
if IAlchemistContainer.providedBy(self.context):
for t in ALLOWED_TYPES["business"]:
iface = resolve.resolve("bungeni.models.interfaces.I%sContainer"%t)
if iface.providedBy(self.context):
type_filter = t
break
if type_filter:
type_query = self.searcher.query_field('object_type', type_filter)
else:
# Filter items allowed in current section
for tq in ALLOWED_TYPES[section]:
subqueries.append(self.searcher.query_field('object_type', tq))
type_query = self.searcher.query_composite(self.searcher.OP_OR,
subqueries)
self.query = self.searcher.query_composite(self.searcher.OP_AND,
(self.query, type_query,))
try:
results = self.searcher.search(self.query, 0,
self.searcher.get_doccount())
except:
results = []
results = filter(self.authorized, results)
return results
示例3: _get_title_from_context
def _get_title_from_context(context):
title = None
if IAlchemistContent.providedBy(context):
if IDCDescriptiveProperties.providedBy(context):
title = context.title
else:
props = IDCDescriptiveProperties(context, None)
if props is not None:
title = props.title
else:
""" !+
AttributeError: 'GroupAddress' object has no attribute 'short_name': File "/home/undesa/bungeni/cap_installs/bungeni_install/bungeni/releases/20100305100101/src/bungeni.main/bungeni/ui/viewlets/navigation.py", line 59, in _get_title_from_context
#title = context.short_name
So, we temporarily default the above to the context.__class__.__name__:
"""
title = getattr(context, "title", context.__class__.__name__)
elif IWorkspaceContainer.providedBy(context):
# WorkspaceContainer._class is not set (and not unique) and it breaks the
# connection between Container -> ContentClass
title = context.__name__
elif IAlchemistContainer.providedBy(context):
domain_model = context._class
try:
descriptor = utils.get_descriptor(domain_model)
except KeyError, e:
log.warn("TYPE_INFO: no descriptor for model %s " "[container=%s] [error=%s]" % (domain_model, context, e))
descriptor = None
name = ""
if descriptor:
name = getattr(descriptor, "container_name", None)
if name is None:
name = getattr(descriptor, "display_name", None)
if not name:
name = getattr(context, "__name__", None)
title = name
示例4: filterFields
def filterFields(context, form_fields):
omit_names = []
if IAlchemistContent.providedBy(context):
md = utils.get_descriptor(context.__class__)
for field in form_fields:
# field:zope.formlib.form.FormField
try:
can_write = security.canWrite(context, field.__name__)
can_read = security.canAccess(context, field.__name__)
except AttributeError:
log.warn('filterFields: item [%s] has no field named "%s"', context, field.__name__)
can_write = can_read = False
if can_write:
continue
if can_read:
field.for_display = True
field.custom_widget = md.get(field.__name__).view_widget
else:
omit_names.append(field.__name__)
elif not IAlchemistContainer.providedBy(context):
ctx = getattr(context, "context", None)
if ctx:
filterFields(ctx, form_fields)
else:
raise NotImplementedError
return form_fields.omit(*omit_names)
示例5: getMenuItems
def getMenuItems(self, context, request):
results = []
try:
items = proxy.removeSecurityProxy(context.__parent__).items()
except AttributeError:
return results
for key, item in items:
if not IAlchemistContainer.providedBy(item): continue
if not IScheduleText.implementedBy(item.domain_model): continue
dc_adapter = IDCDescriptiveProperties(item, None)
if dc_adapter:
_title = dc_adapter.title
else:
_title = getattr(item, "title", "Unknown")
results.append(dict(
title=_title,
description=_title,
action = url.absoluteURL(item, request),
selected=False,
icon=None,
extra={},
submenu=None
))
return results
示例6: process_document_tree
def process_document_tree(root, context):
"""Iterate and optionally update children of provided root node.
Rendering is based on type of node. Further calls to this function
happen when a node with children exists - and so on.
Only nodes with the bungeni namespace tags "br:type" are modified
with content from the provided context.
"""
cond = get_attr(root, "condition")
if cond and not check_exists(context, cond):
return None
iter_children = root.getchildren() or [root]
if not (root in iter_children):
root_typ = get_attr(root, "type")
if root_typ:
process_single_node(root, context, root_typ, get_attr(root, "source"))
for child in iter_children:
typ = get_attr(child, "type")
src = get_attr(child, "source")
cond = get_attr(child, "condition")
if cond and not check_exists(context, cond):
drop_element(child)
continue
children = child.getchildren()
if len(children) == 0:
if typ:
process_single_node(child, context, typ, src)
else:
if typ:
if typ == "listing":
clean_element(child)
children = child.getchildren()
listing = get_element_value(context, src, default=[])
if IAlchemistContainer.providedBy(listing):
listing = [item for item in common.list_container_items(listing)]
len_listing = len(listing)
expanded_children = [deepcopy(children) for x in range(len_listing)]
empty_element(child)
if len(listing) == 0:
no_items_tag = "p"
if child.tag == "tr":
no_items_tag = "td"
no_items_node = etree.SubElement(child, no_items_tag)
no_items_node.text = translate_i18n(_(u"No items found"))
else:
for (index, item) in enumerate(listing):
for inner_element in expanded_children[index]:
iroot = process_document_tree(inner_element, item)
if iroot is not None:
child.append(iroot)
elif typ == "block" and src:
block_context = get_element_value(context, src, default=None)
process_document_tree(child, block_context)
else:
process_document_tree(child, context)
else:
process_document_tree(child, context)
clean_element(root)
return root
示例7: expand_containers
def expand_containers(self, items, containers, _url, chain=(), context=None):
# seen_context = False
_url = _url.rstrip("/")
current = False
for key, container in self._sort_containers(containers):
assert IAlchemistContainer.providedBy(container)
label = container.domain_model.__name__
descriptor = utils.get_descriptor(container.domain_model)
if descriptor:
label = getattr(descriptor, "container_name", None) or getattr(descriptor, "display_name", None)
if context is not None:
current = container.__name__ == context.__name__
selected = not len(chain) and current
if current:
# seen_context = True
nodes = self.expand(chain)
else:
nodes = ()
key_url = "%s/%s" % (_url, key)
items.append(
{
"id": self.get_nav_entry_id(key_url),
"label": translate(
label, target_language=get_request_language(request=self.request), domain="bungeni"
),
"url": key_url,
"current": current,
"selected": selected,
"kind": "container",
"nodes": nodes,
}
)
示例8: _get_title_from_context
def _get_title_from_context(context):
title = None
if IAlchemistContent.providedBy(context):
if IDCDescriptiveProperties.providedBy(context):
title = context.title
else:
props = IDCDescriptiveProperties(context, None)
if props is not None:
title = props.title
else:
''' !+
AttributeError: 'GroupAddress' object has no attribute 'short_name': File "/home/undesa/bungeni/cap_installs/bungeni_install/bungeni/releases/20100305100101/src/bungeni.main/bungeni/ui/viewlets/navigation.py", line 59, in _get_title_from_context
#title = context.short_name
So, we temporarily default the above to the context.__class__.__name__:
'''
title = getattr(context, "short_name",
context.__class__.__name__)
elif IAlchemistContainer.providedBy(context):
domain_model = context._class
try:
descriptor = queryModelDescriptor(domain_model)
except:
descriptor = None
name = ""
if descriptor:
name = getattr(descriptor, 'container_name', None)
if name is None:
name = getattr(descriptor, 'display_name', None)
if not name:
name = getattr(context, '__name__', None)
title = name
elif ILocation.providedBy(context) and \
IDCDescriptiveProperties.providedBy(context):
title = context.title
return title
示例9: domain_model
def domain_model(self):
unproxied = removeSecurityProxy(self.context)
if IAlchemistContainer.providedBy(unproxied):
return unproxied.domain_model
elif IAlchemistContent.providedBy(unproxied):
return unproxied.__class__
else:
raise AttributeError("Could not find domain model for context: %s", unproxied)
示例10: obj2dict
def obj2dict(obj, depth, parent=None, include=[], exclude=[]):
""" Returns dictionary representation of an object.
"""
result = {}
obj = removeSecurityProxy(obj)
# Get additional attributes
for name in include:
value = getattr(obj, name, None)
if value is None:
continue
if not name.endswith("s"):
name += "s"
if isinstance(value, collections.Iterable):
res = []
# !+ allowance for non-container-api-conformant alchemist containers
if IAlchemistContainer.providedBy(value):
value = value.values()
for item in value:
i = obj2dict(item, 0)
if name == "versions":
permissions = get_head_object_state_rpm(item).permissions
i["permissions"] = get_permissions_dict(permissions)
res.append(i)
result[name] = res
else:
result[name] = value
# Get mapped attributes
for property in class_mapper(obj.__class__).iterate_properties:
if property.key in exclude:
continue
value = getattr(obj, property.key)
if value == parent:
continue
if value is None:
continue
if isinstance(property, RelationshipProperty) and depth > 0:
if isinstance(value, collections.Iterable):
result[property.key] = []
for item in value:
result[property.key].append(obj2dict(item, depth-1,
parent=obj,
include=[],
exclude=exclude + ["changes"]
))
else:
result[property.key] = obj2dict(value, depth-1,
parent=obj,
include=[],
exclude=exclude + ["changes"]
)
else:
if isinstance(property, RelationshipProperty):
continue
result[property.key] = value
return result
示例11: generate_tree
def generate_tree(root, context):
for element in root.getiterator():
typ = get_attr(element, "type")
src = get_attr(element, "source")
if typ:
if typ=="text":
clean_element(element)
element.text = get_element_value(context, src)
elif typ=="link":
clean_element(element)
url_source = get_attr(element, "url")
if url_source:
link_url = get_element_value(context, url_source)
else:
link_url = url.absoluteURL(context,
common.get_request()
)
element.attrib["href"] = link_url
if src:
element.text = get_element_value(context, src)
elif typ=="html":
clean_element(element)
_html = u"<div>%s</div>" % get_element_value(context,
src
)
new_html = element.insert(0, etree.fromstring(_html))
elif typ=="listing":
listing = get_element_value(context, src, default=[])
if IAlchemistContainer.providedBy(listing):
_listing = common.list_container_items(listing)
listing = [ item for item in _listing ]
log.debug("[LISTING] %s @@ %s", src, listing)
listing_count = len(listing)
new_children = [
deepcopy(element.getchildren())
for x in range(listing_count)
]
empty_element(element)
clean_element(element)
if listing_count == 0:
parent = element.getparent()
no_items_element = etree.SubElement(element, "p")
no_items_element.text = translate_i18n(
_(u"No items found")
)
else:
for (index, item) in enumerate(listing):
for child in new_children[index]:
generate_tree(child, item)
for children in new_children:
for descendant in children:
element.append(descendant)
break
return etree.tostring(root)
示例12: __call__
def __call__(self, context):
if IAlchemistContent.providedBy(context):
ctx = context
elif IAlchemistContainer.providedBy(context):
domain_model = removeSecurityProxy(context.domain_model)
ctx = domain_model()
workflow = interfaces.IWorkflow(ctx)
items = []
for status in workflow.states.keys():
items.append(SimpleTerm(status, status,
_(workflow.get_state(status).title)))
return SimpleVocabulary(items)
示例13: get_group_for_context
def get_group_for_context(context):
"""Return the "main" (as meaning of this for type) group for this context,
or None if no such logical group can be determined.
The group may be None if:
- context is a user who is not a member of any group within any chamber
- context is a core.interfaces.ISection or workspace Container, for which
there is no "contextual" chamber is defined in the traversal hierarchy
- context is an IAlchemistContainer that is not hierarchically contained
within an IBungeniContent (no such instance in its __parent__ ancestry)
!+ should this be shipped out as a domain_model.group property, or
interfaces organized in "how group is determined" categories?
"""
group = None
if interfaces.IGroup.providedBy(context):
group = context
elif interfaces.IEvent.providedBy(context):
group = context.group or context.head.group
elif (interfaces.IDoc.providedBy(context) or
interfaces.IGroupMember.providedBy(context) or
interfaces.IGroupAddress.providedBy(context) or
interfaces.ISitting.providedBy(context) or
interfaces.ITitleType.providedBy(context) or
interfaces.IEditorialNote.providedBy(context) or
interfaces.IHeading.providedBy(context)
):
group = context.group
elif (IAlchemistContainer.providedBy(context) or
ISection.providedBy(context) # !+group ALWAYS None?
):
group = get_group_for_context(context.__parent__)
elif (interfaces.IAttachment.providedBy(context) or
interfaces.ISignatory.providedBy(context)
):
group = context.head.group
elif (interfaces.IMemberTitle.providedBy(context) or
interfaces.IMemberRole.providedBy(context)
):
group = context.member.group
elif (interfaces.IDebateRecord.providedBy(context) or
interfaces.ISittingAttendance.providedBy(context)
):
group = context.sitting.group
if group is None:
#from bungeni.utils import probing
#log.warn(probing.interfaces(context))
log.warn("!+GROUP_FOR_CONTEXT Cannot determine group for context: %s", context)
#raise ValueError, "No group for context: %s" % (context)
return group
示例14: expand_containers
def expand_containers(self, items, containers, _url, chain=(), context=None):
#seen_context = False
_url = _url.rstrip("/")
current = False
for key, container in containers:
assert IAlchemistContainer.providedBy(container)
# do not include doc containers for docs who do not specifically
# declare the parent group instance as a workspace.group_name
if IDoc.implementedBy(container.domain_model):
group = get_group_for_context(container)
assert IGroup.providedBy(group)
doc_type_key = naming.polymorphic_identity(container.domain_model)
if not group.is_type_workspaced(doc_type_key):
continue
label = container.domain_model.__name__
descriptor = utils.get_descriptor(container.domain_model)
order = 999
if descriptor:
order = descriptor.order
label = getattr(descriptor, "container_name", None) or \
getattr(descriptor, "display_name", None)
if context is not None:
current = container.__name__ == context.__name__
selected = not len(chain) and current
if current:
#seen_context = True
nodes = self.expand(chain)
else:
nodes = ()
key_url = "%s/%s" % (_url, key)
items.append({
"id": self.get_nav_entry_id(key_url),
"order": order,
"label": translate(label,
target_language=get_default_language(),
domain="bungeni"),
"url": key_url,
"current": current,
"selected": selected,
"kind": "container",
"nodes": nodes,
})
items.sort(key=lambda item:(item['order'], item['label']))
示例15: form_name
def form_name(self):
parent = self.context.__parent__
if IAlchemistContainer.providedBy(parent):
descriptor = queryModelDescriptor(parent.domain_model)
elif IAlchemistContent.providedBy(self.context):
descriptor = queryModelDescriptor(self.context.__class__)
else:
raise RuntimeError("Unsupported object: %s." % repr(self.context))
if descriptor:
name = getattr(descriptor, "display_name", None)
if name is None:
name = self.context.__class__.__name__
return name