template::list::write_csv (public)

 template::list::write_csv -name name [ -delimiter delimiter ]

Defined in packages/acs-templating/tcl/list-procs.tcl

Writes a CSV to the connection

Switches:
-name (required)
-delimiter (optional, defaults to ",")

Partial Call Graph (max 5 caller/called nodes):
%3 Class ::Generic::List Class ::Generic::List (public) template::list::write_csv template::list::write_csv Class ::Generic::List->template::list::write_csv template::list::write_output template::list::write_output (public) template::list::write_output->template::list::write_csv ad_script_abort ad_script_abort (public) template::list::write_csv->ad_script_abort template::list::csv_quote template::list::csv_quote (public) template::list::write_csv->template::list::csv_quote template::list::element::get_reference template::list::element::get_reference (public) template::list::write_csv->template::list::element::get_reference template::list::get_reference template::list::get_reference (public) template::list::write_csv->template::list::get_reference template::list::prepare_for_rendering template::list::prepare_for_rendering (private) template::list::write_csv->template::list::prepare_for_rendering

Testcases:
No testcase defined.
Source code:
    # Creates the '_eval' columns and aggregates
    template::list::prepare_for_rendering -name $name

    get_reference -name $name

    set __list_name $name
    set __output {}
    set __groupby $list_properties(groupby)

    # Output header row
    set __cols [list]
    set __csv_cols [list]
    set __csv_labels [list]

    foreach __element_name $list_properties(display_elements) {
        template::list::element::get_reference -list_name $name -element_name $__element_name
        if {!$element_properties(hide_p)} {
            lappend __csv_cols $__element_name
            lappend __csv_labels [csv_quote $element_properties(label)]
        }
    }
    append __output "\"[join $__csv_labels "\"$delimiter\""]\"\n"

    set __rowcount [template::multirow size $list_properties(multirow)]
    set __rownum 0
    # Output rows
    template::multirow foreach $list_properties(multirow) {
        set group_lastnum_p 0
        if {$__groupby ne ""} {
            if {$__rownum < $__rowcount} {
                # check if the next row's group column is the same as this one
                set next_group [template::multirow get $list_properties(multirow) [expr {$__rownum + 1}] $__groupby]
                if {[set $__groupby] ne $next_group} {
                    set group_lastnum_p 1
                }
            } else {
                set group_lastnum_p 1
            }
            incr __rownum
        }

        if {$__groupby eq ""  || $group_lastnum_p} {
            set __cols [list]

            foreach __element_name $__csv_cols {
                if {![string match "*___*_group" $__element_name]} {
                    template::list::element::get_reference  -list_name $__list_name  -element_name $__element_name  -local_name __element_properties
                    if { [info exists $__element_properties(csv_col)] } {
                        lappend __cols [csv_quote [set $__element_properties(csv_col)]]
                    } else {
                        lappend __cols [csv_quote [set $__element_name]]
                    }
                } {
                    lappend __cols [csv_quote [set $__element_name]]
                }
            }
            append __output "\"[join $__cols "\"$delimiter\""]\"\n"
        }
    }
    set oh [ns_conn outputheaders]
    ns_set put $oh Content-Disposition "attachment; filename=${__list_name}.csv"
    ns_return 200 text/csv $__output
    ad_script_abort
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: