work in progress: add media manager and media (attachment) functionality
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@4057 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
5c6ed71819
commit
1768ddfbc0
5 changed files with 102 additions and 2 deletions
|
@ -163,3 +163,14 @@ created.
|
||||||
Media Objects
|
Media Objects
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
>>> from cybertools.wiki.interfaces import IMediaManager
|
||||||
|
>>> mmName = manager.getConfig('mediaManager')
|
||||||
|
>>> mm = component.getAdapter(wiki, IMediaManager, name=mmName)
|
||||||
|
|
||||||
|
>>> media01 = mm.createObject('media01', 'Media Object #1')
|
||||||
|
>>> media01.setRawData('Some data we don\'t care about...')
|
||||||
|
>>> media01.getRawData()
|
||||||
|
"Some data..."
|
||||||
|
|
||||||
|
>>> [(obj.name, obj.title) for obj in mm.listObjects()]
|
||||||
|
[('media01', 'Media Object #1')]
|
||||||
|
|
|
@ -95,4 +95,5 @@ class WikiConfiguration(BaseConfiguration):
|
||||||
writer='docutils.html',
|
writer='docutils.html',
|
||||||
linkManager='basic',
|
linkManager='basic',
|
||||||
nodeProcessors=dict(reference=['default']),
|
nodeProcessors=dict(reference=['default']),
|
||||||
|
mediaManager='default',
|
||||||
)
|
)
|
||||||
|
|
86
wiki/base/media.py
Normal file
86
wiki/base/media.py
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Basic (sample) implementation for a wiki media manager and media objects.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
from zope.component import adapts
|
||||||
|
from zope.interface import implements
|
||||||
|
from cybertools.wiki.interfaces import IWiki, IMediaManager, IMediaObject
|
||||||
|
|
||||||
|
|
||||||
|
class WikiMediaManager(object):
|
||||||
|
""" A Wiki adapter for providing media manager functionality. """
|
||||||
|
|
||||||
|
implements(IMediaManager)
|
||||||
|
adapts(IWiki)
|
||||||
|
|
||||||
|
name = '.media'
|
||||||
|
title = 'Wiki Media Manager'
|
||||||
|
|
||||||
|
def __init__(self, context):
|
||||||
|
self.context = context
|
||||||
|
objects = getattr(context, '_media', None)
|
||||||
|
if objects is None:
|
||||||
|
objects = context._media = {}
|
||||||
|
self.objects = objects
|
||||||
|
|
||||||
|
def getWiki(self):
|
||||||
|
return self.context
|
||||||
|
|
||||||
|
def createObject(self, name, title=None):
|
||||||
|
obj = MediaObject(name, title=title, parent=self.context)
|
||||||
|
self.objects[name] = obj
|
||||||
|
return obj
|
||||||
|
|
||||||
|
def removeObject(self, name):
|
||||||
|
del self.objects[name]
|
||||||
|
|
||||||
|
def getObject(self, name):
|
||||||
|
return self.objects.get(name)
|
||||||
|
|
||||||
|
def listObjects(self):
|
||||||
|
return self.objects.values()
|
||||||
|
|
||||||
|
|
||||||
|
class MediaObject(object):
|
||||||
|
""" A basic (maybe persistent) media object. """
|
||||||
|
|
||||||
|
implements(IMediaObject)
|
||||||
|
|
||||||
|
data = None
|
||||||
|
|
||||||
|
def __init__(self, name, title=None, parent=None):
|
||||||
|
self.name = name
|
||||||
|
self.title = title or Name
|
||||||
|
self.parent = parent
|
||||||
|
|
||||||
|
def getManager(self):
|
||||||
|
if self.parent is None:
|
||||||
|
return None
|
||||||
|
mmName = self.parent.getConfig('mediaManager')
|
||||||
|
return component.getAdapter(self.parent, IMediaManager, name=mmName)
|
||||||
|
|
||||||
|
def getRawData(self):
|
||||||
|
return self.data
|
||||||
|
|
||||||
|
def setRawData(self, data):
|
||||||
|
self.data = data
|
|
@ -150,7 +150,7 @@ class IWikiPage(IWebResource, IIntIdProvider):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = Attribute('A page name or address unique within the wiki.')
|
name = Attribute('A page name or address unique within the wiki.')
|
||||||
title = Attribute('A short string describing the wiki page the may be '
|
title = Attribute('A short string describing the wiki page that may be '
|
||||||
'use as a page title.')
|
'use as a page title.')
|
||||||
text = Attribute('The page content in input text format.')
|
text = Attribute('The page content in input text format.')
|
||||||
|
|
||||||
|
@ -330,7 +330,7 @@ class IMediaManager(Interface):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = Attribute('A page name or address unique within the wiki.')
|
name = Attribute('A page name or address unique within the wiki.')
|
||||||
title = Attribute('A short string describing the wiki page the may be '
|
title = Attribute('A short string describing the object that may be '
|
||||||
'use as a page title.')
|
'use as a page title.')
|
||||||
|
|
||||||
def getWiki():
|
def getWiki():
|
||||||
|
|
|
@ -16,6 +16,7 @@ from zope.traversing.browser.interfaces import IAbsoluteURL
|
||||||
|
|
||||||
from cybertools.relation.tests import IntIdsStub
|
from cybertools.relation.tests import IntIdsStub
|
||||||
from cybertools.wiki.base.config import WikiConfiguration
|
from cybertools.wiki.base.config import WikiConfiguration
|
||||||
|
from cybertools.wiki.base.media import WikiMediaManager
|
||||||
from cybertools.link.base import LinkManager
|
from cybertools.link.base import LinkManager
|
||||||
from cybertools.link.interfaces import ILinkManager
|
from cybertools.link.interfaces import ILinkManager
|
||||||
from cybertools.wiki.dcu.html import Writer as DocutilsHTMLWriter
|
from cybertools.wiki.dcu.html import Writer as DocutilsHTMLWriter
|
||||||
|
@ -61,6 +62,7 @@ def setUp(testCase):
|
||||||
component.provideAdapter(process.Reference, name='default')
|
component.provideAdapter(process.Reference, name='default')
|
||||||
component.provideUtility(LinkManager(), provides=ILinkManager,
|
component.provideUtility(LinkManager(), provides=ILinkManager,
|
||||||
name='cybertools.link')
|
name='cybertools.link')
|
||||||
|
component.provideAdapter(WikiMediaManager, name='default')
|
||||||
from cybertools.wiki.generic import adapter
|
from cybertools.wiki.generic import adapter
|
||||||
adapter.IntIds = IntIdsStub
|
adapter.IntIds = IntIdsStub
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue