Forum OpenACS Development: Creating a .CSV file with OpenACS

Request notifications

Collapse
Posted by Juan Carlos on
Hi, im trying to create a .CSV file with the contents of a list template in OpenACS.

I added this to my list
-selected_format csv \
-formats {
csv { output csv }
}

And I can create the file with
template::list::write_output -name list_name

However, this creates the file when I create the list, and also, it doesn't show me the list in my browser. I need to create a button that generates the file. ¿How could I do that?

Collapse
Posted by Brian Fenton on
Hi Juan

well, it sounds like you want both the list displayed on screen, and the CSV file downloaded, is that right? You could have a form where the user chooses the format they want (list or CSV). Then in your list do something like this:

set selected_format "normal"
if {$parameter_csv == 1} {
  set selected_format "csv"
  set groupby ""  
} 

(Setting groupby to empty string fixed some problems for me, you might not need it).

Then in your list itself, do something like this

template::list::create \
  -name $list_name \
  -multirow tickets \
  -numeric_type "Integer" \
  -caption "[_ aims-client.FinSummaryListCaption]" \
  -no_data "[_ aims-client.FinSummaryNoneAvailable]" \
  -elements $elements_list \
  -pass_properties {locale } \
  -selected_format $selected_format \
  -formats {
              csv { output csv }
            } \
  -orderby $orderby_list \
  -groupby $groupby_list \
  -filters $filter
Finally after you've created your list and multitrow, you just need to call this:
if {$parameter_csv == 1} {
  template::list::write_output -name $list_name
}

Collapse
Posted by Juan Carlos on
Thanks. It worked.