Improvements on resource.MediaAsset; moved tests to directory in order to place files there for test upload
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1020 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
921bbcf92d
commit
55c3137c4f
9 changed files with 89 additions and 44 deletions
43
README.txt
43
README.txt
|
@ -19,13 +19,12 @@ Let's start with creating a few example concepts, putting them in a
|
||||||
top-level loops container and a concept manager:
|
top-level loops container and a concept manager:
|
||||||
|
|
||||||
>>> from loops import Loops
|
>>> from loops import Loops
|
||||||
>>> loops = Loops()
|
|
||||||
>>> site['loops'] = Loops()
|
>>> site['loops'] = Loops()
|
||||||
>>> loops = site['loops']
|
>>> loopsRoot = site['loops']
|
||||||
|
|
||||||
>>> from loops.concept import ConceptManager, Concept
|
>>> from loops.concept import ConceptManager, Concept
|
||||||
>>> loops['concepts'] = ConceptManager()
|
>>> loopsRoot['concepts'] = ConceptManager()
|
||||||
>>> concepts = loops['concepts']
|
>>> concepts = loopsRoot['concepts']
|
||||||
>>> cc1 = Concept()
|
>>> cc1 = Concept()
|
||||||
>>> concepts['cc1'] = cc1
|
>>> concepts['cc1'] = cc1
|
||||||
>>> cc1.title
|
>>> cc1.title
|
||||||
|
@ -78,8 +77,8 @@ Resources and what they have to do with Concepts
|
||||||
We first need a resource manager:
|
We first need a resource manager:
|
||||||
|
|
||||||
>>> from loops.resource import ResourceManager, Document
|
>>> from loops.resource import ResourceManager, Document
|
||||||
>>> loops['resources'] = ResourceManager()
|
>>> loopsRoot['resources'] = ResourceManager()
|
||||||
>>> resources = loops['resources']
|
>>> resources = loopsRoot['resources']
|
||||||
|
|
||||||
A common type of resource is a document:
|
A common type of resource is a document:
|
||||||
|
|
||||||
|
@ -90,10 +89,35 @@ A common type of resource is a document:
|
||||||
>>> doc1.data
|
>>> doc1.data
|
||||||
u''
|
u''
|
||||||
>>> doc1.contentType
|
>>> doc1.contentType
|
||||||
u'text/xml'
|
''
|
||||||
|
|
||||||
Another one is a media asset:
|
Another one is a media asset:
|
||||||
|
|
||||||
|
>>> from loops.resource import MediaAsset
|
||||||
|
>>> img = MediaAsset(u'A png Image')
|
||||||
|
|
||||||
|
For testing we use some simple files from the tests directory:
|
||||||
|
|
||||||
|
>>> from loops import tests
|
||||||
|
>>> import os
|
||||||
|
>>> path = os.path.join(*tests.__path__)
|
||||||
|
>>> img.data = open(os.path.join(path, 'test_icon.png')).read()
|
||||||
|
>>> img.getSize()
|
||||||
|
381
|
||||||
|
>>> img.getImageSize()
|
||||||
|
(16, 16)
|
||||||
|
>>> img.contentType
|
||||||
|
'image/png'
|
||||||
|
|
||||||
|
>>> pdf = MediaAsset(u'A pdf File')
|
||||||
|
>>> pdf.data = open(os.path.join(path, 'test.pdf')).read()
|
||||||
|
>>> pdf.getSize()
|
||||||
|
25862
|
||||||
|
>>> pdf.getImageSize()
|
||||||
|
(-1, -1)
|
||||||
|
>>> pdf.contentType
|
||||||
|
'application/pdf'
|
||||||
|
|
||||||
We can associate a resource with a concept by assigning it to the concept:
|
We can associate a resource with a concept by assigning it to the concept:
|
||||||
|
|
||||||
>>> cc1.assignResource(doc1)
|
>>> cc1.assignResource(doc1)
|
||||||
|
@ -129,8 +153,8 @@ We first need a view manager:
|
||||||
>>> nodeChecker = NamesChecker(('body',))
|
>>> nodeChecker = NamesChecker(('body',))
|
||||||
>>> defineChecker(Node, nodeChecker)
|
>>> defineChecker(Node, nodeChecker)
|
||||||
|
|
||||||
>>> loops['views'] = ViewManager()
|
>>> loopsRoot['views'] = ViewManager()
|
||||||
>>> views = loops['views']
|
>>> views = loopsRoot['views']
|
||||||
|
|
||||||
The view space is typically built up with nodes; a node may be a top-level
|
The view space is typically built up with nodes; a node may be a top-level
|
||||||
menu that may contain other nodes as menu or content items:
|
menu that may contain other nodes as menu or content items:
|
||||||
|
@ -290,7 +314,6 @@ instance to another.
|
||||||
>>> data[3]['name']
|
>>> data[3]['name']
|
||||||
u'm112'
|
u'm112'
|
||||||
|
|
||||||
>>> import os
|
|
||||||
>>> dumpname = os.path.dirname(__file__) + '/test.tmp'
|
>>> dumpname = os.path.dirname(__file__) + '/test.tmp'
|
||||||
>>> exporter.filename = dumpname
|
>>> exporter.filename = dumpname
|
||||||
>>> exporter.dumpData()
|
>>> exporter.dumpData()
|
||||||
|
|
|
@ -152,6 +152,12 @@
|
||||||
|
|
||||||
</content>
|
</content>
|
||||||
|
|
||||||
|
<!--<adapter
|
||||||
|
factory="zope.app.file.image.ImageSized"
|
||||||
|
provides="zope.app.size.interfaces.ISized"
|
||||||
|
for=".interfaces.IMediaAsset"
|
||||||
|
/>-->
|
||||||
|
|
||||||
<!-- view manager and view -->
|
<!-- view manager and view -->
|
||||||
|
|
||||||
<interface interface=".interfaces.IViewManager"
|
<interface interface=".interfaces.IViewManager"
|
||||||
|
@ -215,13 +221,11 @@
|
||||||
|
|
||||||
<view factory="loops.view.NodeTraverser"
|
<view factory="loops.view.NodeTraverser"
|
||||||
for="loops.interfaces.INode"
|
for="loops.interfaces.INode"
|
||||||
type="zope.publisher.interfaces.http.IHTTPRequest"
|
type="zope.publisher.interfaces.browser.IBrowserRequest"
|
||||||
provides="zope.publisher.interfaces.IPublishTraverse"
|
provides="zope.publisher.interfaces.browser.IBrowserPublisher"
|
||||||
allowed_interface="zope.publisher.interfaces.IPublishTraverse"
|
allowed_interface="zope.publisher.interfaces.browser.IBrowserPublisher"
|
||||||
permission="zope.Public" />
|
permission="zope.Public" />
|
||||||
|
|
||||||
<!--<adapter factory="loops.view.NodeTraversable" />-->
|
|
||||||
|
|
||||||
<!-- Register various browser related components, including all views -->
|
<!-- Register various browser related components, including all views -->
|
||||||
<include package=".browser" />
|
<include package=".browser" />
|
||||||
|
|
||||||
|
|
|
@ -108,14 +108,23 @@ class IResource(Interface):
|
||||||
|
|
||||||
title = schema.TextLine(
|
title = schema.TextLine(
|
||||||
title=_(u'Title'),
|
title=_(u'Title'),
|
||||||
description=_(u'Title of the document'),
|
description=_(u'Title of the resource'),
|
||||||
|
default=u'',
|
||||||
|
missing_value=u'',
|
||||||
required=False)
|
required=False)
|
||||||
|
|
||||||
contentType = schema.TextLine(
|
contentType = schema.BytesLine(
|
||||||
title=_(u'Content Type'),
|
title=_(u'Content Type'),
|
||||||
description=_(u'Content type (format) of the body field, '
|
description=_(u'Content type (format) of the data field'),
|
||||||
'default is "text/xml"'),
|
default='',
|
||||||
default=_(u'text/xml'),
|
missing_value='',
|
||||||
|
required=False)
|
||||||
|
|
||||||
|
data = schema.Bytes(
|
||||||
|
title=_(u'Data'),
|
||||||
|
description=_(u'Resource raw data'),
|
||||||
|
default='',
|
||||||
|
missing_value='',
|
||||||
required=False)
|
required=False)
|
||||||
|
|
||||||
def getClients(relationships=None):
|
def getClients(relationships=None):
|
||||||
|
@ -131,6 +140,8 @@ class IDocument(IResource):
|
||||||
data = schema.Text(
|
data = schema.Text(
|
||||||
title=_(u'Data'),
|
title=_(u'Data'),
|
||||||
description=_(u'Raw body data of the document'),
|
description=_(u'Raw body data of the document'),
|
||||||
|
default=u'',
|
||||||
|
missing_value=u'',
|
||||||
required=False)
|
required=False)
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,7 +152,9 @@ class IMediaAsset(IResource, IBaseAsset):
|
||||||
|
|
||||||
data = schema.Bytes(
|
data = schema.Bytes(
|
||||||
title=_(u'Data'),
|
title=_(u'Data'),
|
||||||
description=_(u'Media asset raw data'),
|
description=_(u'Media asset file'),
|
||||||
|
default='',
|
||||||
|
missing_value='',
|
||||||
required=False)
|
required=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
25
resource.py
25
resource.py
|
@ -44,16 +44,11 @@ class Resource(Contained, Persistent):
|
||||||
def setTitle(self, title): self._title = title
|
def setTitle(self, title): self._title = title
|
||||||
title = property(getTitle, setTitle)
|
title = property(getTitle, setTitle)
|
||||||
|
|
||||||
_contentType = u'text/xml'
|
_contentType = ''
|
||||||
def setContentType(self, contentType): self._contentType = contentType
|
def setContentType(self, contentType): self._contentType = contentType
|
||||||
def getContentType(self): return self._contentType
|
def getContentType(self): return self._contentType
|
||||||
contentType = property(getContentType, setContentType)
|
contentType = property(getContentType, setContentType)
|
||||||
|
|
||||||
_data = u''
|
|
||||||
def setData(self, data): self._data = data
|
|
||||||
def getData(self): return self._data
|
|
||||||
data = property(getData, setData)
|
|
||||||
|
|
||||||
def getClients(self, relationships=None):
|
def getClients(self, relationships=None):
|
||||||
rels = getRelations(second=self, relationships=relationships)
|
rels = getRelations(second=self, relationships=relationships)
|
||||||
return [r.first for r in rels]
|
return [r.first for r in rels]
|
||||||
|
@ -61,11 +56,18 @@ class Resource(Contained, Persistent):
|
||||||
def __init__(self, title=u''):
|
def __init__(self, title=u''):
|
||||||
self.title = title
|
self.title = title
|
||||||
|
|
||||||
|
_size = 0
|
||||||
|
|
||||||
|
|
||||||
class Document(Resource):
|
class Document(Resource):
|
||||||
|
|
||||||
implements(IDocument)
|
implements(IDocument)
|
||||||
|
|
||||||
|
_data = u''
|
||||||
|
def setData(self, data): self._data = data
|
||||||
|
def getData(self): return self._data
|
||||||
|
data = property(getData, setData)
|
||||||
|
|
||||||
|
|
||||||
class MediaAsset(Resource, BaseMediaAsset):
|
class MediaAsset(Resource, BaseMediaAsset):
|
||||||
|
|
||||||
|
@ -75,6 +77,17 @@ class MediaAsset(Resource, BaseMediaAsset):
|
||||||
super(MediaAsset, self).__init__()
|
super(MediaAsset, self).__init__()
|
||||||
self.title = title
|
self.title = title
|
||||||
|
|
||||||
|
def _setData(self, data):
|
||||||
|
super(MediaAsset, self)._setData(data)
|
||||||
|
if not self.contentType:
|
||||||
|
self.guessContentType(data)
|
||||||
|
|
||||||
|
data = property(BaseMediaAsset._getData, _setData)
|
||||||
|
|
||||||
|
def guessContentType(self, data):
|
||||||
|
if data.startswith('%PDF'):
|
||||||
|
self.contentType = 'application/pdf'
|
||||||
|
|
||||||
|
|
||||||
class ResourceManager(BTreeContainer):
|
class ResourceManager(BTreeContainer):
|
||||||
|
|
||||||
|
|
4
tests/__init__.py
Normal file
4
tests/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
"""
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
BIN
tests/test.pdf
Normal file
BIN
tests/test.pdf
Normal file
Binary file not shown.
BIN
tests/test_icon.png
Normal file
BIN
tests/test_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 381 B |
|
@ -8,11 +8,11 @@ from zope.interface import implements
|
||||||
from zope.app import zapi
|
from zope.app import zapi
|
||||||
from zope.app.intid.interfaces import IIntIds
|
from zope.app.intid.interfaces import IIntIds
|
||||||
|
|
||||||
from interfaces import ILoops
|
from loops.interfaces import ILoops
|
||||||
from loops import Loops
|
from loops import Loops
|
||||||
from interfaces import IConcept, IConceptManager
|
from loops.interfaces import IConcept, IConceptManager
|
||||||
from interfaces import IDocument, IMediaAsset, IResourceManager
|
from loops.interfaces import IDocument, IMediaAsset, IResourceManager
|
||||||
from interfaces import INode, IViewManager
|
from loops.interfaces import INode, IViewManager
|
||||||
from loops.concept import Concept, ConceptManager
|
from loops.concept import Concept, ConceptManager
|
||||||
from loops.resource import Document, MediaAsset, ResourceManager
|
from loops.resource import Document, MediaAsset, ResourceManager
|
||||||
from loops.view import Node, ViewManager
|
from loops.view import Node, ViewManager
|
||||||
|
@ -43,7 +43,7 @@ def test_suite():
|
||||||
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
||||||
return unittest.TestSuite((
|
return unittest.TestSuite((
|
||||||
unittest.makeSuite(Test),
|
unittest.makeSuite(Test),
|
||||||
DocFileSuite('README.txt', optionflags=flags),
|
DocFileSuite('../README.txt', optionflags=flags),
|
||||||
))
|
))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
12
view.py
12
view.py
|
@ -159,15 +159,3 @@ class NodeTraverser(ItemTraverser):
|
||||||
return self.context.getLoopsRoot()
|
return self.context.getLoopsRoot()
|
||||||
return super(NodeTraverser, self).publishTraverse(request, name)
|
return super(NodeTraverser, self).publishTraverse(request, name)
|
||||||
|
|
||||||
|
|
||||||
# class NodeTraversable(ContainerTraversable):
|
|
||||||
#
|
|
||||||
# adapts(INode)
|
|
||||||
#
|
|
||||||
# def traverse(self, name, furtherPath):
|
|
||||||
# print name
|
|
||||||
# if str(name) == '.loops':
|
|
||||||
# print self._container.getLoopsRoot()
|
|
||||||
# return self._container.getLoopsRoot()
|
|
||||||
# return super(NodeTraversable, self).traverse(name, furtherPath)
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue