achilles.blocks – Dynamically loaded blocks

class achilles.blocks.Library(namespace=None)

Blocks library holds a register of all defined blocks

Use it to define and register new blocks, grouping them under a common namespace. See block().

Parameters:namespace – Unique namespace for this register
block(name=None, template_name=None, takes_context=False)

Block register decorator, register a block on the library.

When decorating a function, this method will automatically create a block. The block will use a dict returned by the function as template context:

from achilles import blocks

register = blocks.Library('myapp')

@register.block(template_name='foo.html')
def foo():
    return {
        'template_var1' : 42,
        'template_var2' : True,
    }

When decorating a Block class it will just register it on the library.

Parameters:
  • name – Name of the block, if None the decorated function name will be taken
  • template_name – Path of the block template
  • takes_context – If True, the decorated function will receive the template context as first parameter
class achilles.blocks.Block(context)

Blocks are parts of the page that can be dinamically rendered. By calling update() action you can reload any block asynchronously.

In most cases blocks are automatically created out of functions decorated with Library.block(). For advanced uses you may need to sublcass this.

get_context_data(*args, **kwargs)

Returns context to be passed to the template renderer in render().

render(*args, **kwargs)

Render the block, this method receives block arguments (if any) and renders HTML result of the block.

template_name = None

Template file that will be used in render()

update(request, *args, **kwargs)

Render and send the update of block within the given request

achilles.blocks.get(name, context=None)

Retrieve a block with the given name. Example:

blocks.get('myapp:foo')
Parameters:name – Fully namespaced block name

Available actions

achilles.blocks.update(request, name, *args, **kwargs)

Action name: blocks:update

Update a block, if the block doesn’t exists on the page nothing will happen.

Blocks may have arguments, this function will pass any argument to the block handler. When using arguments, only blocks matching them will be updated.

Parameters:
  • request – Django request object that is being served
  • name – Fully namespaced block name

Table Of Contents

Previous topic

achilles.actions – Asynchronous actions

Next topic

achilles.console – Javascript console output

This Page