[Zope-dev] How to call the class in python file into zope script python.
¹Ú À缺
bigarea@korea.com
Mon, 24 Dec 2001 16:48:18 +0900
This is a multi-part message in MIME format.
------=_NextPart_000_457B_01C18C9A.C9DADAA0
Content-Type: text/plain;
charset="ks_c_5601-1987"
Content-Transfer-Encoding: quoted-printable
Hi. This is Seoul in SouthKorea.=20
First I excuse what I am not good at English.=20
I made a simple product(named BBSExpert.py) by python, tested it, and
succeeded.
There is the display() class in the BBSExpert.py.
I want to call this class (display() is located in the BBSExpert.py)
into zope base(ex. Script (python)).
These files are what I made.
**************************************************************
1. __init__.py
import BBSExpert
def initialize(context):=20
"""
"""
context.registerClass(
BBSExpert.BBSExpert,
constructors =3D (=20
BBSExpert.Manage_AddBBSExpertForm,
BBSExpert.Manage_AddBBSExpertAction
),
icon=3DNone
)
***********************************************************************
2. BBSExpert.py (display() class is located in this file.)
from Globals import HTMLFile=20
from Globals import MessageDialog=20
from Globals import Persistent
from Globals import DTMLFile
import OFS.SimpleItem=20
import Acquisition
import AccessControl.Role
import test
def Manage_AddBBSExpertAction(self, id=3D'BBSExpert', title=3D'Title =
here',
content=3D'Content here.',
REQUEST=3DNone):
"""
Add a BBSExpert to a folder.
"""
self._setObject(id, BBSExpert(id, title, content))
if REQUEST is not None:
return self.manage_main(self, REQUEST)
=20
# Get user id from this form
Manage_AddBBSExpertForm =3D DTMLFile('www/Manage_AddBBSExpertForm',
globals())
class BBSExpert(
OFS.SimpleItem.Item, # A simple Principia object. Not Folderish.=20
Persistent, # Make us persistent. Yaah!=20
Acquisition.Implicit, # Let us use our parent's variables and methods.
AccessControl.Role.RoleManager # Security manager.=20
):
=20
"""
BBSExpert Product
"""
meta_type =3D 'BBSExpert'
=20
manage_options =3D (
{'label': 'Properties', 'action': 'manage_editForm',},
{'label': 'View', 'action': 'index_html',},
)
=20
def __init__(self, id, title, content):
"Inits the product with default values"
self.id =3D id
self.title =3D title
self.content =3D content
def manage_editAction(self, title, content, RESPONSE=3DNone):
"Changes the product values"
self.title =3D title
self.content =3D content
self._p_changed =3D 1
RESPONSE.redirect('manage_editForm')
# The web pages that shows content. Put your own in the www folder.
def index_html(self):
"used to view content of the object"
return """<html><body>2pu hahaha</body></html>"""
def display(self):
"used to view content of the object"
return """<html><body> We are the world</body></html>"""
# Used to view content of the object
#index_html =3D DTMLFile('www/index_html', globals())
# Edit the content of the object
manage_editForm =3D DTMLFile('www/manage_editForm', globals())
Index_html.dtml********************************************
<dtml-if id>
<b>ID:</b><br>
<dtml-var id><br><br>
</dtml-if>
<dtml-if title>
<b>Title:</b><br>
<dtml-var title><br><br>
</dtml-if>
<dtml-if content>
<b>Content:</b><br>
<dtml-var content><br><br>
</dtml-if>
Manage_AddBBSExpertForm.dtml***************************************
<html>
<head>
<title>Add BBSExpert Instance</title>
</head>
<body bgcolor=3D"#FFFFFF">
<form name=3D"form" action=3D"Manage_AddBBSExpertAction" =
method=3D"post"><br>
id:<br>
<input type=3D"text" name=3D"id:string" size=3D"30"
value=3D"BBSExpert">
<br><br>
BBSExpert Title:<br>
<input type=3D"text" name=3D"title:string" size=3D"30"
value=3D"MyBBS">
<br><br>
Content:<br>
<textarea name=3D"content:text" cols=3D"40" rows=3D"8"
wrap=3D"virtual">Content here.</textarea>
<br><br>
<input type=3D"submit" value=3D" add ">
</form>
</body>
</html>
Manage_EditForm.dtml****************************************************
*
<html>
<head>
<title>Manage BBSExpert</title>
</head>
<body bgcolor=3D"#FFFFFF">
<dtml-var manage_tabs>
<form name=3D"form" action=3D"." method=3D"post"><br>
BBSTitle:<br>
<input type=3D"text" name=3D"title:string" size=3D"30" =
value=3D"<dtml-var
title>">
<br><br>
Content:<br>
<textarea name=3D"content:text" cols=3D"40" rows=3D"8"
wrap=3D"virtual"><dtml-var content></textarea>
<br><br>
<input type=3D"submit" value=3D"Change" =
name=3D"manage_editAction:method">
</form>
</body>
</html>
************************************************************************
*
3. Examplecode.txt (This part what I failed actually.)
(In Example.txt I could not return the display() class.=20
How could I call the display()class into Script (Python) in zope
management framework.)
# Example code:
# Import a standard function, and get the HTML request and response
objects.
from Products.PythonScripts.standard import html_quote
request =3D container.REQUEST
RESPONSE =3D request.RESPONSE
BBSExpert =3D context
return BBSExpert.display()
************************************************************************
****
Help me.
Thank you very much.
<http://www.korea.com> =C4=DA=B8=AE=BE=C6=B4=C2 =B4=E7=BD=C5=C0=BB =
=BB=E7=B6=FB=C7=D5=B4=CF=B4=D9
---------------------------------------
=BD=C5=B3=AA=B4=C2 =B0=D4=C0=D3, =B9=DD=B0=A1=BF=EE =C4=A3=B1=B8, =B1=D7 =
=B8=F0=B5=E7 =B0=CD=C0=CC =C0=CC=B0=F7=BF=A1!
=B4=EB=C7=A5 =B0=D4=C0=D3 =B8=DE=B0=A1 =C6=F7=C5=BB =
http://game.korea.com =09
=09
------=_NextPart_000_457B_01C18C9A.C9DADAA0
Content-Type: text/html;
charset="ks_c_5601-1987"
Content-Transfer-Encoding: 8bit
<BODY><P><BASEFONT face=±¼¸² size=2></BASEFONT><FONT face=±¼¸² size=2>Hi. This is Seoul in SouthKorea. <BR>First I excuse what I am not good at English. <BR><BR>I made a simple product(named BBSExpert.py) by python, tested it, and succeeded.<BR>There is the display() class in the BBSExpert.py.<BR>I want to call this class (display() is located in the BBSExpert.py) into zope base(ex. Script (python)).<BR><BR>These files are what I made.<BR><BR>**************************************************************<BR><BR>1. __init__.py<BR><BR>import BBSExpert</FONT></P>
<P><FONT face=±¼¸² size=2>def initialize(context): <BR> """<BR> """<BR> context.registerClass(<BR> BBSExpert.BBSExpert,<BR> constructors = ( <BR> BBSExpert.Manage_AddBBSExpertForm, BBSExpert.Manage_AddBBSExpertAction<BR> ),<BR> icon=None<BR> )<BR><BR><BR>***********************************************************************<BR>2. BBSExpert.py (display() class is located in this file.)<BR><BR>from Globals import HTMLFile <BR>from Globals import MessageDialog <BR>from Globals import Persistent<BR>from Globals import DTMLFile</FONT></P>
<P><FONT face=±¼¸² size=2>import OFS.SimpleItem <BR>import Acquisition<BR>import AccessControl.Role</FONT></P>
<P><FONT face=±¼¸² size=2>import test</FONT></P>
<P><FONT face=±¼¸² size=2>def Manage_AddBBSExpertAction(self, id='BBSExpert', title='Title here',<BR> content='Content here.', REQUEST=None):<BR> """<BR> Add a BBSExpert to a folder.<BR> """</FONT></P>
<P><FONT face=±¼¸² size=2> self._setObject(id, BBSExpert(id, title, content))<BR> if REQUEST is not None:<BR> return self.manage_main(self, REQUEST)<BR> <BR># Get user id from this form<BR>Manage_AddBBSExpertForm = DTMLFile('www/Manage_AddBBSExpertForm', globals())</FONT></P><FONT face=±¼¸² size=2>
<P><BR>class BBSExpert(<BR> OFS.SimpleItem.Item, # A simple Principia object. Not Folderish. <BR> Persistent, # Make us persistent. Yaah! <BR> Acquisition.Implicit, # Let us use our parent's variables and methods. <BR> AccessControl.Role.RoleManager # Security manager. <BR> ):<BR> <BR> """<BR> BBSExpert Product<BR> """</P>
<P> meta_type = 'BBSExpert'<BR> <BR> manage_options = (<BR> {'label': 'Properties', 'action': 'manage_editForm',},<BR> {'label': 'View', 'action': 'index_html',},<BR> )<BR> <BR> def __init__(self, id, title, content):<BR> "Inits the product with default values"<BR> self.id = id<BR> self.title = title<BR> self.content = content</P>
<P> def manage_editAction(self, title, content, RESPONSE=None):<BR> "Changes the product values"<BR> self.title = title<BR> self.content = content<BR> self._p_changed = 1<BR> RESPONSE.redirect('manage_editForm')</P>
<P> # The web pages that shows content. Put your own in the www folder.</P>
<P> def index_html(self):<BR> "used to view content of the object"<BR> return """<html><body>2pu hahaha</body></html>"""</P>
<P> def display(self):<BR> "used to view content of the object"<BR> return """<html><body> We are the world</body></html>"""</P>
<P><BR> # Used to view content of the object<BR> #index_html = DTMLFile('www/index_html', globals())</P>
<P> # Edit the content of the object<BR> manage_editForm = DTMLFile('www/manage_editForm', globals())<BR><BR><BR><BR>Index_html.dtml********************************************<BR><BR> <dtml-if id><BR> <b>ID:</b><br><BR> <dtml-var id><br><br><BR> </dtml-if></P>
<P> <dtml-if title><BR> <b>Title:</b><br><BR> <dtml-var title><br><br><BR> </dtml-if></P>
<P> <dtml-if content><BR> <b>Content:</b><br><BR> <dtml-var content><br><br><BR> </dtml-if><BR></P>
<P>Manage_AddBBSExpertForm.dtml***************************************<BR><BR><html><BR><head><BR><title>Add BBSExpert Instance</title><BR></head></P>
<P><body bgcolor="#FFFFFF"><BR> <form name="form" action="Manage_AddBBSExpertAction" method="post"><br><BR> id:<br><BR> <input type="text" name="id:string" size="30" value="BBSExpert"><BR> <br><br></P>
<P> BBSExpert Title:<br><BR> <input type="text" name="title:string" size="30" value="MyBBS"><BR> <br><br></P>
<P> Content:<br><BR> <textarea name="content:text" cols="40" rows="8" wrap="virtual">Content here.</textarea><BR> <br><br></P>
<P> <input type="submit" value=" add "><BR> </form></P>
<P></body><BR></html><BR><BR><BR><BR>Manage_EditForm.dtml*****************************************************<BR><BR><html><BR><head><BR><title>Manage BBSExpert</title><BR></head><BR><body bgcolor="#FFFFFF"></P>
<P> <dtml-var manage_tabs></P>
<P> <form name="form" action="." method="post"><br></P>
<P> BBSTitle:<br><BR> <input type="text" name="title:string" size="30" value="<dtml-var title>"><BR> <br><br></P>
<P> Content:<br><BR> <textarea name="content:text" cols="40" rows="8" wrap="virtual"><dtml-var content></textarea><BR> <br><br></P>
<P> <input type="submit" value="Change" name="manage_editAction:method"></P>
<P> </form></P>
<P></body><BR></html><BR><BR><BR>*************************************************************************<BR><BR>3. Examplecode.txt (This part what I failed actually.)<BR> (In Example.txt I could not return the display() class. <BR> How could I call the display()class into Script (Python) in zope management framework.)<BR><BR><BR># Example code:</P>
<P># Import a standard function, and get the HTML request and response objects.<BR>from Products.PythonScripts.standard import html_quote<BR>request = container.REQUEST<BR>RESPONSE = request.RESPONSE</P>
<P>BBSExpert = context<BR>return BBSExpert.display()<BR><BR>****************************************************************************<BR><BR><BR>Help me.<BR>Thank you very much.<BR><BR></P></FONT><br><br><br><br><br><table id="idKoreaDotComCommonTail" width="350" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15"></td>
<td width="335"><a href="http://www.korea.com" target="_blank"><img src="http://mail.korea.com/images/tail01.gif" width=125 height=18 border="0"></a>
<font style="font-size:12px; font-family:±¼¸²"><b>ÄÚ¸®¾Æ´Â ´ç½ÅÀ» »ç¶ûÇÕ´Ï´Ù</b></font><br>
---------------------------------------<br>
<font style="font-size:12px; font-family:±¼¸²">½Å³ª´Â °ÔÀÓ, ¹Ý°¡¿î Ä£±¸, ±× ¸ðµç °ÍÀÌ ÀÌ°÷¿¡!</font><br>
<font style="font-size:12px; font-family:±¼¸²">´ëÇ¥ °ÔÀÓ ¸Þ°¡ Æ÷Å» <a href="http://game.korea.com" style="text-decoration:none" target="_blank">http://game.korea.com</a></font>
</td>
</tr>
<tr>
<td colspan="2" height="10"></td>
</tr>
</table><br><br>
</BODY>
------=_NextPart_000_457B_01C18C9A.C9DADAA0--