import OFS import AccessControl from OFS import SimpleItem import types import time from Products.Krihvel.BaseTask import BaseTask #from TraversableWrapper import Traversable from Globals import Persistent from AccessControl import ClassSecurityInfo #from Cruft import Cruft #from common import add_dtml, translate, perm_edit, perm_view from Products.ZCatalog.CatalogAwareness import CatalogAware from Products.Archetypes.public import registerType, BaseContent from Products.Krihvel.BaseAnswer import BaseAnswer from Products.Krihvel.config import PROJECT_NAME class Message( OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager # Traversable, # Cruft, # CatalogAware ): """ teate kataloogis """ meta_type = 'Message' security = ClassSecurityInfo() security.declareObjectPublic() def __init__(self, content, user): "creating new message" self.content=content self.user=user def kysiAeg(self): "creation time" return time.localtime(self.bobobase_modification_time().timeTime()) class Chatroom( OFS.Folder.Folder, OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager, BaseTask # Traversable, # Cruft ): """ Place for holding messages""" security = ClassSecurityInfo() security.declareObjectPublic() userdata={} links_title={} links_url={} messageNr=0 topic="" task="" meta_type="Chatroom" # def __init__(self): # """ init, set id """ # self.id = 'Messages' def prooviTekst(self): "tekst proovimiseks" return "proov" security.declarePrivate('AskNewNr') def AskNewNr(self): self.messageNr=self.messageNr+1 while hasattr(self.aq_self, 'event'+str(self.messageNr)): self.messageNr=self.messageNr+1 return self.messageNr def AddMessage(self, content, user): nr = str(self.AskNewNr()) m = Message(content,user) m.id = nr self._setObject(nr, m) return m def Message_listener(self, REQUEST, content): "Storing Message data" kasutajanimi=str(REQUEST.AUTHENTICATED_USER) self.AddMessage(content, kasutajanimi) REQUEST.RESPONSE.redirect('chatroom') return "Created" def task_listener(self, REQUEST, topic, task): "Storing task data" self.topic=topic self.task=task REQUEST.RESPONSE.redirect('chatroom') #return "Created" def link_listener(self, REQUEST, title, url): "storing task data" if not hasattr(self, 'links_title'): self.links_title={} if not hasattr(self, 'links_url'): self.links_url={} self.links_title[len(self.links_title)]=title self.links_url[len(self.links_url)]=url self.links_title=self.links_title self.links_url=self.links_url REQUEST.RESPONSE.redirect('chatroom') #return "Created" def AskTask(self): "AskTask" return self.task def AskTopic(self): "AskTopic" return self.topic def AskLinks(self): "AskLinks" l1=[] for i in range(len(self.links_title)): l=[] l.append(self.links_title[i]) l.append(self.links_url[i]) l1.append(l) return l1 def DeleteLinks(self): "Delete links" for i in range(len(self.links_title)): self.links_title[i]=null self.links_url[i]=null return l1 def AskMessages(self): "returing stored message objects" m=self.objectValues('Message') kogus=len(m) if kogus>10: m=m[-10:] return m def RegisterVisit(self, REQUEST): "Data about page visit" import time if not hasattr(self, 'userdata'): self.userdata={} self.userdata[str(REQUEST.AUTHENTICATED_USER)]=time.time() def AskVisits(self): "Users list who are viewing page" t=[] for k in self.userdata.keys(): temp=self.userdata[k]+30 if time.time() < temp: t.append(k) return t def isOwner(self, REQUEST): "Is user owner" return str(REQUEST.AUTHENTICATED_USER)==str(self.getOwner()) registerType(Chatroom, PROJECT_NAME)