# Path: achilles/blocks.py
# class Library(BaseLibrary):
#         class B(Block):
# class Block(object):
#     def __init__(self, namespace=None):
#     def register(self, name=None):
#     def block(self, name=None, template_name=None, takes_context=False):
#         def dec(name):
#     def _create_class(self, func):
#             def get_context_data(self, *args, **kwargs):
# def get(name, context=None):
#     def __init__(self, context):
#     def render(self, *args, **kwargs):
#     def get_context_data(self, *args, **kwargs):
#     def update(self, transport, *args, **kwargs):
# def update(transport, name, *args, **kwargs):
# def render(transport):
# 
# Path: achilles/actions.py
# class Library(BaseLibrary):
#     def __init__(self, namespace=None):
#     def _register(self, func, name=None):
#         def wrapper(transport, *args, **kwargs):
# def get(name):
# def run_actions(transport, actions):
# def render(transport):


from django.template import RequestContext
from achilles import blocks, actions
class ActionColumn(ButtonColumn):
    """
    Action calling column, it will show a button that will can
    the given action on click, the action will get the the table
    and object in the row as arguments
    """
    def __init__(self, action, classes='', *args, **kwargs):
        super(ActionColumn, self).__init__(classes=classes, *args, **kwargs)
        self.action = action

    def call(self, *args, **kwargs):
        return self.action(*args, **kwargs)

    def get_href(self, obj):
        return ("javascript:achilles.action("
                "'tables:row_action', ['%s', '%s', '%s'])") % (
            self.table.register_name, self.name, self.table.get_object_id(obj))


@register.action
def table_action(transport, table_name, action_name, *args, **kwargs):
    """
    Call table action

    :param transport: achilles transport
    :param table_name: Name of the table calling this
    :param action_name: Name of the action to call
    """
    # Get TableAction item
    context = RequestContext(transport.request, {})

# Path: achilles/blocks.py
# class Library(BaseLibrary):
#         class B(Block):
# class Block(object):
#     def __init__(self, namespace=None):
#     def register(self, name=None):
#     def block(self, name=None, template_name=None, takes_context=False):
#         def dec(name):
#     def _create_class(self, func):
#             def get_context_data(self, *args, **kwargs):
# def get(name, context=None):
#     def __init__(self, context):
#     def render(self, *args, **kwargs):
#     def get_context_data(self, *args, **kwargs):
#     def update(self, transport, *args, **kwargs):
# def update(transport, name, *args, **kwargs):
# def render(transport):
# 
# Path: achilles/actions.py
# class Library(BaseLibrary):
#     def __init__(self, namespace=None):
#     def _register(self, func, name=None):
#         def wrapper(transport, *args, **kwargs):
# def get(name):
# def run_actions(transport, actions):
# def render(transport):


# Path: achilles/tables/columns.py
from django.template import RequestContext
from achilles import blocks, actions

class ActionColumn(ButtonColumn):
    """
    Action calling column, it will show a button that will can
    the given action on click, the action will get the the table
    and object in the row as arguments
    """
    def __init__(self, action, classes='', *args, **kwargs):
        super(ActionColumn, self).__init__(classes=classes, *args, **kwargs)
        self.action = action

    def call(self, *args, **kwargs):
        return self.action(*args, **kwargs)

    def get_href(self, obj):
        return ("javascript:achilles.action("
                "'tables:row_action', ['%s', '%s', '%s'])") % (
            self.table.register_name, self.name, self.table.get_object_id(obj))


@register.action
def table_action(transport, table_name, action_name, *args, **kwargs):
    """
    Call table action

    :param transport: achilles transport
    :param table_name: Name of the table calling this
    :param action_name: Name of the action to call
    """
    # Get TableAction item
    context = RequestContext(transport.request, {})

    table = blocks.get(table_name, context)