• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 23. Availability of Content via ... > Step 1: Creating Methods: XML-RPC Pr...

Step 1: Creating Methods: XML-RPC Presentation Components

Obviously, you have to create a view component for each of the content objects, MessageBoard and Message. However, both can contain and manage submessages, so you want to factor out this functionality into a common base class, MessageContainerMethods. Because you want to keep the XML-RPC code separate from other code, you should create a new module called xmlrpc.py in the messageboard directory and add the following content:

01 from zope.event import notify
02 from zope.app.publisher.xmlrpc import MethodPublisher
03
04 from zope.app.event.objectevent import ObjectCreatedEvent
05
06 from book.messageboard.message import Message
07
08 class MessageContainerMethods(MethodPublisher):
09
10     def getMessageNames(self):
11         """Get a list of all messages."""
12         return list(self.context.keys())
13
14     def addMessage(self, name, title, body):
15         """Add a message."""
16         msg = Message()
17         msg.title = title
18         msg.body = body
19         notify(ObjectCreatedEvent(msg))
20         self.context[name] = msg
21         return name
22
23     def deleteMessage(self, name):
24         """Delete a message. Return True, if successful."""
25         self.context.__delitem__(name)
26         return True 


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint