Hi all, I have a form where the users enter the entries as a name value pair. I have to save this info as text to be used later in a batch mode. I am new to Zope and python and i am having trouble figuring out how this can be done. I would highly appreciate if someone could send me some pointers or some sample code. So far i haven't been able to get anything useful from google. Thanks in advance, vikx __________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus
vivek singh wrote:
Hi all,
I have a form where the users enter the entries as a name value pair. I have to save this info as text to be used later in a batch mode. I am new to Zope and python and i am having trouble figuring out how this can be done. I would highly appreciate if someone could send me some pointers or some sample code. So far i haven't been able to get anything useful from google.
Thanks in advance, vikx
__________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Here you have a form that collects data, and two scripts: -getAprovelist retrieves the stored data -setAprovelist writes the stored data And a page-template that displays and sets the data just put all the thre in a folder (2 scripts, one page template) and name them correctly As datastore you need a DTML Method at the same place named "aprovelist" HTH Robert ----------------------------------------------------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" metal:use-macro="here/main_template/macros/master"> <body> <div metal:fill-slot="main"> <h1 i18n:translate="">Please adapt the state of the accounts</h1> <form class="group" action="setAprovelist" method="post"> <span class="legend" i18n:translate="">Known users</span> <table style="width:100%; margin-left:30;margin-rigth:30"> <tr> <th align="left" class="field">Member</th> <th align="left" class="field">Email</th> <th align="left" class="field">Approval Manager</th> <th align="left" class="field">Approved?</th> </tr> <tr class="row" tal:repeat="user here/getAprovelist"> <td> <input type="hidden" name="users.username:records" tal:attributes="value python:user[0]"/> <span tal:omit-tag="" tal:content="python:user[0]" /> <br /> <hr /> </td> <td> <input type="hidden" name="users.email:records" tal:attributes="value python:user[1]"/> <span tal:omit-tag="" tal:content="python:user[1]" /> <br /> <hr /> </td> <td> <input type="hidden" name="users.accessmanager:records" tal:attributes="value python:user[2]"/> <span tal:omit-tag="" tal:content="python:user[2]" /> <br /> <hr /> </td> <td valign="top"> <input type="checkbox" name="users.aproved:records" tal:attributes="checked python:test(user[3].strip()=='1', 1,0)" value="1" /> </td> </tr> </table> <input type="submit" value="save" /> </form> </div> </body> </html> ---------------------------------------- aprovelist is a DTML--Method ----------------------------------------- ----------------------------------------- script getAprovelist ----------------------------------------- ## Script (Python) "getAprovelist" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=username='', status=None ##title=(hat kein proxy) ## aprove=container.aprovelist() aprove = aprove.replace('\n','\r') aprovelines = string.split(aprove, '\r') aprovelist = [] aprovedic = {} for person in aprovelines: if len(person.strip()): try: name,email,supervisor,OK = person.split(',')[:4] aprovelist.append((name,email,supervisor,OK)) aprovedic[name] = OK except: continue # do we have to check a single person if len(username) and aprovedic.has_key(username): return aprovedic[username] elif len(username): return 0 return aprovelist ------------------------------------------- script setAprovelist ----------------------------------------- ## Script (Python) "setAprovelist" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=users ##title=(hat proxy) ## aprove = getattr(context, 'aprovelist') result = [] for x in users: if x.has_key('aproved'): result.append("%s,%s,%s,%s" % (x['username'].strip(),x['email'].strip(),x['accessmanager'].strip(),x['aproved'].strip())) else: result.append("%s,%s,%s,%s" % (x['username'].strip(),x['email'].strip(),x['accessmanager'].strip(),'0')) aprove.manage_edit( string.join(result, '\r'),'') context.REQUEST.RESPONSE.redirect("%s/manage_users_form" % context.absolute_url())
Thanks Robert for the prompt response. I have followed your directions. However when I view the DTML doc, I do not get the text fields where I can enter the values. Am I doing something wrong? Thanks again. Vivek --- robert rottermann <robert@redcor.ch> wrote:
vivek singh wrote:
Hi all,
I have a form where the users enter the entries as a name value pair. I have to save this info as text to be used later in a batch mode. I am new to Zope and python and i am having trouble figuring out how this can be done. I would highly appreciate if someone could send me some pointers or some sample code. So far i haven't been able to get anything useful from google.
Thanks in advance, vikx
__________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
Here you have a form that collects data, and two scripts: -getAprovelist retrieves the stored data -setAprovelist writes the stored data And a page-template that displays and sets the data
just put all the thre in a folder (2 scripts, one page template) and name them correctly As datastore you need a DTML Method at the same place named "aprovelist"
HTH Robert
-----------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"
metal:use-macro="here/main_template/macros/master"> <body>
<div metal:fill-slot="main">
<h1 i18n:translate="">Please adapt the state of the accounts</h1>
<form class="group" action="setAprovelist" method="post">
<span class="legend" i18n:translate="">Known users</span> <table style="width:100%; margin-left:30;margin-rigth:30"> <tr> <th align="left" class="field">Member</th> <th align="left" class="field">Email</th> <th align="left" class="field">Approval Manager</th> <th align="left" class="field">Approved?</th> </tr>
<tr class="row" tal:repeat="user here/getAprovelist"> <td> <input type="hidden" name="users.username:records" tal:attributes="value python:user[0]"/> <span tal:omit-tag="" tal:content="python:user[0]" /> <br /> <hr /> </td> <td> <input type="hidden" name="users.email:records" tal:attributes="value python:user[1]"/> <span tal:omit-tag="" tal:content="python:user[1]" /> <br /> <hr /> </td> <td> <input type="hidden" name="users.accessmanager:records" tal:attributes="value python:user[2]"/> <span tal:omit-tag="" tal:content="python:user[2]" /> <br /> <hr />
</td> <td valign="top"> <input type="checkbox" name="users.aproved:records" tal:attributes="checked python:test(user[3].strip()=='1', 1,0)" value="1" /> </td> </tr> </table> <input type="submit" value="save" /> </form>
</div>
</body>
</html>
---------------------------------------- aprovelist is a DTML--Method ----------------------------------------- ----------------------------------------- script getAprovelist -----------------------------------------
## Script (Python) "getAprovelist" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=username='', status=None ##title=(hat kein proxy) ## aprove=container.aprovelist() aprove = aprove.replace('\n','\r') aprovelines = string.split(aprove, '\r') aprovelist = [] aprovedic = {}
for person in aprovelines: if len(person.strip()): try: name,email,supervisor,OK = person.split(',')[:4]
aprovelist.append((name,email,supervisor,OK)) aprovedic[name] = OK except: continue
# do we have to check a single person if len(username) and aprovedic.has_key(username): return aprovedic[username] elif len(username): return 0
return aprovelist
------------------------------------------- script setAprovelist -----------------------------------------
## Script (Python) "setAprovelist" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=users ##title=(hat proxy) ## aprove = getattr(context, 'aprovelist') result = [] for x in users: if x.has_key('aproved'): result.append("%s,%s,%s,%s" %
(x['username'].strip(),x['email'].strip(),x['accessmanager'].strip(),x['aproved'].strip()))
else: result.append("%s,%s,%s,%s" %
(x['username'].strip(),x['email'].strip(),x['accessmanager'].strip(),'0'))
=== message truncated === __________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus
vivek singh wrote:
Thanks Robert for the prompt response. I have followed your directions. However when I view the DTML doc, I do not get the text fields where I can enter the values. Am I doing something wrong?
Thanks again. Vivek
--- robert rottermann <robert@redcor.ch> wrote:
vivek singh wrote:
Hi all,
I have a form where the users enter the entries as
a
name value pair. I have to save this info as text
to
be used later in a batch mode. I am new to Zope and python and i am having trouble figuring out how
this
can be done. I would highly appreciate if someone could send me some pointers or some sample code. So far i haven't been able to get anything useful from google.
Thanks in advance, vikx
__________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus"
Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
Here you have a form that collects data, and two scripts: -getAprovelist retrieves the stored data -setAprovelist writes the stored data And a page-template that displays and sets the data
just put all the thre in a folder (2 scripts, one page template) and name them correctly As datastore you need a DTML Method at the same place named "aprovelist"
HTH Robert
-----------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"
metal:use-macro="here/main_template/macros/master"> <body>
<div metal:fill-slot="main">
<h1 i18n:translate="">Please adapt the state of the accounts</h1>
<form class="group" action="setAprovelist" method="post">
<span class="legend" i18n:translate="">Known users</span> <table style="width:100%; margin-left:30;margin-rigth:30"> <tr> <th align="left" class="field">Member</th> <th align="left" class="field">Email</th> <th align="left" class="field">Approval Manager</th> <th align="left" class="field">Approved?</th> </tr>
<tr class="row" tal:repeat="user here/getAprovelist"> <td> <input type="hidden" name="users.username:records" tal:attributes="value python:user[0]"/> <span tal:omit-tag="" tal:content="python:user[0]" /> <br /> <hr /> </td> <td> <input type="hidden" name="users.email:records" tal:attributes="value python:user[1]"/> <span tal:omit-tag="" tal:content="python:user[1]" /> <br /> <hr /> </td> <td> <input type="hidden" name="users.accessmanager:records" tal:attributes="value python:user[2]"/> <span tal:omit-tag="" tal:content="python:user[2]" /> <br /> <hr />
</td> <td valign="top"> <input type="checkbox" name="users.aproved:records" tal:attributes="checked python:test(user[3].strip()=='1', 1,0)" value="1" /> </td> </tr> </table> <input type="submit" value="save" /> </form>
</div>
</body>
</html>
---------------------------------------- aprovelist is a DTML--Method ----------------------------------------- ----------------------------------------- script getAprovelist -----------------------------------------
## Script (Python) "getAprovelist" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=username='', status=None ##title=(hat kein proxy) ## aprove=container.aprovelist() aprove = aprove.replace('\n','\r') aprovelines = string.split(aprove, '\r') aprovelist = [] aprovedic = {}
for person in aprovelines: if len(person.strip()): try: name,email,supervisor,OK = person.split(',')[:4]
aprovelist.append((name,email,supervisor,OK)) aprovedic[name] = OK except: continue
# do we have to check a single person if len(username) and aprovedic.has_key(username): return aprovedic[username] elif len(username): return 0
return aprovelist
------------------------------------------- script setAprovelist -----------------------------------------
## Script (Python) "setAprovelist" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=users ##title=(hat proxy) ## aprove = getattr(context, 'aprovelist') result = [] for x in users: if x.has_key('aproved'): result.append("%s,%s,%s,%s" %
(x['username'].strip(),x['email'].strip(),x['accessmanager'].strip(),x['aproved'].strip()))
else: result.append("%s,%s,%s,%s" %
(x['username'].strip(),x['email'].strip(),x['accessmanager'].strip(),'0'))
=== message truncated ===
__________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
You must not view the dtml but the page template. The dtml only serves as a container of your data. Robert
vivek singh wrote:
I have a form where the users enter the entries as a name value pair. I have to save this info as text to be used later in a batch mode. I am new to Zope and python and i am having trouble figuring out how this can be done. I would highly appreciate if someone could send me some pointers or some sample code. So far i haven't been able to get anything useful from google.
To the filesystem? In that case, write an External Method that writes a file to disk as appropriate. Have it take the parameters that you want to write (or perhaps a dictionary) and use those to create your output. See http://www.python.org/doc/current/lib/bltin-file-objects.html Have your form submit to a Python Script that takes the necessary info out of context.REQUEST and passes that to the external method above. Have it return the next page or redirect there. --jcc -- "Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design." (http://www.devx.com/java/editorial/15511)
participants (3)
-
J Cameron Cooper -
robert rottermann -
vivek singh