Skip to content

Commit

Permalink
Merge pull request #367 from cneves/feature/imagemarshal_tiled
Browse files Browse the repository at this point in the history
Allow passing 'tiled' argument to image.simpleMarshal
  • Loading branch information
joshmoore committed Sep 20, 2012
2 parents 2b61aa0 + e7a1f9d commit 67c9e73
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
21 changes: 19 additions & 2 deletions components/tools/OmeroPy/src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5724,8 +5724,16 @@ def resetRDefs (self):

def simpleMarshal (self, xtra=None, parents=False):
"""
Creates a dict representation of the Image, including author and date info.
Creates a dict representation of the Image, including author and date info.
@param xtra: controls the optional parts of simpleMarshal;
- thumbUrlPrefix - allows customizing the thumb URL by
either a static string prefix or a callable function
that will take a single ImgId int argument and return the
customized URL string
- tiled - if passed and value evaluates to true, add
information on whether this image is tiled on this server.
@type: Dict
@return: Dict
@rtype: Dict
"""
Expand All @@ -5739,6 +5747,15 @@ def simpleMarshal (self, xtra=None, parents=False):
rv['thumb_url'] = xtra['thumbUrlPrefix'](str(self.id))
else:
rv['thumb_url'] = xtra['thumbUrlPrefix'] + str(self.id) + '/'
if xtra.get('tiled', False):
# Since we need to calculate sizes, store them too in the marshaled value
maxplanesize = self._conn.getMaxPlaneSize()
rv['size'] = {'width': self.getSizeX(),
'height': self.getSizeY(),
}
rv['tiled'] = (rv['size']['height'] * rv['size']['width']) > (maxplanesize[0] * maxplanesize[1])


return rv

def getStageLabel (self):
Expand Down
14 changes: 14 additions & 0 deletions components/tools/OmeroPy/test/gatewaytest/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ def testSimpleMarshal (self):
self.assertEqual(m['author'], self.AUTHOR.fullname())
self.assert_('parents' not in m)
self.assert_('date' in m)
self.assert_('tiled' not in m)
self.assert_('size' not in m)
m = self.image.simpleMarshal(xtra={'tiled':True})
self.assertEqual(m['name'], self.image.getName())
self.assertEqual(m['description'], self.image.getDescription())
self.assertEqual(m['id'], self.image.getId())
self.assertEqual(m['type'], self.image.OMERO_CLASS)
self.assertEqual(m['author'], self.AUTHOR.fullname())
self.assertEqual(m['tiled'], False)
self.assertEqual(m['size'], {'width': self.image.getSizeX(), 'height': self.image.getSizeY()})
self.assert_('parents' not in m)
self.assert_('date' in m)
m = self.image.simpleMarshal(xtra={'tiled':False})
self.assert_('tiled' not in m)
parents = map(lambda x: x.simpleMarshal(), self.image.getAncestry())
m = self.image.simpleMarshal(parents=True)
self.assertEqual(m['name'], self.image.getName())
Expand Down
15 changes: 15 additions & 0 deletions components/tools/OmeroWeb/omeroweb/webgateway/tests/unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,21 @@ def testImageData (self):
self.assert_('"split_channel":' in v)
self.assert_('"pixel_range": [-32768, 32767]' in v)

def testListChildren (self):
self.loginAsAuthor()
img = self.getTestImage()
did = img.getParent().getId()
r = fakeRequest()
v = views.listImages_json(r, did=did, server_id=1, conn=self.gateway, _internal=True)
self.assert_(type(v) == type(''))
self.assert_('"id": %d,' % img.getId() in v)
self.assert_('"tiled: "' not in v)
r.setQuery(tiled='1')
v = views.listImages_json(r, did=did, server_id=1, conn=self.gateway, _internal=True)
self.assert_(type(v) == type(''))
self.assert_('"id": %d,' % img.getId() in v)
self.assert_('"tiled": false' in v)

class UserProxyTest (WGTest):
def test (self):
self.loginAsAuthor()
Expand Down
8 changes: 7 additions & 1 deletion components/tools/OmeroWeb/omeroweb/webgateway/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@
json method: returns list of Images belonging to specified Dataset. See L{views.listImages_json}. Returns E.g list of
{"description": "", "author": "Will Moore", "date": 1291325060.0, "thumb_url": "/webgateway/render_thumbnail/4701/", "type": "Image", "id": 4701, "name": "spim.png"}
- webgateway/dataset/<did>/children params are:
- did: Dataset ID
- did: Dataset ID
- request variables:
- thumbUrlPrefix: view key whose reverse url is to be used as prefix for thumb_url instead of default
webgateway.views.render_thumbnail
- tiled: if set with anything other than an empty string will add information on whether each image
is tiled on this server
"""

webgateway_listwellimages_json = url(r'^well/(?P<did>[^/]+)/children/$', 'webgateway.views.listWellImages_json', name="webgateway_listwellimages_json")
Expand Down
3 changes: 2 additions & 1 deletion components/tools/OmeroWeb/omeroweb/webgateway/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,8 @@ def listImages_json (request, did, conn=None, **kwargs):
prefix = kwargs.get('thumbprefix', 'webgateway.views.render_thumbnail')
def urlprefix(iid):
return reverse(prefix, args=(iid,))
xtra = {'thumbUrlPrefix': kwargs.get('urlprefix', urlprefix)}
xtra = {'thumbUrlPrefix': kwargs.get('urlprefix', urlprefix),
'tiled': request.REQUEST.get('tiled', False),}
return map(lambda x: x.simpleMarshal(xtra=xtra), dataset.listChildren())

@login_required()
Expand Down

0 comments on commit 67c9e73

Please sign in to comment.