Example #1
0
 def visit_cmsitemselection_node(self, node):
     encodedItemsel=node.attributes['itemsel']
     itemsel = ItemSelection.fromString(str(encodedItemsel))
     if itemsel.id:
         # Individual item
         htmlFragment = """
         <n:invisible n:data="cmsitemselection %(itemsel)s" n:render="cmsitemselection %(itemsel)s" />
         """%{'itemsel': encodedItemsel}
     elif itemsel.paging:
         # List with paging tags
         htmlFragment = """
         <n:invisible n:data="cmsitemselection %(itemsel)s" n:render="paging %(itemsPerPage)s" >
           <n:invisible n:pattern="item" n:render="cmsitemselection %(itemsel)s" />
         </n:invisible>
         <n:invisible n:render="fragment paging_controls" />
         """%{'itemsel': encodedItemsel, 'itemsPerPage':itemsel.paging}
     else:
         # List without paging
         htmlFragment = """
         <n:invisible n:data="cmsitemselection %(itemsel)s" n:render="sequence" >
           <n:invisible n:pattern="item" n:render="cmsitemselection %(itemsel)s" />
         </n:invisible>
         """%{'itemsel': encodedItemsel}
     classes=node.attributes.get('classes')
     if classes:
         htmlFragment = """<div class="%s cmsitems">%s</div>"""%(" ".join(classes), htmlFragment)
     self.body.append(htmlFragment)
Example #2
0
def render_cmsitemselection(encodedItemsel):
    itemsel = ItemSelection.fromString(str(encodedItemsel))

    def renderer(ctx, data):
        from basiccms.web import cmsresources
        resource = inevow.IResource(data)
        if itemsel.template is not None and hasattr(resource, 'setTemplate'): 
            resource.setTemplate(*cmsresources.parseTemplateString(itemsel.template))
        return resource

    return renderer
def CmsFragmentFlattener(original,ctx):
    def gotData(data, ctx):
        if hasattr(data, 'sort'):
            data.sort(key=lambda i: i.date, reverse=True)
        resource = inevow.IResource(data)
        #if itemsel.template is not None and hasattr(resource, 'setTemplate'): 
            #resource.setTemplate(*parseTemplateString(itemsel.template))
        return resource

    itemsel = ItemSelection.fromString(str(original))
    d = inevow.IGettable(itemsel).get(ctx)
    d.addCallback(gotData, ctx)
    return d
Example #4
0
 def visit_cmsitemselection_node(self, node):
     itemsel = ItemSelection.fromString(str(node.attributes['itemsel']))
     tag = T.div(class_="cmsitemselection")[
         "Items matching:", T.br,
         T.strong["Type:"], itemsel.type or '', T.br,
         T.strong["Categories:"], itemsel.categories or '', T.br,
         T.strong["Max Publish Age:"], itemsel.maxPublishedAge or '', T.br,
         T.strong["Max Items:"], itemsel.maxItems or '', T.br,
         T.strong["Template:"], itemsel.template or '', T.br,
         "will be inserted here"
     ]
     html = flat.flatten(tag)
     self.body.append(html)
Example #5
0
    def data(ctx, data):
        def gotData(data, ctx):
            if hasattr(data, "sort"):
                try:
                    data.sort(key=lambda i: i.date, reverse=True)
                except AttributeError:
                    data.sort(key=lambda i: i.name, reverse=True)

            return data

        itemsel = ItemSelection.fromString(str(encodedItemsel))
        d = inevow.IGettable(itemsel).get(ctx)
        d.addCallback(gotData, ctx)
        return d