Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit aed3f211df28b578fde651e79984e045fee27538 1 parent 3979b35
@tomster tomster authored
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
1  CHANGES.txt
@@ -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
View
8 deform/tests/test_widget.py
@@ -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
4 deform/widget.py
@@ -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:
Please sign in to comment.
Something went wrong with that request. Please try again.