Personal tools
You are here: Home Lists ZPUG DC List Archives 2005 2005-03 Re: Welcome to [ZPUGDC] / prabuddha ray <buddharay@gmail.com>
Navigation
Log in


Forgot your password?
New user?
Mailing Lists
You can read our ZPUGDC mailing list archives online.
You can subscribe to our mailing list:
Book Review

The Definitive Guide to Plone

Reviewer: joel
 

Re: Welcome to [ZPUGDC] / prabuddha ray <buddharay@gmail.com>

Re: Welcome to [ZPUGDC]
prabuddha ray <buddharay(at)gmail.com>
2005-03-10 00:08:29 [ FULL ]
I'm a newbie working on govt. project as a trainee.

I've this small prob. kindly help.

In a dtml document i've 2 dropdownlist for district and users respectively.
when a user selects a district the users of that district should get
filled up in the 2nd dropdownlist.
I'm getting the districts from a ZSQL method . i've another ZSQL
method to get the users taking districtname as parameter.
1> for this i've to reload the page on changing selection from the
districtlist.
further i need 
2>to pass the district name as parameter from the request form variables.

how do i accomplish this two.



On Wed, 09 Mar 2005 23:56:13 -0600, zpugdc(at)lists.zpugdc.org wrote:[...]
[...]

Re: Welcome to [ZPUGDC] / Jules <jules@jules.com>

Re: Welcome to [ZPUGDC]
Jules <jules(at)jules.com>
2005-03-10 07:33:49 [ FULL ]
Hello, and welcome to the DC ZPUG.

I'd offer some sample code but I haven't done DTML in years I'm afraid. 
Is there a reason your project isn't using ZPTs?

So, obviously, you can refresh the whole page and populate the second 
list each time you select a different user. You can do this with 
javascript -- when you select a user, the page refreshes. Or you can 
add a submit button at the bottom should a user have javascript turned 
off.

As you probably know, if it's federal government you have to follow the 
Section 508 guidelines. You call the same page and check for 'user' 
submitted variable. Then you show the SQL data based on the user you 
passed in.

<span tal:condition="user_name|nothing" tal:omit-tag="">
    <!-- Show the refreshed data here... -->
</span>

Yet another way to do it is to use the XMLHttpRequest object and call a 
Python wrapper to your SQL data. Google is full of examples on how to 
make this work. It doesn't require a page refresh which is very nifty.

It doesn't sound to me like I've fully answered your question but if 
you post some more I'm sure we can work it out for you.

Good luck!
Jules

On Mar 10, 2005, at 1:21 AM, prabuddha ray wrote:
[...]

Re: Welcome to [ZPUGDC] / prabuddha ray <buddharay@gmail.com>

Re: Welcome to [ZPUGDC]
prabuddha ray <buddharay(at)gmail.com>
2005-03-11 00:56:08 [ FULL ]
thnx jules so much.
 I never expected this much.
now after readin ur mail i tried the whole page in ZPT.
two things done here are :

<select name=districtname style="HEIGHT: 22px; WIDTH: 185px"
onchange="user10()">
    <option name="selectDistrict" selected> 
    <div tal:repeat="district container/getDistrict">
        <option tal:content="district/district_name"></option>  
    </div>
</select>
this was for 1st dropdown list ;

<select name=username style="HEIGHT: 22px; WIDTH: 185px">
   <div tal:repeat="user
python:context.getDistrictUser(districtname=request.form['districtname'])">
       <option tal:content="user/username"></option>  
   </div>
</select>

this one for the 2nd one to be filled.

now an obvious error comes up.
 Error Type
KeyError Error Value
'districtname'

I guess this is coz districtname is not available wen the page loads 1st time.
kindly tel if there is anyway to initialiaze the request var
districtname using an ifelse loop.
so sud i take that ZPTs are better than DTML docs for database based web pages?
hope dint bug u up.

I'm tryin the XMLhttprequest thingi but not working good for ZSQL method.
 hope to hear from u soon.


On Thu, 10 Mar 2005 08:47:16 -0500, Jules <jules(at)jules.com>
wrote:[...]
[...]

Re: Welcome to [ZPUGDC] / Jules <jules@jules.com>

Re: Welcome to [ZPUGDC]
Jules <jules(at)jules.com>
2005-03-11 07:52:14 [ FULL ]
I think you'll be much happier and productive with ZPTs.

In the body tag define:

<body tal:define="doDistrict request/districtname|nothing">

On Mar 11, 2005, at 2:09 AM, prabuddha ray wrote:
[...]

tal:condition="doDistrict"
[...]

That should get rid of the error.

In your Python script getDistricUser you could also, by default, assume  
that you're passing in districtname. Then you could just say

	<div tal:repeat="user here/getDistrictUser">

which is more pleasing to the eye.

In essence when using ZPTs you should try and pass off anything mildly  
complex to Python scripts. Doing serious logic in ZPTs is (by design)  
hard to do.
[...]

Indeed. By saying "or nothing" when you define your variable doDistrict  
you can then test for it later. And it evaluates to false on the first  
pass.

But if your logic in your python script tests for the districtname  
variable, you can do away with testing for it in the ZPT. And you end  
up with a blank second <select> which is a better visual cue for the  
user. Your python script should return a dictionary.

Does that make sense?
[...]

I'm not 100% sure what you're trying to do with this.
[...]

DTML isn't dead and it has its uses. But you're more likely to get help  
and have an app that's structured if you use ZPTs.
[...]

Not at all. We're all here to help each other.
[...]

Wrap the ZSQL method with a Python script.

Re: Welcome to [ZPUGDC] / prabuddha ray <buddharay@gmail.com>

Re: Welcome to [ZPUGDC]
prabuddha ray <buddharay(at)gmail.com>
2005-03-12 03:21:43 [ FULL ]
kudos to u ceasar,
                         I got it finally. jus a matter of placing the
define tag in body. i'll be in tuch to bother u for more. thanks a lot
for finding time for this newbie.

An interesting thing is happening. wen the page loads for 1st time the
2nd combobox is not there n wen i select the district from 1st list
the page reloads n the user list appears. is it coz i placed the
tal:condition in the 2nd select tag?

 some tips required from ur mail
 1.  u wrote: 
In your Python script getDistricUser you could also, by default, assume
that you're passing in districtname. Then you could just say
       <div tal:repeat="user here/getDistrictUser">
which is more pleasing to the eye.
In essence when using ZPTs you should try and pass off anything mildly
complex to Python scripts. Doing serious logic in ZPTs is (by design)
hard to do.

how do i pass the default parameter here wen i need to pass the
districtname req val?

2. abt XMLHTTPRequest u wrote : Wrap the ZSQL method with a Python script.

how do i return the result from the ZSQL method from the python script ?
Will multiple row result be returned correctly ?

thnx again for finding time.
 


[...]

Re: Welcome to [ZPUGDC] / Jules <jules@jules.com>

Re: Welcome to [ZPUGDC]
Jules <jules(at)jules.com>
2005-03-12 10:42:59 [ FULL ]
On Mar 12, 2005, at 4:35 AM, prabuddha ray wrote:
[...]

It'll be in the request object.

try:
     dist = request.districtname
except KeyError:
     return

# rest of script...
[...]

Even though it's called XMLHttpRequest there's nothing forcing you to 
return XML. you can just return text and split it if you like.

Powered by Plone, the Open Source Content Management System

This site conforms to the following standards: