|
from OFS.DTMLDocument import DTMLDocument
from OFS.Folder import Folder
from Globals import HTML, DTMLFile
from urllib import quote
from DateTime import DateTime
import string
import Globals, OFS
class Comment(Folder, DTMLDocument):
meta_type='Code Comment'
_properties = (
{'id':'comment', 'type':'text', 'mode':'w'},
{'id':'title', 'type':'string', 'mode':'w'},
{'id':'username', 'type':'string', 'mode':'w'},
)
__ac_permissions__ = (
('Change Code Comment',
('manage','manage_main','manage_editComment')),
('Add Code Comment',
('manage_addCommentForm','manage_userAddCommentForm',
'manage_addComment')),
)
commentOptions = ({'label':'Edit Comment', 'action':'manage_editForm'},)
manage_options=(
Folder.manage_options[:1]+
commentOptions+
DTMLDocument.manage_options[1:2]+
Folder.manage_options[3:]
)
manage_editForm = DTMLFile('dtml/editCommentForm', globals())
user_editForm = DTMLFile('dtml/userEditCommentForm', globals())
replyComment = DTMLFile('dtml/userAddCommentForm', globals())
index_html = DTMLFile('dtml/indexhtmlComment', globals())
def filtered_meta_types(self, user=None):
meta_types = []
meta_types.append(Globals.Dictionary(name=self.meta_type,
action='manage_addProduct/CookBook/addCommentForm'),)
return meta_types
def getOwnership(self):
owner=self.getOwner(1)
return owner[1]
def isOwner(self):
owner = self.getOwnership()
user = self.REQUEST.AUTHENTICATED_USER.getUserName()
if owner == user:
return 1
else:
return 0
def manage_editComment(self,comment,title='',
redir=None, REQUEST=None):
"""
Replaces a Comments contents with new information
"""
self.title=str(title)
self.comment=comment
for parent in REQUEST['PARENTS']:
if parent.meta_type == 'Code Recipe':
RecipeURL = parent.absolute_url()
if REQUEST is not None:
try: u='%s' % (self.DestinationURL(),)
except: u='%s' % (RecipeURL,)
if redir is None:
u='%s/manage_main' %(u,)
REQUEST.RESPONSE.redirect(u)
return ''
__call__ = index_html
def manage_addComment(self, comment, title='', redir=None,
REQUEST=None, submit=None):
"""Add a Comment object
"""
id=str(int(DateTime()))
ob=Comment(__name__=id)
ob.id=str(int(DateTime()))
ob.title=str(title)
ob.username=REQUEST.AUTHENTICATED_USER.getUserName()
ob.comment=comment
id=self._setObject(id, ob)
for parent in REQUEST['PARENTS']:
if parent.meta_type == 'Code Recipe':
RecipeURL = parent.absolute_url()
if REQUEST is not None:
try: u='%s' % (self.DestinationURL(),)
except: u='%s' % (RecipeURL,)
if redir is None:
u='%s/manage_main' % (u,)
if submit==" Add and Edit ":
if redir is None:
u="%s/%s/manage_main" % (REQUEST['URL1'],quote(id))
else:
u="%s/%s/%s" % (REQUEST['URL1'],quote(id),'user_editForm')
REQUEST.RESPONSE.redirect(u)
return ''
Globals.default__class_init__(Comment)
manage_addCommentForm = DTMLFile('dtml/addCommentForm', globals())
manage_userAddCommentForm = DTMLFile('dtml/userAddCommentForm', globals())
def manage_addComment(self, comment, title='', redir=None,
REQUEST=None, submit=None):
"""Add a Comment object
"""
id=str(int(DateTime()))
ob=Comment(__name__=id)
ob.id=str(int(DateTime()))
ob.title=str(title)
ob.username=REQUEST.AUTHENTICATED_USER.getUserName()
ob.comment=comment
id=self._setObject(id, ob)
for parent in REQUEST['PARENTS']:
if parent.meta_type == 'Code Recipe':
RecipeURL = parent.absolute_url()
if REQUEST is not None:
try: u='%s' % (self.DestinationURL(),)
except: u='%s' % (RecipeURL,)
if redir is None:
u='%s/manage_main' % (u,)
if submit==" Add and Edit ":
if redir is None:
u="%s/%s/manage_main" % (REQUEST['URL1'],quote(id))
else:
u="%s/%s/%s" % (REQUEST['URL1'],quote(id),'user_editForm')
REQUEST.RESPONSE.redirect(u)
return ''
|