示例#1
0
def get_block_with_arg(block_name, arg):
    block_library = BlockLibrary()
    block_library.autodiscover()
    try:
        return block_library.get_block(block_name)(arg)
    except NotInLibraryException:
        return ''
示例#2
0
class BlockNode(template.Node):
    def __init__(self, arguments):
        self.block_library = BlockLibrary()
        self.block_library.autodiscover()
        self.block_name = arguments[0][1:-1]
        self.argument = arguments[1][1:-1] if len(arguments) > 1 else None

    def render(self, context):
        try:
            block = self.block_library.get_block(self.block_name)
        except NotInLibraryException:
            return ''
        if not self.argument:
            return block()
        else:
            return block(self.argument)
示例#3
0
 def __init__(self, arguments):
     self.block_library = BlockLibrary()
     self.block_library.autodiscover()
     self.block_name = arguments[0][1:-1]
     self.argument = arguments[1][1:-1] if len(arguments) > 1 else None