示例#1
0
    def items_for(self, model, breakpoint=None):
        items = list()
        for node in LocationIterator(model):
            title = node.metadata.title
            title = safe_decode(title) if title else title
            items.append({
                'title': title,
                'url': self.item_url(node),
                'target': self.item_target(node),
                'selected': False,
                'id': node.name,
                'default_child': node.properties.default_child,
            })
            if node is breakpoint:
                break
        items.reverse()
        ret = list()
        count = len(items)
        for i in range(count):
            default_child = items[i]['default_child']
            if default_child \
              and i < count - 1 \
              and default_child == items[i + 1]['id']:
                continue
            ret.append(items[i])

        # XXX: this is crap!
        if not breakpoint:
            ret[0]['title'] = 'Home'

        ret[-1]['selected'] = True
        return ret
示例#2
0
 def nodelevel(self):
     level = -1
     for parent in LocationIterator(self):
         if IModule.providedBy(parent):
             break
         level += 1
     return level
示例#3
0
 def referencebrowser_model(self):
     root = self.referencable_root
     if root in LocationIterator(self.model):
         return self.model
     return root
示例#4
0
 def root(self):
     root = None
     for parent in LocationIterator(self):
         root = parent
     return root
示例#5
0
 def path(self):
     path = [parent.name for parent in LocationIterator(self)]
     path.reverse()
     return path
示例#6
0
 def render(self):
     cut = extract_copysupport_cookie(self.request, 'cut')
     copy = extract_copysupport_cookie(self.request, 'copy')
     localizer = get_localizer(self.request)
     if not cut and not copy:
         message = localizer.translate(
             _('nothing_to_paste', default='Nothing to paste'))
         ajax_message(self.request, message)
         return u''
     urls = copy and copy or cut
     paths = paths_from_urls(urls)
     call_sources = set()
     errors = list()
     success = 0
     for path in paths:
         node = self.model.root
         for key in path:
             node = node[key]
         if not node.node_info_name:
             message = localizer.translate(_(
                 'cannot_paste_unknown_source',
                 default="Cannot paste '${name}'. Unknown source"),
                                           mapping={'name': node.name})
             errors.append(message)
             continue
         if not self.model.node_info_name:
             message = localizer.translate(
                 _('cannot_paste_unknown_target',
                   default="Cannot paste to '${name}'. Unknown target"),
                 mapping={'name': self.model.name})
             errors.append(message)
             continue
         if node.node_info_name not in self.model.nodeinfo.addables:
             message = localizer.translate(
                 _('cannot_paste_cardinality_violation',
                   default=("Violation. '${target}' is not allowed to "
                            "contain '${source}'")),
                 mapping={
                     'target': self.model.nodeinfo.title,
                     'source': node.nodeinfo.title
                 })
             errors.append(message)
             continue
         source = node.parent
         if copy:
             node = source[node.name].deepcopy()
         else:
             in_model = False
             for parent in LocationIterator(self.model):
                 if parent is node:
                     message = localizer.translate(
                         _('cannot_paste_self_containment',
                           default=("Cannot paste cut object to child "
                                    "of it: ${name}")),
                         mapping={'name': parent.name})
                     errors.append(message)
                     in_model = True
                     break
             if in_model:
                 continue
             node = source.detach(node.name)
         node.__parent__ = self.model
         self.model[choose_name(self.model, node.name)] = node
         if cut:
             call_sources.add(source)
         success += 1
     if success > 0:
         self.model()
     for source in call_sources:
         source()
     message = localizer.translate(_('pasted_items',
                                     default="Pasted ${count} items"),
                                   mapping={'count': success})
     if errors:
         failed = localizer.translate(_(
             'pasting_items_failed',
             default="Pasting of ${count} items failed"),
                                      mapping={'count': len(errors)})
         failed = "<br /><strong>%s</strong>" % failed
         message += "<br />".join([failed] + errors)
     ajax_message(self.request, message)
     content_tile = self.model.properties.action_paste_tile
     if not content_tile:
         content_tile = 'listing'
     query = make_query(contenttile=content_tile)
     url = make_url(self.request, node=self.model, query=query)
     event = AjaxEvent(url, 'contextchanged', '#layout')
     ajax_continue(self.request, event)
     res = self.request.response
     res.delete_cookie(cookie_name(copy and 'copy' or 'cut'))
     return u''