Example #1
0
    def view(self, handler, instance):
        ctx = {}
        ctx['spokes'] = [SpokeContext(s) for s in type_registry.values()]

        # import pdb; pdb.set_trace()
        
        return handler.template("wheelcms_debug/configure_debug.html", **ctx)
Example #2
0
    def children(self):
        """ return the addable children for this type, except the primary
            type (if any) """
        type = self.type()
        ## order?
        ## unconnected, or no restrictions
        if type is None:
            ch = [t for t in type_registry.values() if t.implicit_add]
            primary = None
        else:
            ch = type(self.instance.content()).allowed_spokes()
            primary = type.primary

        return [dict(name=c.name(), title=c.title, icon_path=c.full_type_icon_path()) for c in ch if c != primary]
Example #3
0
 def allowed_spokes(self):
     return type_registry.values()
Example #4
0
 def allchildren(self, children):
     """ match against all registered children """
     return set(x['name'] for x in children) == \
            set(c.name() for c in type_registry.values())
Example #5
0
    def panels(self, path, original, mode):
        """
            Generate panels for the file selection popup
            mode can be either "link" (any content) or "image" (only image
            based content)
        """
        language = self.active_language()
        if not self.hasaccess():
            return self.forbidden()


        ##
        ## No path means a new item is to be selected. Use the current
        ## item as a starting point
        
        if not path:
            path = self.instance.path
        else:
            path = resolve_path(path)

        if path is None:
            return self.notfound()

        original = resolve_path(original) or ""

        ## remove optional 'action', marked by a +
        ## not sure if this is the right place to do this, or if the browser
        ## modal should have been invoked without the action in the first place


        path = strip_action(path)
        original = strip_action(original)

        node = start = Node.get(path)# , language=language)

        ##
        ## Selectable means the node is a valid selection. Unattached
        ## nodes are never selectable and in image mode only image based
        ## content is a valid selection
        def is_selectable(node):
            content = node.content()
            if content:
                if mode == "link":
                    return True
                elif isinstance(content, ImageContent):
                    return True
            return False

        ## Is the starting point a valid selection?
        start_selectable = is_selectable(node)

        panels = []

        ## first panel: bookmarks/shortcuts

        bookmarks_paths = [''] # root
        if self.instance.path not in bookmarks_paths:
            bookmarks_paths.append(self.instance.path)
        #if path not in bookmarks_paths:
        #    bookmarks_paths.append(path)
        ## original can also be an external url, starting with http
        if original not in bookmarks_paths and not original.startswith("http"):
            bookmarks_paths.append(original)

        bookmarks = []

        for p in bookmarks_paths:
            ## handle non-existing nodes and unattached nodes
            n = Node.get(p)
            if not n:
                continue
            content = n.content()
            if not content: ## unattached
                continue
            spoke = content.spoke()
            selectable = is_selectable(n)
            bookmarks.append(dict(children=[], path=n.get_absolute_url(),
                            title=content.title,
                            meta_type=content.meta_type,
                            content=content,
                            selectable=selectable,
                            icon=spoke.icon_base() + '/' + spoke.icon,
                            spoke=spoke))

        panels.append(self.render_template("wheelcms_axle/popup_links.html",
                                           instance=self.instance,
                                           bookmarks=bookmarks
                                           ))
        upload = False

        for i in range(2):
            content = node.content()

            if content:
                ## FileSpoke also includes ImageSpoke

                spoke = content.spoke()
                addables = [x for x in spoke.addable_children()
                            if issubclass(x, FileSpoke)]
                instance = dict(children=[], path=node.get_absolute_url(),
                                title=content.title,
                                meta_type=content.meta_type,
                                content=content,
                                spoke=spoke,
                                addables=addables)
            else:
                addables = [x for x in type_registry.values()
                            if issubclass(x, FileSpoke)]
                instance = dict(children=[], path=node.get_absolute_url(),
                                title="Unattached node",
                                meta_type="none",
                                content=None,
                                spoke=None,
                                addables=addables)

            if i == 0:
                ## first iteration means current context. Check if uploading
                ## is possible.
                upload = bool(addables)

            for child in node.children():
                content = child.content()

                if not content:
                    continue  ## ignore unattached nodes
                spoke = content.spoke()

                selectable = is_selectable(child)

                selected = path == child.path or \
                           path.startswith(child.path + '/')
                instance['children'].append(
                                      dict(title=content.title,
                                           path=child.get_absolute_url(),
                                           icon=spoke.icon_base() + '/' +
                                                spoke.icon,
                                           selectable=selectable,
                                           meta_type=content.meta_type,
                                           selected=selected))

            panels.insert(1,
                          self.render_template("wheelcms_axle/popup_list.html",
                                               instance=instance,
                                               path=node.get_absolute_url(),
                                               mode=mode,
                                               selectable=(i==0)))
            if node.isroot():
                break
            node = node.parent()

        ## generate the crumbs
        crumbs = []
        node = start
        while True:
            content = node.content()
            selectable = is_selectable(node)
            if node.isroot():
                crumbs.insert(0, dict(path=node.get_absolute_url(),
                                      selectable=selectable, title="Home"))
                break
            crumbs.insert(0, dict(path=node.get_absolute_url(),
                                  selectable=selectable,
                                  title=node.content().title))
            node = node.parent()

        crumbtpl = self.render_template("wheelcms_axle/popup_crumbs.html",
                                        crumbs=crumbs)
        return dict(panels=panels, path=start.get_absolute_url(),
                    crumbs=crumbtpl, upload=upload, selectable=start_selectable)