Back to index

plone3  3.1.7
simplecontent.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 # Copyright (c) 2005-2006
00003 # Authors:
00004 #   Godefroid Chapelle <gotcha@bubblenet.be>
00005 #   Tarek Ziadé <tz@nuxeo.com>
00006 #   Balázs Reé <ree@greenfinity.hu>
00007 #
00008 # This program is free software; you can redistribute it and/or modify
00009 # it under the terms of the GNU General Public License version 2 as published
00010 # by the Free Software Foundation.
00011 #
00012 # This program is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 # GNU General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU General Public License
00018 # along with this program; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020 # 02111-1307, USA.
00021 #
00022 
00023 """Simple content implementation
00024 """
00025 from OFS.SimpleItem import SimpleItem
00026 from Globals import InitializeClass
00027 from AccessControl import ClassSecurityInfo
00028 from helpers import add_and_edit
00029 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00030 from zope.interface import implements
00031 from interfaces import ISimpleContent
00032 from persistent.mapping import PersistentMapping
00033 
00034 class SimpleContent(SimpleItem):
00035     implements(ISimpleContent)
00036 
00037     meta_type = 'KssDemo SimpleContent'
00038     security = ClassSecurityInfo()
00039 
00040     manage_options = (
00041         {'label':'Demos', 'action':''},
00042         ) + SimpleItem.manage_options
00043     
00044     def __init__(self, id, title):
00045         self.id = id
00046         self.title = title
00047         self.mapping = PersistentMapping()
00048 
00049     def getValue(self, name, default=None):
00050         result = self.mapping.get(name, default)
00051         if not result or result == default:
00052             result = default
00053             self.setValue(name, result)
00054         return result
00055 
00056     def setValue(self, name, value):
00057         self.mapping[name] = value
00058 
00059     security.declarePublic('direct')
00060     def direct(self):
00061         """Should be able to traverse directly to this as there is no view.
00062         """
00063         return "Direct traversal worked"
00064 
00065 InitializeClass(SimpleContent)
00066 
00067 manage_addSimpleContentForm = PageTemplateFile(
00068     "www/simpleContentAdd", globals(),
00069     __name__ = 'manage_addSimpleContentForm')
00070 
00071 def manage_addSimpleContent(self, id, title, REQUEST=None):
00072     """Add the simple content."""
00073     id = self._setObject(id, SimpleContent(id, title))
00074     add_and_edit(self, id, REQUEST)
00075     return ''