wiki.zope.jp
QuickPollJ
   
RecentChanges WikiHelp WikiPractice JumpSearch

QuickPollJ


簡易アンケート

著者: Ioan 最終変更日: 2001/11/14.

target="_blank">QuickSurvey の後は、Quick Poll (簡易アンケート) を使ってみましょう。



This how-to will help the beginners to create quick and short (just one question) surveys.
この HowTo? は、簡単なアンケート(質問は1問だけ)を、初心者でも作れるように説明します。

It looks like target="_blank">HostTracker.
見た目は、HostTracker に似ています。

First you will need to install target="_blank">TinyTablePlus and Zope 2.3.x
まず、target="_blank">TinyTablePlus と Zope 2.3.x をインストールします。

(Zope 2.3.x is much better because I like Python scripts, but on Zope 2.2.x you may use External python methods.)

(私は Python script を好んで使うので、Zope 2.3.x のほうが都合が良いですが、Zope 2.2.x でも External python method を使えます。)

Then you have to create 3 TinyTablePlus, 2 DTML methods and a Python Script.
つぎに TinyTablePlus を3つ、DTML methodを 2つ、 Python Script をひとつ作成します。

All these objects can be created and edited from management interface of Zope from your Internet Browser (IE, Netscape and so on).
これらのオブジェクトはすべて、ブラウザ (IE, Netscape など) からアクセスできる Zope の管理画面から作成、編集が可能です。


TinyTablePlus id: snames
Title: Short Survey Names
Columns: surv ans name
Data:
"s1", "s1", "Do you visit this web site on a regular basis?"
"s1", "a1", "daily"
"s1", "a2", "weekly"
"s1", "a3", "ocassionally"
"s1", "a4", "rarely"

"s2", "s2", "Do you like the new look of this site?"
"s2", "a1", "Yes"
"s2", "a2", "No"


What that means?
You have two questions: s1 and s2.
Answers are a1, a2, ...

Fill snames table with more items to get the picture.



TinyTablePlus id: svalues
Title: Short Survey Values
Columns: surv ans counter
Data:
--- leave it blank ---

In this table you will collect the results.
Don't edit this table. Clear all results if you like, but don't edit.


TinyTablePlus id: hostlist
Title: List of IP
Columns: name
Data:
--- leave it blank ---

In this table you will keep IP of computers which vote.
Clear this table when you post a new survey.

DTML Method id: list
Title: List all short surveys
Body
<dtml-var standard_html_header>
<h1>Quick Poll Survey</h1>

<dtml-in snames> <dtml-if "surv==ans"> <dtml-var "s_survey.draw_survey(s_survey,surv,0)"> <hr> </dtml-if> </dtml-in> <dtml-var standard_html_footer>

That means this script will call draw_survey which is in s_survey folder of Zope FileSystem?.

So if you want to call the Survey from your documents (home.htm or index.htm or index_html) you must :
....
<dtml-var "s_survey.draw_survey(s_survey,s1,0)">
....
Which will display the survey in read only mode (parameter 0 at end).


DTML Method id: sredirect
Title:Update survey and redirect back to caller page
Body
<dtml-if ans>
<dtml-call "REQUEST.set(cnt,0)">
<dtml-in "hostlist(name=REMOTE_ADDR)">
<dtml-var standard_html_header>
<center><br><br><br>
<h1>Oops! You did it again!</h1>
</center>
<dtml-var standard_html_footer>

<dtml-else> <dtml-in "svalues(surv=surv,ans=ans)"> <dtml-call "REQUEST.set(cnt,counter)"> </dtml-in> <dtml-call "REQUEST.set(cnt,_.int(cnt)+1)"> <dtml-call "svalues.delRows(surv=surv,ans=ans)"> <dtml-call "svalues.setRow(surv=surv,ans=ans,counter=cnt)"> <dtml-call "hostlist.setRow(name=REMOTE_ADDR)"> <dtml-call "RESPONSE.redirect(HTTP_REFERER)"> </dtml-in> </dtml-if>


This is the action script of form used to fill the survey.


Script (Python): draw_survey
Title : Python script which display survey table
Parameter List: self,surv,listing=1
Body:
ret='
ret=ret+<form method="post" action="s_survey/sredirect">
ret=ret+<input type="hidden" name="surv" value="'+surv+"&gt;
for i in self.snames(surv=surv,ans=surv):
 ret=ret+'<b>+i.name+</b><br>
ret=ret+<table>'

max=0 sum=0 length_bar=250 for i in self.snames(surv=surv): if surv!=i.ans: for j in self.svalues(surv=surv,ans=i.ans): sum=sum+int(j.counter) if max<int(j.counter): max=int(j.counter)

for i in self.snames(surv=surv): if surv!=i.ans: cnt=0 for j in self.svalues(surv=surv,ans=i.ans): cnt=int(j.counter) ret=ret+&lt;tr&gt; if int(listing)==1: ret=ret+'<td><input type="radio" name="ans" value="'+i.ans+'">+i.name+</td> else: ret=ret+<td>+i.name+</td> if sum&gt;0 : ret=ret+<th>+str(cnt)+</th><th>('+str(cnt*100/sum)+'%)</th><td><img src="/img/box/bar.gif" border=0 width=+str(cnt*length_bar/max)+ height=10> ret=ret+</td></tr></table> if int(listing)==1 : ret=ret+<input type="submit" value="Answer"> ret=ret+</form>'

return ret

This Python script will return the html table.
Call this script like that:
<dtml-var "s_survey.draw_survey(s_survey,surv=s2)">
So self=s_survey and surv=s2

Parameter listing is 0 for survey and 1 for read only (display only) survey.
If you don't give this parameter, it will be 0 by default.

Don't forget to create a picture (single color 3x3 pixels is ok) and to update the path to it.
On draw_survey Python script my picture is at /img/box/bar.gif
Keep the spaces on Python scripts. Python need spaces to understand where are his instruction blocks.

That's all! Feel free to e-mail me with questions.

Last edited Sat, 16 Sep 2006 16:15:49 +0900 Edit this page