Permalink
Browse files

Give the preview_url method of the tempstore access to the stored item.

This allows implementations of that method to base the URL generation on
the actual data, i.e. generate different previews depending on the file
type etc.
  • Loading branch information...
1 parent 3979b35 commit aed3f211df28b578fde651e79984e045fee27538 @tomster tomster committed Jun 18, 2012
Showing with 7 additions and 6 deletions.
  1. +1 −0 CHANGES.txt
  2. +4 −4 deform/tests/test_widget.py
  3. +2 −2 deform/widget.py
View
@@ -4,6 +4,7 @@ Changes
Next release
------------
+- Give the preview_url method of the tempstore access to the stored item. [tomster]
- Fixed remove bug in nested sequences. See
https://github.com/Pylons/deform/pull/89
@@ -1018,7 +1018,7 @@ def test_deserialize_file_selected_no_previous_file(self):
self.assertEqual(result['filename'], 'filename')
self.assertEqual(result['mimetype'], 'mimetype')
self.assertEqual(result['size'], 'size')
- self.assertEqual(result['preview_url'], 'preview_url')
+ self.assertEqual(result['preview_url'], 'http://localhost/filename')
self.assertEqual(tmpstore[uid], result)
def test_deserialize_file_selected_with_previous_file(self):
@@ -1033,7 +1033,7 @@ def test_deserialize_file_selected_with_previous_file(self):
self.assertEqual(result['filename'], 'filename')
self.assertEqual(result['mimetype'], 'mimetype')
self.assertEqual(result['size'], 'size')
- self.assertEqual(result['preview_url'], 'preview_url')
+ self.assertEqual(result['preview_url'], 'http://localhost/filename')
self.assertEqual(tmpstore['uid'], result)
def test_deserialize_file_selected_with_previous_file_IE_whole_path(self):
@@ -1049,7 +1049,7 @@ def test_deserialize_file_selected_with_previous_file_IE_whole_path(self):
self.assertEqual(result['filename'], 'baz.pt')
self.assertEqual(result['mimetype'], 'mimetype')
self.assertEqual(result['size'], 'size')
- self.assertEqual(result['preview_url'], 'preview_url')
+ self.assertEqual(result['preview_url'], 'http://localhost/filename')
self.assertEqual(tmpstore['uid'], result)
class TestDatePartsWidget(unittest.TestCase):
@@ -1855,7 +1855,7 @@ def translate(self, term):
class DummyTmpStore(dict):
def preview_url(self, uid):
- return 'preview_url'
+ return 'http://localhost/%s' % self[uid]['filename']
class DummyUpload(object):
file = 'fp'
View
@@ -1275,14 +1275,14 @@ def deserialize(self, field, pstruct):
uid = self.random_id()
if self.tmpstore.get(uid) is None:
data['uid'] = uid
- data['preview_url'] = self.tmpstore.preview_url(uid)
self.tmpstore[uid] = data
+ self.tmpstore[uid]['preview_url'] = self.tmpstore.preview_url(uid)
break
else:
# a previous file exists
data['uid'] = uid
- data['preview_url'] = self.tmpstore.preview_url(uid)
self.tmpstore[uid] = data
+ self.tmpstore[uid]['preview_url'] = self.tmpstore.preview_url(uid)
else:
# the upload control had no file selected
if uid is None:

0 comments on commit aed3f21

Please sign in to comment.