# Copyright (C) 2006 Roman Joost

# Zope3 imports
from zope.interface import implements

# Zope
from DateTime import DateTime
from OFS.SimpleItem import SimpleItem
from AccessControl import ClassSecurityInfo
from Products.PageTemplates.PageTemplateFile import PageTemplateFile

# Products
from Products.Silva.Content import Content
from Products.Silva.interfaces import IContent
from Products.Silva.helpers import add_and_edit

# Sibling imports
from Products.SilvaBlog.interfaces import ISilvaBlogComment

icon = "www/silvablogcomment.png"

class SilvaBlogComment(Content, SimpleItem):
    """A SilvaBlog comment entry"""

    security = ClassSecurityInfo()
    meta_type = 'Silva Blog Comment'
    implements(ISilvaBlogComment)

    def __init__(self, id, title):
        SilvaBlogComment.inheritedAttribute('__init__')(self, id, '')
        self.person_name = "" 
        self.title = title
        self.body = ""
        self.email = ""
        self.posted = DateTime()
    
    def update(self, result_dict):
        """updates the comment"""
        self.person_name = result_dict.get('person_name',
                                           self.person_name)
        self.title = result_dict.get('comment_subject', self.title)
        self.body = result_dict.get('comment_body', self.body)
        self.email = result_dict.get('person_mail', self.email)

    def is_deletable(self):
        """Comments are always deletable"""
        return True

        
manage_addSilvaBlogCommentForm = PageTemplateFile("www/silvaBlogCommentAdd", 
                globals(), __name__ = 'manage_addSilvaBlogComment')

def manage_addSilvaBlogComment(dispatcher, id, title, REQUEST=None):
    """Add SilvaBlogComment"""
    entry = SilvaBlogComment(id, title)
    dispatcher._setObject(id, entry)
    add_and_edit(dispatcher, id, REQUEST)
    return ''


