コード例 #1
0
ファイル: ajax.py プロジェクト: xealot/django-helpers
def table(queryset, params, fields=(), exclude=(), listfield_callback=None, make_selectable=False, linker=False, additional_plugins=()):
    record_url = None
    plugins = get_plugins(queryset, params, record_url, fields, exclude, listfield_callback, make_selectable, linker, additional_plugins)
    table = ModelTable(plugins=plugins, include_header=False, include_footer=False, finalize=False)
    return xmlstring(table.build(queryset, columns=fields, exclude=exclude))
コード例 #2
0
ファイル: makotable.py プロジェクト: xealot/django-helpers
def table(
    context,
    queryset,
    fields=(),
    exclude=(),
    classes=(),
    record_url=None,
    instance=None,
    make_selectable=False,
    row_formatter=False,
    make_editable=False,
    listfield_callback=None,
    wrapper=True,
    additional_plugins=(),
    table_class=ModelTable,
    **kwargs
):
    listfield_callback = listfield_callback or {}
    header_callback = {}

    # THe crazy mako shit is mostly at the top
    try:
        context.caller_stack._push_frame()
        caller = context.get("caller", runtime.UNDEFINED)
        capture = context.get("capture", runtime.UNDEFINED)

        for key in fields:
            index = isinstance(key, (tuple, list)) and key[0] or key
            # FIRST COLUMN SPECIAL CASE ***DEPRECATED***
            if key == fields[0] and hasattr(caller, "td__first"):  # First column override :TODO: make this more generic
                #:TODO: I wish I didn't need to wrap this in a lambda, backward compat issue; also I don't know how passing context to a mako function works.
                listfield_callback[1] = partial(
                    capture, lambda attr, obj, context: getattr(caller, "td__first")(attr, obj)
                )
            #:TODO: can we deprecate this too?
            if hasattr(caller, "td_%s" % index):
                func = getattr(caller, "td_%s" % index)
                listfield_callback[index] = partial(capture, partial(lambda func, attr, obj: func(obj), func))
            if hasattr(caller, "th_%s" % index):
                func = getattr(caller, "th_%s" % index)
                header_callback[index] = partial(capture, partial(lambda func: func(), func))
    finally:
        context.caller_stack._pop_frame()
    # End completely crazy mako shit

    plugins = [DTGeneralFormatter, DTUnicode, DTHtmlTable, NGLegacyCSS]
    # Give table appropriate CSS classes
    if listfield_callback:
        plugins.insert(2, DTCallback(listfield_callback, header_callback))

    if not classes:
        classes = ["zebra", "records", "paging"]
    if record_url is not None:
        classes = classes + [u"{record_url: '%s'}" % record_url]

    if wrapper is True:
        plugins.append(DTWrapper(classes=classes, style="width: 100%;"))
    if make_selectable is not False and make_selectable != runtime.UNDEFINED:
        plugins.append(DTSelectable(make_selectable))
    if row_formatter is not False and row_formatter != runtime.UNDEFINED:
        plugins.append(DTRowFormatter(test=row_formatter[0], **row_formatter[1]))
    plugins.extend(additional_plugins)
    table = table_class(plugins=plugins, finalize=wrapper)
    return xmlstring(table.build(queryset, columns=fields, exclude=exclude))
コード例 #3
0
ファイル: ajax.py プロジェクト: xealot/django-helpers
def stub(queryset, params, record_url, fields=(), exclude=(), listfield_callback=None, make_selectable=False, linker=False, additional_plugins=()):
    plugins = get_plugins(queryset, params, record_url, fields, exclude, listfield_callback, make_selectable, linker, wrapper=True, additional_plugins=additional_plugins)
    table = ModelTable(plugins=plugins)
    return xmlstring(table.build(queryset, columns=fields, exclude=exclude))