Forum OpenACS Q&A: Tutorial package confusion

Collapse
Posted by Joe Cooper on
Hi all,

I've religiously followed chapter 9 of the 5.1 documentation (the "My First Package" tutorial), and while I've gotten the application working with a minor tweak on my 5.1.5 installation, I'd like to understand things a bit better.

In order to make the mfp::note::add call in note-edit.tcl work, I had to add "-item_id $item_id". Without it, the procedure in note-procs.tcl fails because of the "-item_id:required" statement.

Since the comments indicate the item_id should auto-magically happen when none exists...which procedure is wrong? Should mfp::note::add have an optional item_id argument, or should all callers provide an item_id? If the latter, where does the item_id come from?

I'm assuming the former, since the test case tutorial also calls the add proc without an item_id. But I don't really know what to do with that assumption.

Thanks for any clarity anyone can provide.

Collapse
Posted by Harish Krishnan on
Joe,there is nothing wrong with the procedure. An item_id should be provided to the mfp::note::add call. The item_id is created by the ad_form procedure. In the ad_form constructed on the note-edit.tcl page the item_id is set by " {item_id:key}". The key is dynamically generated from the sequence acs_object_id_seq. Check the ad_form documentation [1] for further reading.
In the end the item_id should be available when the form is submitted when creating a new note.

[1] https://openacs.org/api-doc/proc-view?proc=ad%5fform

Collapse
Posted by Joe Cooper on
Thanks for the pointer to the ad_form docs, Harish. Very useful. I had been reading about the old form generator procedures...ad_form looks much nicer.

Since the item_id is required (and should be), my question becomes, "Why was the tutorial and test case written without the item_id included in the call to mfp::note::add?" Was there a time when this variable magically followed the object around? I'm an utter newbie to both OACS and TCL, so forgive me if I'm being daft...I'm just trying to wrap my head around the design of OACS so I can get started on some simple apps of my own.

On a related note, since the :key needs to get passed around when dealing with ad_forms, how does one write a test case for an ad_form procedure. A grep of the test directories in the current OACS version turns up no obvious cases of ad_form tests. Can someone point me to a test suite that includes tests for ad_form procedures?

Specifically, I guess just a pointer for how to fix the provided test case in the tutorial so that it can pass the item_id would be sufficient to make the test tutorial make sense.

Collapse
Posted by Harish Krishnan on
You can even make item_id in the proc as optional. But in that case you will need to handle creation of the new item_id in the procedure. This is generally done at the stored procedure level. Check the new procedure for note or any other package, you will find that passing the note_id field optional.

Regarding test cases for ad_form, why do you think you need to bother if it is being handled by ad_form for you?

Collapse
Posted by Eric Wolfram on
I got the same error when doing the tutorial just now and had to add the -item_id $item_id \ to get it to work. I'd guess that this was simply an error in the docs -- an omission -- similar to how this:

"[$OPENACS_SERVICE_NAME postgresql]$ cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackages/www"

should actually be this:

"[$OPENACS_SERVICE_NAME postgresql]$ cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/www"

(note the myfirstpackage(s) part of those paths.

Anyway, here's the error message so those who run into this in the future might find it on google 😊

Required switch -item_id not provided
while executing
"mfp::note::add__arg_parser"
(procedure "mfp::note::add" line 1)
invoked from within
"mfp::note::add -title $title"
("uplevel" body line 2)
invoked from within
"uplevel #$level $new_data"
("1" arm line 598)
invoked from within
"switch $errno {
0 {
# TCL_OK
}
1 {
# TCL_E..."
(procedure "ad_form" line 612)
invoked from within