Hi,
Me and DaveB did some discussion about this:
https://openacs.org/bugtracker/openacs/com/acs-tcl/bug?bug%5fnumber=630
I guess you might have noticed both patches was refused because it did not work 100%. After my failure on patching it too. Me and DaveB finally decided to use ad_conn as the global var to know if ad_page_contract was already used or not.
I have gone away with the implementation. So far it does seem to work. The following cases work:
- basic includes
- includes coming from rp_internal_redirect
- includes coming from explicit ad_template_return
The following behaviour of ad_page_contract was changed. It only gets form vars in first pass. Succeeding passes, which should be likely in an include you will need to pass the var on the include. Of course the include will complain that notnull vars are not passed, just as if its a standalone .tcl file. The good side of this is that we can use ad_page_contract to enforce rules on includes. I can't find the thread where DaveB started to discuss about this. Maybe someone can point it out. The merits of what DaveB wants to achieve is something that is positive.
If my current implementation is to be applied, it might break existing code that depends on this situation:
- includes that makes use of ad_page_contract that does not involve the parent doc. That means reusing ad_page_contract instead of properly passing the vars on the includes. Can be corrected by properly passing the vars.
- 2nd calls of ad_page_contract in rp_internal_redirect.
ex.
index.vuh
ad_page_contract {} {foo:notnull} {}
mypage
ad_page_contract {} {bar:notnull} {}
on mypage "bar" must be passed not via form vars.
I think this is a more proper behaviour of ad_page_contract, but what are your thoughts? It may break some code. If it does break a lot of code. Maybe we can create a switch on ad_page_contract to function in an include only, bad side is that .tcl file can not be used if its not used as an include.
Here is a the patch: The later part is needed because ad_page_contract by nature will clobber local vars. Since it does assume its the first thing that is called. So I added some checking on those.
diff -u -r1.1.1.1 tcl-documentation-procs.tcl
--- packages/acs-tcl/tcl/tcl-documentation-procs.tcl 15 Jul 2003 12:05:50 -0000 1.1.1.1
+++ packages/acs-tcl/tcl/tcl-documentation-procs.tcl 21 Sep 2003 17:03:08 -0000
@@ -46,6 +46,32 @@
set ad_conn(api_page_documentation_mode_p) $page_documentation_mode_p
}
+ad_proc -private page_form_data_gathered_p {} {
+ Checks if the ad_page_contract has already been processed once, this is used
+ to check if a page that is in includes will not form process the vars
+ but rather get the vars from passed values on the the include tag
+
+ @return true if the thread has already processed ad_page_contract
+} {
+ global ad_conn
+ if { [info exists ad_conn(page_form_data_gathered_p)] } {
+ return $ad_conn(page_form_data_gathered_p)
+ }
+ return 0
+}
+
+ad_proc -private set_page_form_data_gathered { page_status } {
+ set a flag to see if the page through ad_page_contract has finished gathering
+ data
+
+ @param page_status set to true if page has gathered data
+
+ @see page_form_data_gathered_p
+} {
+ global ad_conn
+ set ad_conn(page_form_data_gathered_p) $page_status
+}
+
####################
#
# Complaints procs
@@ -820,6 +846,11 @@
# Step 2: Go through all the actual arguments supplied in the form
#
####################
+
+ # check to see if we have processed the ad_page_contract once,
+ # if yes skip through this block of code
+ # big if - start
+ if {![page_form_data_gathered_p]} {
set form [ns_getform]
@@ -943,6 +974,12 @@
}
}
}
+
+ # we have already process the form vars once, set its status
+ set_page_form_data_gathered 1
+ # big if - end
+ }
+
####################
#
@@ -998,7 +1035,7 @@
# no value supplied for this arg spec
- if { [info exists apc_default_value($formal_name)] } {
+ if { [info exists apc_default_value($formal_name)] && ![info exists var] } {
# Only use the default value if there has been no complaints so far
# Why? Because if there are complaints, the page isn't going to serve anyway,
@@ -1012,7 +1049,7 @@
}
}
- } elseif { ![info exists apc_internal_filter($formal_name:optional)] } {
+ } elseif { ![info exists apc_internal_filter($formal_name:optional)] && ![info exists var] } {
ad_complain -key $formal_name "You must supply a value for $formal_name"
}
}