예제 #1
0
 def send_comment(self, userid, prefix, comment):
   self.lock.acquire()  # only send one comment at a time (since we're hitting multiple rootids)
   try:
     sent_to = {}
     for sessionid, rootid in self.sessions.items():
       # get the session; if the session has expired, remove and move on
       session = Directory.get_session(sessionid)
       if not session:
         del self.sessions[sessionid]
         continue
         
       # if we've already sent to this rootid, skip and move on
       if sent_to.has_key(rootid):
         continue
       sent_to[rootid] = rootid
       
       # find the actual parent of this comment
       root = datagate.get_item(rootid)
       if not root:
         print "RatingProxy couldn't find rootid:", rootid
         continue
       parentid = self.find_parent(root, prefix) or rootid
       
       # create and send the event to the system (goes to all interested users)
       # I'm using a blank windowid so it goes to anyone looking at this rootid
       item = datagate.create_item(parentid=parentid, creatorid=userid)
       item.text = comment
       item.save()
       event = BaseView.views['rating']._create_event(item, 'processAdd')
       Events.send_event(rootid, event)
   
   finally:
     self.lock.release()