[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&nbsp;I excuse&nbsp;what I am not good at English.&nbsp;<BR><BR>I made a simple product(named&nbsp;BBSExpert.py)&nbsp;by python, tested it, and succeeded.<BR>There&nbsp;is the display()&nbsp;class&nbsp;&nbsp;in the BBSExpert.py.<BR>I want to call this class (display() is located in the BBSExpert.py)&nbsp;into zope base(ex. Script (python)).<BR><BR>These&nbsp;&nbsp;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>&nbsp;"""<BR>&nbsp;"""<BR>&nbsp;context.registerClass(<BR>&nbsp;&nbsp;BBSExpert.BBSExpert,<BR>&nbsp;&nbsp;constructors = ( <BR>&nbsp;&nbsp;&nbsp;BBSExpert.Manage_AddBBSExpertForm, BBSExpert.Manage_AddBBSExpertAction<BR>&nbsp;&nbsp;),<BR>&nbsp;&nbsp;icon=None<BR>&nbsp;)<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; content='Content here.', REQUEST=None):<BR>&nbsp;"""<BR>&nbsp;Add a BBSExpert to a folder.<BR>&nbsp;"""</FONT></P>
<P><FONT face=±¼¸² size=2>&nbsp;self._setObject(id, BBSExpert(id, title, content))<BR>&nbsp;if REQUEST is not None:<BR>&nbsp;&nbsp;return self.manage_main(self, REQUEST)<BR>&nbsp;<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>&nbsp;OFS.SimpleItem.Item,&nbsp;&nbsp;# A simple Principia object. Not Folderish. <BR>&nbsp;Persistent,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Make us persistent. Yaah! <BR>&nbsp;Acquisition.Implicit,&nbsp;&nbsp;# Let us use our parent's variables and methods.&nbsp; <BR>&nbsp;AccessControl.Role.RoleManager&nbsp;# Security manager. <BR>&nbsp;):<BR>&nbsp;<BR>&nbsp;"""<BR>&nbsp;BBSExpert Product<BR>&nbsp;"""</P>
<P>&nbsp;meta_type = 'BBSExpert'<BR>&nbsp;<BR>&nbsp;manage_options = (<BR>&nbsp;&nbsp;{'label': 'Properties', 'action': 'manage_editForm',},<BR>&nbsp;&nbsp;{'label': 'View', 'action': 'index_html',},<BR>&nbsp;)<BR>&nbsp;<BR>&nbsp;def __init__(self, id, title, content):<BR>&nbsp;&nbsp;"Inits the product with default values"<BR>&nbsp;&nbsp;self.id = id<BR>&nbsp;&nbsp;self.title = title<BR>&nbsp;&nbsp;self.content = content</P>
<P>&nbsp;def manage_editAction(self, title, content, RESPONSE=None):<BR>&nbsp;&nbsp;"Changes the product values"<BR>&nbsp;&nbsp;self.title = title<BR>&nbsp;&nbsp;self.content = content<BR>&nbsp;&nbsp;self._p_changed = 1<BR>&nbsp;&nbsp;RESPONSE.redirect('manage_editForm')</P>
<P>&nbsp;# The web pages that shows content. Put your own in the www folder.</P>
<P>&nbsp;def index_html(self):<BR>&nbsp;&nbsp;"used to view content of the object"<BR>&nbsp;&nbsp;return """&lt;html&gt;&lt;body&gt;2pu hahaha&lt;/body&gt;&lt;/html&gt;"""</P>
<P>&nbsp;def display(self):<BR>&nbsp;&nbsp;"used to view content of the object"<BR>&nbsp;&nbsp;return """&lt;html&gt;&lt;body&gt; We are the world&lt;/body&gt;&lt;/html&gt;"""</P>
<P><BR>&nbsp;# Used to view content of the object<BR>&nbsp;#index_html = DTMLFile('www/index_html', globals())</P>
<P>&nbsp;# Edit the content of the object<BR>&nbsp;manage_editForm = DTMLFile('www/manage_editForm', globals())<BR><BR><BR><BR>Index_html.dtml********************************************<BR><BR>&nbsp;&lt;dtml-if id&gt;<BR>&nbsp;&nbsp;&lt;b&gt;ID:&lt;/b&gt;&lt;br&gt;<BR>&nbsp;&nbsp;&lt;dtml-var id&gt;&lt;br&gt;&lt;br&gt;<BR>&nbsp;&lt;/dtml-if&gt;</P>
<P>&nbsp;&lt;dtml-if title&gt;<BR>&nbsp;&nbsp;&lt;b&gt;Title:&lt;/b&gt;&lt;br&gt;<BR>&nbsp;&nbsp;&lt;dtml-var title&gt;&lt;br&gt;&lt;br&gt;<BR>&nbsp;&lt;/dtml-if&gt;</P>
<P>&nbsp;&lt;dtml-if content&gt;<BR>&nbsp;&nbsp;&lt;b&gt;Content:&lt;/b&gt;&lt;br&gt;<BR>&nbsp;&nbsp;&lt;dtml-var content&gt;&lt;br&gt;&lt;br&gt;<BR>&nbsp;&lt;/dtml-if&gt;<BR></P>
<P>Manage_AddBBSExpertForm.dtml***************************************<BR><BR>&lt;html&gt;<BR>&lt;head&gt;<BR>&lt;title&gt;Add BBSExpert Instance&lt;/title&gt;<BR>&lt;/head&gt;</P>
<P>&lt;body bgcolor="#FFFFFF"&gt;<BR>&nbsp;&lt;form name="form" action="Manage_AddBBSExpertAction" method="post"&gt;&lt;br&gt;<BR>&nbsp;&nbsp;id:&lt;br&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="text" name="id:string" size="30" value="BBSExpert"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br&gt;&lt;br&gt;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BBSExpert Title:&lt;br&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="text" name="title:string" size="30" value="MyBBS"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br&gt;&lt;br&gt;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Content:&lt;br&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;textarea name="content:text" cols="40" rows="8" wrap="virtual"&gt;Content here.&lt;/textarea&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br&gt;&lt;br&gt;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="submit" value="&nbsp; add&nbsp; "&gt;<BR>&nbsp;&lt;/form&gt;</P>
<P>&lt;/body&gt;<BR>&lt;/html&gt;<BR><BR><BR><BR>Manage_EditForm.dtml*****************************************************<BR><BR>&lt;html&gt;<BR>&lt;head&gt;<BR>&lt;title&gt;Manage BBSExpert&lt;/title&gt;<BR>&lt;/head&gt;<BR>&lt;body bgcolor="#FFFFFF"&gt;</P>
<P>&nbsp;&lt;dtml-var manage_tabs&gt;</P>
<P>&nbsp;&lt;form name="form" action="." method="post"&gt;&lt;br&gt;</P>
<P>&nbsp;&nbsp;BBSTitle:&lt;br&gt;<BR>&nbsp;&nbsp;&lt;input type="text" name="title:string" size="30" value="&lt;dtml-var title&gt;"&gt;<BR>&nbsp;&nbsp;&lt;br&gt;&lt;br&gt;</P>
<P>&nbsp;&nbsp;Content:&lt;br&gt;<BR>&nbsp;&nbsp;&lt;textarea name="content:text" cols="40" rows="8" wrap="virtual"&gt;&lt;dtml-var content&gt;&lt;/textarea&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br&gt;&lt;br&gt;</P>
<P>&nbsp;&nbsp;&lt;input type="submit" value="Change" name="manage_editAction:method"&gt;</P>
<P>&nbsp;&lt;/form&gt;</P>
<P>&lt;/body&gt;<BR>&lt;/html&gt;<BR><BR><BR>*************************************************************************<BR><BR>3. Examplecode.txt (This part what I failed actually.)<BR>&nbsp;&nbsp;&nbsp; (In Example.txt I could not return the display() class. <BR>&nbsp;&nbsp;&nbsp;&nbsp; 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 =&nbsp; 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>&nbsp;&nbsp;
        <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:±¼¸²">´ëÇ¥ °ÔÀÓ ¸Þ°¡ Æ÷Å» &nbsp;&nbsp;<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--